diff --git a/src/axios/fetch.js b/src/axios/fetch.js index 82dc914..6a7906f 100644 --- a/src/axios/fetch.js +++ b/src/axios/fetch.js @@ -1,8 +1,8 @@ import axios from 'axios' export const api = axios.create({ - baseURL: 'https://ccb.canary.moe/api/', - // baseURL: window.location.origin + '/api/', + // baseURL: 'https://ccb.canary.moe/api/', + baseURL: window.location.origin + '/api/', // baseURL: 'http://152.136.99.231:8001' + '/api/', headers: { 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/src/utils/language.js b/src/utils/language.js new file mode 100644 index 0000000..8a2fc33 --- /dev/null +++ b/src/utils/language.js @@ -0,0 +1,252 @@ +export function lang() { + return { + home: { + CHS: { + title: '密码本', + search: '搜索...', + menu: ['按首字母', '按最常使用'], + drawer: ['账户', '设置', '分享链接', '下载apk', '立即锁定'], + empty_state: { + label: '创建你的第一个密码', + description: '创建密码后,您就可以将信息上载到服务器并保存', + button: '立即创建' + }, + unlock_msg: { + expired: '密码校验过期,请重新输入', + wrong: '密码错误,请重新输入' + }, + copy: { + successful: '恭喜!复制成功', + failed: '抱歉,复制失败。夸克等浏览器复制成功也会报错,请试着粘贴看看' + } + }, + EN: { + title: 'Codebook', + search: 'Search...', + menu: ['Alphabetically', 'Recently Used'], + drawer: ['Account', 'Settings', 'Share', 'Download apk', 'Lock Now'], + empty_state: { + label: 'Create your first code', + description: "Creating code, you'll be able to upload your information to the server and save it.", + button: 'Create first code' + }, + unlock_msg: { + expired: 'Password validity period has expired, please re-enter.', + wrong: 'Wrong password, please re-enter.' + }, + copy: { + successful: 'Copy successful', + failed: 'Failed to copy, but failed in some cases. Try to paste' + } + } + }, + settings: { + CHS: { + title: '设置', + subheader: ['重置', '选项'], + reset_list: ['账户', '密码本', '应用', '主密码'], + option_list: ['语言', '黑暗模式', '密码超时时间'], + expired_time: '无限', + dialog: { + title: '输入新的主密码', + placeholder: '输入...', + confirm: '完成', + cancel: '取消' + }, + snakebar_msg: { + reset_account: '恭喜! 账户重置完成', + reset_codebook: '恭喜! 密码本重置完成', + reset_settings: '恭喜! 个性化设置成功', + reset_pwd_failed: '密码不能为空', + reset_pwd_successful: '恭喜! 新的密码已经应用' + } + }, + EN: { + title: 'Settings', + subheader: ['Reset', 'Option'], + reset_list: ['Account', 'Codebook', 'Application', 'Main Password'], + option_list: ['Language', 'Dark Mode', 'Expired Time'], + expired_time: 'Infinite', + dialog: { + title: 'Enter new password', + placeholder: 'Enter here...', + confirm: 'Done', + cancel: 'Cancel' + }, + snakebar_msg: { + reset_account: 'Congratulations! Reset account completed', + reset_codebook: 'Congratulations! Reset codebook completed', + reset_settings: 'Congratulations! Reset settings completed', + reset_pwd_failed: 'Password can not be none', + reset_pwd_successful: 'Congratulations! New password set up successfully' + } + } + }, + detail: { + CHS: { + label: ['用户名', '密码', '网址', '备注'], + copy: { + successful: '恭喜!复制成功', + failed: '抱歉,复制失败。夸克等浏览器复制成功也会报错,请试着粘贴看看' + }, + snakebar_msg_empty: '网址为空', + empty_placeholder: '空空如也呢', + dialog: { + title: "删除该记录", + content: "此操作不可复原,是否继续", + confirm: "删除", + cancel: "取消" + } + }, + EN: { + label: ['Username', 'Password', 'Web address', 'Node'], + copy: { + successful: 'Copy successful', + failed: 'Failed to copy, but failed in some cases. Try to paste' + }, + snakebar_msg_empty: 'Web address is empty', + empty_placeholder: 'Empty', + dialog: { + title: "Delete this password?", + content: "This operation cannot be resumed. Are you sure to continue?", + confirm: "Continue", + cancel: "Cancel" + } + } + }, + add: { + CHS: { + title: ['新建密码', '编辑'], + subheader: ['密码标题', '用户名', '密码', '网址', '备注...'], + enter: '提交', + empty_error: ['密码标题不可为空', '用户名不可为空', '密码不可为空'] + }, + EN: { + title: ['Add New Code', 'Edit'], + subheader: ['Code Title', 'Username', 'Password', 'Web address', 'Node'], + enter: 'Enter', + empty_error: ['Title can not be none.', 'Username can not be none.', 'Password can not be none.'] + } + }, + account: { + CHS: { + title: '账户', + login: { + input_placeholder: ['邮箱地址', '密码'], + password_errmsg: '密码不能为空', + submit: '登录 / 注册' + }, + activation: { + title: '恭喜! 激活码已经下发到你的邮箱', + subheader: '激活码', + input_errmsg: '激活码不可为空', + submit: '立即激活' + }, + account: { + label: ['云端信息最后修改时间', '同步本地密码本至云端', '同步云端密码本至本地'], + logout: '退出登录' + }, + mail_addr_errmsg: ['邮箱地址不能为空', '邮箱地址不合法'], + snakebar_msg: ['抱歉, 网络错误', + '恭喜! 登录成功!', + '恭喜! 请在您的邮箱里找到激活码!', + '抱歉, 密码错误, 请重新输入', + '抱歉, 网络错误. 错误码:', + '恭喜! 激活成功!', + '抱歉, 激活码错误, 请重新输入', + '恭喜! 本地数据更新成功!', + '恭喜! 云端数据更新成功!' + ] + }, + EN: { + title: 'Account', + login: { + input_placeholder: ['Mail addr', 'Password'], + password_errmsg: 'Password can not be none.', + submit: 'Login / Sign' + }, + activation: { + title: 'Congratulations! Activation code has been sent to your email', + subheader: 'Activation Code', + input_errmsg: 'Activation Code can not be none.', + submit: 'activation' + }, + account: { + label: ['Cloud last modified time', 'Sync local codebook to cloud', 'Sync cloud codebook to local'], + logout: 'Logout' + }, + mail_addr_errmsg: ['Mail addr can not be none.', 'Mail addr is invalid.'], + snakebar_msg: ['Sorry, network error', + 'Congratulations! Login is successful!', + 'Congratulations! Please find the activation code in your email!', + 'Sorry, the password is wrong, please re-enter', + 'Sorry, network error. errcode:', + 'Congratulations! Activation is successful!', + 'Sorry, the activation is wrong, please re-enter', + 'Congratulations! Local data update completed!', + 'Congratulations! Cloud data update completed!' + ] + } + }, + unlock: { + CHS: { + title: ['创建主密码','解锁'], + subheader: ['创建主密码', '解锁Canary Codebook'], + pwd_label: ['主密码','解锁密码'], + repeat_pwd: '再次输入主密码', + enter: '提交', + dialog: { + title: '确认提交', + content: '该密码提交之后不可被修改, 请不要将此密码告诉任何人', + confirm: '同意', + cancel: '不同意' + }, + empty_pwd_error: '主密码不能为空', + wrong_pwd_error: '主密码错误', + match_pwd_error: '两次输入密码不一致' + }, + EN: { + title: ['Create Password','Unlock'], + subheader: ['Create New Password', 'Unlock Canary Codebook'], + pwd_label: ['New Password','Unlock Password'], + repeat_pwd: 'Repeat Password', + enter: 'Enter', + dialog: { + title: 'Confirm you new password?', + content: 'The password will not be modified after submission, please make sure you don’t tell anyone this password.', + confirm: 'Agree', + cancel: 'Disagree' + }, + empty_pwd_error: 'Password can not be none', + wrong_pwd_error: 'Wrong password', + match_pwd_error: 'The two passwords do not match' + } + } + } +} + +/** + * 引入 + import { lang } from '@/utils/language.js' + + * data 里边加入lang + data -> lang + + * create() 初始化语言系统,防止报错 + this.lang = lang().home.CHS + console.log('临时语言系统加载完成') + + * computed 获取settings + ...mapState(['user_infos', 'row_data', 'row_pwd', 'settings']) + + * 在合适的地方配置语言 + // 配置语言 + initLanguage() { + if(this.settings.is_chinese) { + this.lang = lang().home.CHS + } else { + this.lang = lang().home.EN + } + console.log('语言配置完成') + }, +*/ diff --git a/src/views/Account/Account.vue b/src/views/Account/Account.vue index e565945..8dfebf5 100644 --- a/src/views/Account/Account.vue +++ b/src/views/Account/Account.vue @@ -4,7 +4,7 @@
arrow_back -

Account

+

{{lang.title}}

@@ -12,17 +12,17 @@ @@ -84,6 +84,7 @@ import { mapState, mapActions } from 'vuex'; import { encrypt, decrypt, encryptMainCode, decryptMainCode } from '@/utils/aes.js'; import { login, activation, syncLocal, syncCloud } from '@/axios/api.js' +import { lang } from '@/utils/language.js' export default { name: 'Add', @@ -102,11 +103,12 @@ export default { login_loading: false, activation_loading: false, show_snackbar: false, - snakebar_msg:'' + snakebar_msg:'', + lang:'' }; }, computed: { - ...mapState(['user_infos', 'row_data', 'row_pwd']), + ...mapState(['user_infos', 'row_data', 'row_pwd','settings']), update_time:function() { return this.formatDateTime(new Date(parseInt(this.user_infos.update_time))); }, @@ -118,6 +120,7 @@ export default { init() { // 刷新vuex this.$store.replaceState(Object.assign(this.$store.state, JSON.parse(localStorage.getItem('storeState')))); + this.initLanguage() // 判断页面类型 if(this.user_infos.has_login) { // 已经登录 @@ -134,7 +137,17 @@ export default { } console.log('当前用户状态为'+ this.page_type) }, - + + // 配置语言 + initLanguage() { + if(this.settings.is_chinese) { + this.lang = lang().account.CHS + } else { + this.lang = lang().account.EN + } + console.log('语言配置完成') + }, + //返回上一页 back() { this.$router.go(-1); @@ -155,13 +168,13 @@ export default { if(!(this.mail_addr = this.mail_addr.trim())) { can_continue = false this.mail_addr_verify = false - this.mail_addr_errmsg = 'Mail addr can not be none.' + this.mail_addr_errmsg = this.lang.mail_addr_errmsg[0] } let reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ if(!reg.test(this.mail_addr)) { can_continue = false this.mail_addr_verify = false - this.mail_addr_errmsg = 'Mail addr is invalid.' + this.mail_addr_errmsg = this.lang.mail_addr_errmsg[1] } // 处理password if(!(this.password = this.password.trim())) { @@ -186,7 +199,7 @@ export default { }).catch(err => { console.log(err) this.login_loading = false - this.snakebar_msg = 'Sorry, network error' + this.snakebar_msg = this.lang.snakebar_msg[0] this.show_snackbar = true }) }, @@ -204,7 +217,7 @@ export default { } this.setUserInfo([user_infos, this]); console.log('正常用户登录,用户信息覆写完成'); - this.snakebar_msg = 'Congratulations! Login is successful!' + this.snakebar_msg = this.lang.snakebar_msg[1] this.show_snackbar = true this.page_type = 'account' } else if(data.errcode == 107 || data.errcode == 108 || data.errcode == 105) { @@ -218,18 +231,18 @@ export default { } this.setUserInfo([user_infos, this]); console.log('用户注册成功,验证码已下发,用户信息覆写完成'); - this.snakebar_msg = 'Congratulations! Please find the activation code in your email!' + this.snakebar_msg = this.lang.snakebar_msg[2] this.show_snackbar = true this.page_type = 'activation' } else if (data.errcode == 106) { this.password = '' console.log('用户密码错误'); - this.snakebar_msg = 'Sorry, the password is wrong, please re-enter' + this.snakebar_msg = this.lang.snakebar_msg[3] this.show_snackbar = true } else { console.log('请求出错'); console.log(data) - this.snakebar_msg = 'Sorry, network error. errcode:' + data.errcode + this.snakebar_msg = this.lang.snakebar_msg[4] + data.errcode this.show_snackbar = true } this.login_loading = false @@ -261,7 +274,7 @@ export default { }).catch(err => { console.log(err) this.activation_loading = false - this.snakebar_msg = 'Sorry, network error' + this.snakebar_msg = this.lang.snakebar_msg[0] this.show_snackbar = true }) }, @@ -279,7 +292,7 @@ export default { } this.setUserInfo([user_infos, this]); console.log('验证成功,用户信息覆写完成'); - this.snakebar_msg = 'Congratulations! Activation is successful!' + this.snakebar_msg = this.lang.snakebar_msg[5] this.show_snackbar = true this.page_type = 'account' } else if(data.errcode == 401 || data.errcode == 404 || data.errcode == 407) { @@ -287,12 +300,12 @@ export default { this.activation_code = '' console.log('验证码错误'); console.log(data) - this.snakebar_msg = 'Sorry, the activation is wrong, please re-enter' + this.snakebar_msg = this.lang.snakebar_msg[6] this.show_snackbar = true } else { console.log('请求出错'); console.log(data) - this.snakebar_msg = 'Sorry, network error. errcode:' + data.errcode + this.snakebar_msg = this.lang.snakebar_msg[4] + data.errcode this.show_snackbar = true } this.activation_loading = false @@ -329,13 +342,13 @@ export default { // 获取成功 this.setRowData([res.data.codebook, this]) console.log('数据获取成功,密码本覆写成功') - this.snakebar_msg = 'Congratulations! Local data update completed!' + this.snakebar_msg = this.lang.snakebar_msg[7] this.show_snackbar = true } else { // 获取失败 console.log('数据获取失败') console.log(res.data) - this.snakebar_msg = 'Sorry, network error. errcode:' + res.data.errcode + this.snakebar_msg = this.lang.snakebar_msg[4] + res.data.errcode this.show_snackbar = true } setTimeout(function(){ @@ -344,7 +357,7 @@ export default { }).catch(err => { console.log(err) this.sync_local_loading = false - this.snakebar_msg = 'Sorry, network error' + this.snakebar_msg = this.lang.snakebar_msg[0] this.show_snackbar = true }) }, @@ -366,13 +379,13 @@ export default { user_infos.update_time = res.data.update_time this.setUserInfo([user_infos, this]); console.log('数据获取成功,用户信息覆写成功') - this.snakebar_msg = 'Congratulations! Cloud data update completed!' + this.snakebar_msg = this.lang.snakebar_msg[8] this.show_snackbar = true } else { // 获取失败 console.log('数据获取失败') console.log(res.data) - this.snakebar_msg = 'Sorry, network error. errcode:' + res.data.errcode + this.snakebar_msg = this.lang.snakebar_msg[4] + res.data.errcode this.show_snackbar = true } setTimeout(function(){ @@ -381,7 +394,7 @@ export default { }).catch(err => { console.log(err) this.sync_cloud_loading = false - this.snakebar_msg = 'Sorry, network error' + this.snakebar_msg = this.lang.snakebar_msg[0] this.show_snackbar = true }) }, @@ -402,6 +415,8 @@ export default { }, created() { + this.lang = lang().account.CHS + console.log('临时语言系统加载完成') this.init() }, mounted() {}, diff --git a/src/views/Add/Add.vue b/src/views/Add/Add.vue index 653873f..2045c10 100644 --- a/src/views/Add/Add.vue +++ b/src/views/Add/Add.vue @@ -4,40 +4,40 @@
arrow_back -

{{id_cache?'Edit':'Add New Code'}}

+

{{id_cache?lang.title[1]:lang.title[0]}}

- + - Title can not be none. + {{lang.empty_error[0]}} - + - Username can not be none. + {{lang.empty_error[1]}} - + - Password can not be none. + {{lang.empty_error[2]}} - + - + - Enter + {{lang.enter}} @@ -47,6 +47,7 @@ // @ is an alias to /src import { mapState, mapActions } from 'vuex'; import { encrypt, decrypt, encryptMainCode, decryptMainCode } from '@/utils/aes.js'; +import { lang } from '@/utils/language.js' export default { name: 'Add', @@ -61,7 +62,8 @@ export default { open_count_cache:'', title_verify: true, user_name_verify: true, - password_verify: true + password_verify: true, + lang:'' }; }, computed: { @@ -81,6 +83,7 @@ export default { if (now - this.row_pwd.create_time < this.settings.expired_time) { // 上次写入时间距离现在在(默认五分钟)之内 // 判断是否是更新 + this.initLanguage() if (this.$route.params.modify_content) { // 刷新重置数据 let content = this.$route.params.modify_content @@ -103,6 +106,16 @@ export default { } }, + // 配置语言 + initLanguage() { + if(this.settings.is_chinese) { + this.lang = lang().add.CHS + } else { + this.lang = lang().add.EN + } + console.log('语言配置完成') + }, + // 对输入框里边的内容进行判断 judgeContent() { // 设置flag @@ -222,6 +235,8 @@ export default { } }, created() { + this.lang = lang().add.CHS + console.log('临时语言系统加载完成') this.init() }, mounted() {}, diff --git a/src/views/Detail/Detail.vue b/src/views/Detail/Detail.vue index 642ba39..9e94fb1 100644 --- a/src/views/Detail/Detail.vue +++ b/src/views/Detail/Detail.vue @@ -15,14 +15,14 @@ - +

{{content.user_name}}

- +

{{show_password? content.password : doitPassword}}

remove_red_eye @@ -30,25 +30,25 @@
- +
-

{{content.web_address? content.web_address : 'Empty'}}

+

{{content.web_address? content.web_address : lang.empty_placeholder}}

open_in_new
- +
-

{{content.node ? content.node : 'Empty'}}

+

{{content.node ? content.node : lang.empty_placeholder}}

@@ -64,6 +64,7 @@ // @ is an alias to /src import { mapState, mapActions } from 'vuex'; import { encrypt, decrypt, encryptMainCode, decryptMainCode } from '@/utils/aes.js'; +import { lang } from '@/utils/language.js' export default { name: 'Add', @@ -73,7 +74,8 @@ export default { snakebar_msg: '', content: {}, show_password: false, - show_dialog: false + show_dialog: false, + lang:'' }; }, computed: { @@ -104,6 +106,7 @@ export default { if (now - this.row_pwd.create_time < this.settings.expired_time) { // 上次写入时间距离现在在(默认五分钟)之内 // 刷新重置数据 + this.initLanguage() this.content = this.$route.params.code_content this.addCount() } else { @@ -120,6 +123,15 @@ export default { } }, + // 配置语言 + initLanguage() { + if(this.settings.is_chinese) { + this.lang = lang().detail.CHS + } else { + this.lang = lang().detail.EN + } + console.log('语言配置完成') + }, //返回上一页 back() { @@ -139,13 +151,13 @@ export default { // 复制成功 onCopyUrl(e) { - this.snakebar_msg = 'Copy successful'; + this.snakebar_msg = this.lang.copy.successful; this.show_snackbar = true; }, // 复制失败 onErrorUrl(e) { - this.snakebar_msg = 'Failed to copy, but failed in some cases. Try to paste'; + this.snakebar_msg = this.lang.copy.failed; this.show_snackbar = true; }, @@ -154,7 +166,7 @@ export default { if(this.content.web_address) { window.open(this.content.web_address) } else { - this.snakebar_msg = 'Web address is empty.'; + this.snakebar_msg = this.lang.snakebar_msg_empty; this.show_snackbar = true; } }, @@ -213,6 +225,8 @@ export default { } }, created() { + this.lang = lang().detail.CHS + console.log('临时语言系统加载完成') this.init() }, mounted() {}, diff --git a/src/views/Home/Home.vue b/src/views/Home/Home.vue index c783510..ec83ab9 100644 --- a/src/views/Home/Home.vue +++ b/src/views/Home/Home.vue @@ -4,20 +4,20 @@
menu - Codebook + {{lang.title}}
search more_vert - Alphabetically - Recently Used + {{lang.menu[0]}} + {{lang.menu[1]}}
- +
@@ -31,7 +31,7 @@ person - Account + {{lang.drawer[0]}}