Skip to content

Commit

Permalink
Merge pull request #47 from LucienShui/dev
Browse files Browse the repository at this point in the history
png compressed, i18n lazy loaded, add api.js, update README.md
  • Loading branch information
LucienShui authored Jun 10, 2019
2 parents 049b2dd + 643c8ae commit 388772c
Show file tree
Hide file tree
Showing 34 changed files with 127 additions and 119 deletions.
2 changes: 1 addition & 1 deletion Frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ module.exports = {
parserOptions: {
parser: 'babel-eslint'
}
}
};
2 changes: 1 addition & 1 deletion Frontend/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module.exports = {
presets: [
'@vue/app'
]
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
list: ["af", "sq", "ar-SA", "ar-IQ", "ar-EG", "ar-LY", "ar-DZ", "ar-MA", "ar-TN", "ar-OM",
{
"list": ["af", "sq", "ar-SA", "ar-IQ", "ar-EG", "ar-LY", "ar-DZ", "ar-MA", "ar-TN", "ar-OM",
"ar-YE", "ar-SY", "ar-JO", "ar-LB", "ar-KW", "ar-AE", "ar-BH", "ar-QA", "eu", "bg",
"be", "ca", "zh-TW", "zh-CN", "zh-HK", "zh-SG", "hr", "cs", "da", "nl", "nl-BE", "en",
"en-US", "en-EG", "en-AU", "en-GB", "en-CA", "en-NZ", "en-IE", "en-ZA", "en-JM",
Expand All @@ -10,5 +10,5 @@ export default {
"es", "es-AR", "es-GT", "es-CR", "es-PA", "es-DO", "es-MX", "es-VE", "es-CO",
"es-PE", "es-EC", "es-CL", "es-UY", "es-PY", "es-BO", "es-SV", "es-HN", "es-NI",
"es-PR", "sx", "sv", "sv-FI", "th", "ts", "tn", "tr", "uk", "ur", "ve", "vi", "xh",
"ji", "zu"],
"ji", "zu"]
}
7 changes: 1 addition & 6 deletions Frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pasteme",
"version": "2.1.2",
"version": "2.1.4",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -20,7 +20,6 @@
"prismjs": "^1.16.0",
"qs": "^6.7.0",
"vue": "^2.6.10",
"vue-axios": "^2.1.4",
"vue-cookie": "^1.1.4",
"vue-i18n": "^8.11.2",
"vue-router": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion Frontend/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module.exports = {
plugins: {
autoprefixer: {}
}
}
};
10 changes: 5 additions & 5 deletions Frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" class="max-height">
<html lang="zh-CN" class="max-height">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand All @@ -8,10 +8,10 @@
<meta itemprop="name" content="PasteMe" />
<meta itemprop="url" content="https://pasteme.cn/" />
<title>PasteMe - 一个不算糟糕的可私有文本分享平台</title>
<link rel="apple-touch-icon" sizes="60x60" href="../src/assets/touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="76x76" href="../src/assets/touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="120x120" href="../src/assets/touch-icon-iphone-retina.png">
<link rel="apple-touch-icon" sizes="152x152" href="../src/assets/touch-icon-ipad-retina.png">
<link rel="apple-touch-icon" sizes="60x60" href="../src/assets/img/touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="76x76" href="../src/assets/img/touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="120x120" href="../src/assets/img/touch-icon-iphone-retina.png">
<link rel="apple-touch-icon" sizes="152x152" href="../src/assets/img/touch-icon-ipad-retina.png">
<link rel="dns-prefetch" href="//ghbtns.com">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<script async src="<%= BASE_URL %>usr.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions Frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
},
mounted() {
if (this.$cookie.get('pasteme_lang') === null) {
this.$cookie.set('pasteme_lang', 'zh-CN', 30);
this.$cookie.set('pasteme_lang', 'zh-CN', 7);
}
this.$i18n.locale = this.$cookie.get('pasteme_lang');
this.setI18n(this.$cookie.get('pasteme_lang'));
}
}
</script>
Expand Down
27 changes: 27 additions & 0 deletions Frontend/src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import axios from 'axios'
import qs from 'qs'

