const App = {
|
mixins: [sharedMixin],/////共用的方法/////
|
data() {
|
return {
|
Add_form: {
|
father_id: 0,
|
langs: [],
|
},
|
Add_title: "添加菜单",
|
dialogVisible_menu: false,
|
ifsubmit: false,
|
list: [],
|
|
langs: [],
|
active: 0,
|
lang_1: '',///当前语言/////
|
loadingTran: false,///翻译加载中/////
|
|
|
};
|
},
|
mounted() {
|
Promise.all([
|
this.getLanguageList(),
|
|
]).then(() => {
|
this.index();
|
}).catch((error) => {
|
});
|
},
|
created() { },
|
methods: {
|
async handChange(data) {
|
let lang_last = this.lang_1;///当前语言保存到 lang_last中/////
|
this.lang_1 = data//更新当前语言
|
const index = this.languages.list.findIndex((item) => item.symbol === data);
|
this.active = index;///更新当前语言索引
|
|
//数组存储
|
if (lang_last != "") {
|
let arr = {
|
'lang': lang_last,
|
'title': this.Add_form.title,
|
}
|
let array = this.pushArr(this.langs, lang_last, arr);
|
this.langs = array;
|
}
|
//输入初始化
|
let arr2 = {
|
'lang': data,
|
'title': "",
|
}
|
Object.keys(this.langs).forEach((key) => {
|
if (this.langs[key]['lang'] == data) {
|
arr2 = this.langs[key];
|
}
|
})
|
|
|
if (lang_last != "") {
|
Object.keys(arr2).forEach((key) => {
|
this.Add_form[key] = arr2[key]
|
})
|
}
|
this.Add_form.langs = this.langs;
|
},
|
async handTranslation(field) {
|
|
//查询首个语言是否填写
|
let exists = false;
|
let langs_key = 0;
|
|
Object.keys(this.langs).forEach((key) => {
|
if (this.langs[key]['lang'] == this.languages.list[0]['symbol']) {
|
if (this.langs[key][field] != "") {
|
exists = true;
|
langs_key = parseInt(key);
|
}
|
}
|
})
|
if (!exists) {
|
that.$message({
|
message: '首个语言必填',
|
type: 'error',
|
duration: 1500,
|
center: true
|
});
|
}
|
const qArray = [this.langs[langs_key][field]]
|
|
this.loadingTran = true;
|
const res = await this.translation({
|
qArray: qArray,
|
from: this.languages.list[0]['trans_symbol'],
|
to: this.languages.list[this.active]['trans_symbol']
|
})
|
this.Add_form[field] = res[0]['translation'];
|
this.loadingTran = false;
|
},
|
async translation(params) {
|
return new Promise((resolve, reject) => {
|
let url = "/admin/translation/trans.html";
|
postRequest(url, params).then(res => {
|
if (res.data.code == 200) {
|
resolve(res.data);
|
} else {
|
reject(res.data);
|
}
|
});
|
});
|
|
},
|
pushArr(arr, lang, params) {
|
let result = false;
|
Object.keys(arr).forEach((key) => {
|
if (arr[key]['lang'] == lang) {
|
arr[key] = params;
|
result = true;
|
}
|
})
|
|
if (!result) {
|
arr.push(params);
|
}
|
return arr;
|
},
|
index() {
|
let that = this;
|
let url = "/admin/" + viewPath + "/index.html"
|
postRequest(url, {}).then(res => {
|
if (res.data.code == 200) {
|
that.list = res.data.list;
|
}
|
});
|
},
|
updateShowMenu(row) {
|
var { id, show_menu } = row;
|
let url = "/admin/" + viewPath + "/updateShowMenu.html"
|
postRequest(url, { id: id, show_menu: show_menu }).then(res => {
|
if (res.data.code != 200) {
|
row.show_menu = show_menu == 1 ? 0 : 1;//修改失败,恢复状态
|
}
|
});
|
},
|
Add() {
|
this.active = 0;
|
this.Add_title = "添加菜单";
|
this.Add_form = {
|
father_id: 0,
|
langs: [],
|
}
|
this.languages.symbol = this.languages.list[0]['symbol'];
|
this.lang_1 = this.languages.symbol
|
this.dialogVisible_menu = true;
|
|
},
|
Edit(row) {
|
var { id } = row;
|
let url = "/admin/" + viewPath + "/getMenuDetail.html";
|
postRequest(url, { id: id }).then(res => {
|
if (res.data.code == 200) {
|
this.active = 0;
|
this.Add_title = "编辑菜单";
|
this.Add_form = res.data.info;
|
this.languages.symbol = this.languages.list[0]['symbol'];
|
this.lang_1 = this.languages.symbol
|
this.langs = row.langs
|
this.dialogVisible_menu = true;
|
}
|
else {
|
that.$message({
|
message: res.data.message,
|
type: 'error',
|
duration: 1500,
|
center: true
|
});
|
}
|
});
|
|
|
|
},
|
/////保存菜单/////
|
saveMenu() {
|
var that = this;
|
|
//数组存储
|
let arr = {
|
'lang': this.languages.symbol,
|
'title': this.Add_form.title,
|
}
|
|
//数组更新
|
let array = this.pushArr(this.langs, this.languages.symbol, arr);
|
this.langs = array;
|
|
//查询首个语言是否填写
|
let exists = false;
|
let langs_key = 0;
|
Object.keys(this.langs).forEach((key) => {
|
if (this.langs[key]['lang'] == this.languages.list[0]['symbol']) {
|
if (this.langs[key]['title'] != "") {
|
exists = true;
|
langs_key = parseInt(key);
|
}
|
}
|
})
|
if (!exists) {
|
that.$message({
|
message: '首个语言必填',
|
type: 'error',
|
duration: 1500,
|
center: true
|
});
|
}
|
|
//输入初始化
|
let arr2 = this.langs[langs_key];
|
Object.keys(arr2).forEach((key) => {
|
this.Add_form[key] = arr2[key]
|
})
|
this.Add_form.langs = this.langs;
|
if (that.ifsubmit) {
|
return false;
|
}
|
that.ifsubmit = true;
|
let url = "/admin/" + viewPath + "/saveMenu.html";
|
postRequest(url, that.Add_form).then(res => {
|
if (res.data.code == 200) {
|
that.$message({
|
message: res.data.message,
|
type: 'success',
|
duration: 1000,
|
center: true,
|
onClose: function () {
|
that.ifsubmit = false;
|
that.dialogVisible_menu = false;
|
that.index();
|
|
}
|
});
|
}
|
else {
|
that.ifsubmit = false;
|
that.$message({
|
message: res.data.message,
|
type: 'error',
|
duration: 1500,
|
center: true
|
});
|
}
|
});
|
},
|
|
}
|
};
|
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");
|