const App = { mixins: [sharedMixin],/////共用的方法///// data() { return { mode: "add", loading: { list: false, add: false }, dialog: { addDialogStatus: false, }, Add_title: "新增语言包", currindex: '', direction: 'ltr', clearable: false, useritem: {}, list: [], other: {}, clearable: false, searchdata: { page: 1, page_size: 20, type: '', name: '', value: '', lang: '', platform_type: 1, }, Add_form: { id: 0, type: '', name: '', value: '', }, dhktype: '', dialogImageUrl: '', dialogVisible_img: false, langs: { list: [], symbol: '', }, rules: { platform_type: [ { required: true, message: '请选择平台类型', trigger: 'change' }, ], type: [ { required: true, message: '请输入类型', trigger: 'blur' }, ], name: [ { required: true, message: '请输入名称', trigger: 'blur' }, ], value: [ { required: true, message: '请输入值', trigger: 'blur' }, ], }, active: 0, platformTypeList: [ { id: 1, name: '供应商后台' }, { id: 2, name: '分销商后台' }, ], copiedText: '', inputText: '', }; }, mounted() { Promise.all([ this.getLanguageList(), ]).then(() => { setTimeout(() => { this.index(); }, 500); }).catch((error) => { this.loading.list = false; }); }, created() { }, methods: { async copyToClipboard(row, type) { let content = ''; if (type == 1) { content = row.type } else if (type == 2) { content = row.name } else if (type == 3) { content = "t('" + row.type + "." + row.name + "','" + row.value + "')" } else if (type == 4) { content = row.from_value } try { // 使用现代剪贴板 API await navigator.clipboard.writeText(content); this.$message.success('复制成功'); } catch (err) { console.log('复制失败'); // 兼容旧浏览器的降级方案 const textArea = document.createElement('textarea'); textArea.value = content; document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); this.$message.success('复制成功'); } }, createJson() { var that = this; that.$confirm( '确定重新生成吗?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { let url = "/admin/" + viewPath + "/createJson.html" postRequest(url, {}).then(res => { if (res.data.code == 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }); ///////////// }).catch(() => { //取消 }) }, // 新增语言包 handleAdd() { this.Add_form = { id: '', type: this.dhktype,//类型 name: '', value: '', lang: this.langs.symbol,//语言标识 platform_type: this.searchdata.platform_type,//平台类型 } this.dialog.addDialogStatus = true; this.mode = "add"; }, // 同步 handleSync() { var that = this; that.$confirm( '当前语言包同步首个语言,确定要同步?', '', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { that.loading.list = true; var formData = { from_id: that.langs['list'][0]['id'], to_id: that.langs['list'][that.active]['id'], platform_type: that.searchdata.platform_type } let url = "/admin/" + viewPath + "/sync.html" postRequest(url, formData).then(res => { if (res.data.code == 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); that.index(); } else { that.loading.list = false; that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }); }).then(() => { }); }, // 翻译 handleTrans() { var that = this; that.$confirm( '翻译未填写的值,确定要翻译?', '', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { that.loading.list = true; var formData = { from_id: that.langs['list'][0]['id'], to_id: that.langs['list'][that.active]['id'], platform_type: that.searchdata.platform_type } let url = "/admin/" + viewPath + "/trans.html" postRequest(url, formData).then(res => { if (res.data.code == 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); that.index(); } else { that.loading.list = false; that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }); }).then(() => { }); }, ///修改扩展字段的值//// updateExt(row, field) { if (row.id) { let that = this; let url = "/admin/" + viewPath + "/updateExt.html" postRequest(url, { id: row.id, [field]: row[field] }).then(res => { if (res.data.code == 200) { that.$notify({ title: "成功", message: res.data.message, position: "top-left", type: "success", }); } else { that.$notify.error({ title: "错误", position: "top-left", message: res.data.message, }); } }); } }, del(index) { var that = this; let { id } = that.list[index]; that.$confirm( '确定删除吗?', '警告', { confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { let url = "/admin/" + viewPath + "/delete.html" postRequest(url, { id: id }).then(res => { if (res.data.code == 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); that.list.splice(index, 1) that.other.count--; } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }); ///////////// }).catch(() => { //取消 }) }, ///清空值//// clearValue(index) { var that = this; let { id } = that.list[index]; that.$confirm( '确定清空值吗?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { let url = "/admin/" + viewPath + "/clearValue.html" postRequest(url, { id: id }).then(res => { if (res.data.code == 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); this.list[index].value = ''; } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }); ///////////// }).catch(() => { //取消 }) }, Add(index) { this.Add_title = "编辑语言包"; this.Add_form = this.list[index]; this.loading.add = false; this.dialog.addDialogStatus = true; this.mode = "edit"; }, submit() { let that = this; that.loading.add = true; that.dhktype = that.Add_form.type; let url = "/admin/" + viewPath + "/save.html" postRequest(url, that.Add_form).then(res => { that.loading.add = false; if (res.data.code == 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); this.dialog.addDialogStatus = false; that.index(); } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }).then((res) => { that.loading.add = false; }); }, handleSizeChange(val) { //////设置每页多少条 this.searchdata.page_size = val this.index(); }, handleCurrentChange(val) { ///改变当前页/////// this.searchdata.p = val this.index(); }, index() { let that = this; that.loading.list = true; let url = "/admin/" + viewPath + "/index.html" postRequest(url, that.searchdata).then(res => { that.loading.list = false; if (res.data.code == 200) { that.list = res.data.list; that.other = res.data.other; } else { that.list = []; } }); }, getLanguageList() { let that = this; let url = "/admin/" + viewPath + "/getLanguageList.html" postRequest(url, {}).then(res => { if (res.data.code == 200) { that.langs.list = res.data.list; that.langs.symbol = res.data.list[0]['symbol'] that.searchdata.lang = that.langs.symbol; } else { that.langs.list = []; that.langs.symbol = ''; } }); }, handChange(data) { // that.list = []; // that.other = {}; this.active = this.langs.list.findIndex((item) => item.symbol === data); this.searchdata.lang = data this.index(); }, } }; const app = Vue.createApp(App); for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component) } app.use(ElementPlus, { locale: ElementPlusLocaleZhCn, }); app.mount("#vue_item");