export default {
get: function(url, params = {}) {
return new Promise((resolve, reject) => {
axios.get(url, {
params: params
}).then(response => {
resolve(response.data);
}).catch(error => {
alert(url + '\n' + JSON.stringify(error));
reject(error);
});
});
},
post: function(url, params = {}) {
return new Promise((resolve, reject) => {
axios.post(url, qs.stringify(params)).then(response => {
resolve(response.data);
}).catch(error => {
alert(url + '\n' + JSON.stringify(error));
reject(error);
});
});
}
}
Binary file removed Frontend/src/assets/donate.png
Binary file not shown.
Binary file added Frontend/src/assets/img/donate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Frontend/src/assets/img/touch-icon-ipad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Frontend/src/assets/img/touch-icon-iphone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions Frontend/src/assets/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@ export const lang = {
h2: 'Success!',
p: [
{
left: 'How to access this Paste ',
right: ':',
text: 'How to access this Paste <strong>{keyword}</strong> :',
},
{
button: 'Retrun',
button: 'Return',
},
],
ul: {
li: [
{
left: 'Enter its number in the navbar area.',
mid: '',
right: '',
text: 'Enter <strong>Paste\'s number</strong> in the nav bar area.',
},
{
browser: 'Direct click to access: ',
Expand All @@ -52,9 +49,7 @@ export const lang = {
],
},
popover: {
left: 'Enter ',
mid: 'Paste\'s number',
right: ' here to access to it.',
text: 'Enter <strong>Paste\'s number</strong> here to access to it.',
},
badge: {
copy: 'Copy',
Expand Down
11 changes: 3 additions & 8 deletions Frontend/src/assets/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export const lang = {
h2: '保存成功',
p: [
{
left: '欲访问',
right: '所对应的 Paste',
text: '欲访问 <strong>{keyword}</strong> 所对应的 Paste',
},
{
button: '返回主页',
Expand All @@ -38,9 +37,7 @@ export const lang = {
ul: {
li: [
{
left: '在导航栏中输入',
mid: '索引',
right: '',
text: '在导航栏中输入<strong>索引</strong>',
},
{
browser: '在浏览器中访问',
Expand All @@ -52,9 +49,7 @@ export const lang = {
],
},
popover: {
left: '在这里填入',
mid: '索引',
right: '即可查看相应的 Paste',
text: '在这里填入 <strong>索引</strong> 即可查看相应的 Paste',
},
badge: {
copy: '复制链接',
Expand Down
Binary file removed Frontend/src/assets/touch-icon-ipad-retina.png
Binary file not shown.
Binary file removed Frontend/src/assets/touch-icon-ipad.png
Binary file not shown.
Binary file removed Frontend/src/assets/touch-icon-iphone-retina.png
Binary file not shown.
Binary file removed Frontend/src/assets/touch-icon-iphone.png
Binary file not shown.
8 changes: 4 additions & 4 deletions Frontend/src/components/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
async getOne() {
let one = null;
do {
await this.axios.get('https://v1.hitokoto.cn?encode=text').then(response => {
one = response.data;
}).catch(error => {
alert(JSON.stringify(error) + '\n' + this.$t('lang.error.text'));
await this.api.get('https://v1.hitokoto.cn', {
encode: 'text'
}).then(response => {
one = response;
});
} while (one.replace(/[\u4e00-\u9fa5]/ig, '**').length > 100);
return one;
Expand Down
9 changes: 3 additions & 6 deletions Frontend/src/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@
if (this.$route.params.keyword !== '') {
this.form.keyword = this.$route.params.keyword;
}
this.axios.post(this.$store.state.config.api,
this.qs.stringify(this.form)).then(response => {
if (response.data.status === 201) {
this.api.post(this.$store.state.config.api, this.form).then(response => {
if (response.status === 201) {
this.$parent.view = 'success';
this.$parent.keyword = response.data.keyword;
this.$parent.keyword = response.keyword;
}
}).catch(error => {
alert(JSON.stringify(error) + '\n' + this.$t('lang.error.text'));
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions Frontend/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</div>
</b-popover>
<b-modal id="modal-donate" hide-footer lazy>
<img src="../assets/donate.png" alt="donate.png">
<img src="../assets/img/donate.png" alt="donate.png">
</b-modal>
</b-col>
</b-row>
Expand All @@ -89,7 +89,7 @@
this.keyword = null;
},
setLang(lang) {
this.$i18n.locale = lang;
this.setI18n(lang);
this.$cookie.set('pasteme_lang', lang, 7);
}
}
Expand Down
14 changes: 7 additions & 7 deletions Frontend/src/components/PasswordAuth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
methods: {
onSubmit(event) {
event.preventDefault();
this.axios.get(this.$store.state.config.api + '?browser=&token=' +
this.$route.params.keyword + ',' + this.form.password).then(response => {
if (response.data.status === 200) {
this.$parent.content = response.data.content;
this.$parent.type = response.data.type;
this.api.get(this.$store.state.config.api, {
browser: '',
token: this.$route.params.keyword + ',' + this.form.password,
}).then(response => {
if (response.status === 200) {
this.$parent.content = response.content;
this.$parent.type = response.type;
this.$parent.view = 'paste_view';
} else {
this.flag = false;
this.form.password = null;
}
}).catch(error => {
alert(JSON.stringify(error) + '\n' + this.$t('lang.error.text'));
});
}
}
Expand Down
10 changes: 3 additions & 7 deletions Frontend/src/components/Success.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
<h2>
{{ $t('lang.success.h2') }}
</h2>
<p>
{{ $t('lang.success.p[0].left') }}&nbsp;<b id="success_jumbotron_p_b">{{ $parent.keyword }}</b>&nbsp;{{ $t('lang.success.p[0].right') }}
</p>
<p v-html="$t('lang.success.p[0].text', { keyword: $parent.keyword })"></p>
<ul>
<li>{{ $t('lang.success.ul.li[0].left') }}<strong>{{ $t('lang.success.ul.li[0].mid') }}</strong>{{ $t('lang.success.ul.li[0].right') }}&nbsp;<b-badge
<li><a v-html="$t('lang.success.ul.li[0].text')"></a>&nbsp;<b-badge
pill class="badge-fixed"
href="#"
@mouseenter="popover_show = true"
Expand Down Expand Up @@ -49,9 +47,7 @@
:show.sync="popover_show"
target="nav_input"
placement="bottomright"
>
{{ $t('lang.success.popover.left') }}<strong>{{ $t('lang.success.popover.mid') }}</strong>{{ $t('lang.success.popover.right') }}
</b-popover>
><a v-html="$t('lang.success.popover.text')"></a></b-popover>
<b-popover
target="qr_code_link"
placement="auto"
Expand Down
41 changes: 29 additions & 12 deletions Frontend/src/i18n.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
/*
@File : i18n.js
@Contact : [email protected]
@License : (C)Copyright 2019, Lucien Shui
@Modify Time @Author @Version @Desciption
------------ ------- -------- -----------
2019-05-31 23:48 Lucien 1.0 None
*/
import Vue from 'vue'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n);

export default new VueI18n({
const i18n = new VueI18n({
locale: 'zh-CN',
fallbackLocale: 'zh-CN',
messages: {
'zh-CN': require('./assets/lang/zh-CN'),
'en': require('./assets/lang/en'),
'zh-CN': require('./assets/lang/zh-CN')
}
});

const loadedLanguages = ['zh-CN'];
const supportedLanguage = ['zh-CN', 'en'];

function setI18nLanguage(lang) {
i18n.locale = lang;
document.querySelector('html').setAttribute('lang', lang);
}

Vue.prototype.setI18n = function (lang) {
if (i18n.locale !== lang) {
if (supportedLanguage.includes(lang)) {
if (!loadedLanguages.includes(lang)) {
import(/* webpackChunkName: "lang-[request]" */ `./assets/lang/${lang}`).then(messages => {
i18n.setLocaleMessage(lang, messages);
loadedLanguages.push(lang);
setI18nLanguage(lang);
}).catch(error => {
alert(JSON.stringify(error));
});
} else setI18nLanguage(lang);
} else setI18nLanguage(supportedLanguage[0]);
}
};

export default i18n;
16 changes: 6 additions & 10 deletions Frontend/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VueQrcode from '@chenfengyuan/vue-qrcode'
import clipboard from 'clipboard'
import BootstrapVue from 'bootstrap-vue'
Expand All @@ -9,7 +7,7 @@ import App from './App.vue'
import router from './router'
import store from './store'
import i18n from './i18n'
import qs from 'qs'
import api from './api'

import '@/prism'
import '@/assets/js/daovoice.object'
Expand All @@ -24,23 +22,21 @@ library.add(faGlobeAsia);

let VueCookie = require('vue-cookie');
Vue.config.productionTip = false;
Vue.use(VueAxios, axios);
Vue.use(BootstrapVue);
Vue.use(VueCookie);
Vue.prototype.clipboard = clipboard;
Vue.prototype.qs = qs;
Vue.prototype.api = api;
Vue.component('QRCode', VueQrcode);
Vue.component('font-awesome-icon', FontAwesomeIcon);

(async function () {
await (function() {
return new Promise ((resolve, reject) => {
axios.get('./config.json').then(response => {
store.state.config = response.data;
api.get('./config.json').then(response => {
store.state.config = response;
resolve();
}).catch((error) => {
alert(JSON.stringify(error) + '\n' + this.$t('lang.error.text'));
reject();
}).catch(error => {
reject(error);
})
})
})();
Expand Down
Loading

0 comments on commit 388772c

Please sign in to comment.