frontSide.vue
10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<template>
<div class="manage-container deviceStatus-wrapper">
<el-row class="manage-head-wrapper">
<el-col :span="24" :sm="24">
<span class="condition-item-text">关键词:</span>
<div class="manage-select-box">
<el-input v-model="keyWord" class="search-inp" placeholder="请输入要查询的关键词" clearable />
</div>
<el-button type="primary" class="search-btn" plain size="mini" @click="searchData()">
{{ $t('button.search') }}</el-button>
<el-button type="primary" class="search-btn" plain size="mini" @click="addData()">{{ '添加' }}</el-button>
<!-- <el-button type="primary" style="float:right" class="search-btn" plain size="mini" @click="exportData()">
导出<i class="el-icon-download el-icon--right"></i></el-button> -->
<el-button type="primary" style="float:right" class="search-btn" plain size="mini" @click="saveData()">
提交配置</el-button>
</el-col>
</el-row>
<el-row class="manage-content">
<el-col :span="24">
<el-table id="languageTable" :data="tableData" border :max-height="tableHeight" v-loading="loading" style="width: 100%"
:span-method="tabSpanMethod" header-row-class-name="manage-tab-head">
<el-table-column label="模块" align="center">
<template #default="{ row }">
{{ row.key1 }}
</template>
</el-table-column>
<el-table-column label="Key" align="center">
<template #default="{ row }">
{{ row.key2 }}
</template>
</el-table-column>
<!-- <el-table-column label="Mall中文" align="center" prop="mall">
<template #default="{ row }">
<el-input class="nborder" v-model="row.mall" />
</template>
</el-table-column> -->
<el-table-column label="中文" align="center" prop="zh">
<template #default="{ row }">
<el-input class="nborder" v-model="row.zh" />
</template>
</el-table-column>
<el-table-column label="英文" align="center" prop="en">
<template #default="{ row }">
<el-input class="nborder" v-model="row.en" />
</template>
</el-table-column>
<el-table-column label="繁体" align="center" prop="tw">
<template #default="{ row }">
<el-input class="nborder" v-model="row.tw" />
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
<add-dialog ref="addModel" @submit="addField" :loading="dloading" :module-list="moduleList"></add-dialog>
</div>
</template>
<script>
var tempTableData = [];
import _ from 'underscore';
import addDialog from "./add";
export default {
data() {
let that = this;
return {
keyWord: '',
dloading: false,
loading: true,
moduleList: [],
tableData: []
}
},
components: {
"add-dialog": addDialog
},
computed: {
tableHeight() {
const windowInnerHeight = window.innerHeight
return windowInnerHeight - 200
},
},
mounted() {
},
created() {
this.getLangData();
window.language = this;
},
methods: {
exportData(){
this.dealExport('languageTable','国际化文件');
},
async searchData(isAdd) {
this.loading = true;
await this.timeWait(100);
if (!this.keyWord) {
this.tableData = tempTableData;
this.$nextTick(() => {
setTimeout(() => {
this.loading = false;
if (isAdd) {
this.$message({
message: '添加成功,编辑完点击右上角提交',
type: 'success'
});
}
}, 1500);
})
return;
}
let list = _.filter(tempTableData, item => {
return [item.zh, (item.en || '').toLowerCase(), item.tw].join('#').includes(this.keyWord.toLowerCase());
})
this.tableData = this.colSpanList(list);
this.$nextTick(() => {
setTimeout(() => {
this.loading = false;
}, 1500);
})
},
timeWait(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, time);
})
},
colSpanList(list) {
let klist = [];
let keys = _.uniq(_.pluck(list, 'key1'));
_.each(list, item => {
if (klist.includes(item.key1)) {
item.rspan = 0;
} else {
klist.push(item.key1);
item.rspan = _.where(list, { key1: item.key1 }).length
}
})
return list;
},
async addField(data) {
if (!/^[a-z]|[A-Z]/.test(data.key2)) {
this.$refs.addModel.hideLoading();
return this.$message({
showClose: true,
type: "error",
message: 'Key首字母必须以英文开头'
});
}
let item = _.findWhere(tempTableData, { key1: data.key1, key2: data.key2 });
if (item) {
this.$refs.addModel.hideLoading();
return this.$message({
showClose: true,
type: "error",
message: data.key1 + '模块下该Key值已存在'
});
}
let index = _.findIndex(tempTableData, { key1: data.key1 });
let rspan = tempTableData[index].rspan;
tempTableData[index].rspan = rspan + 1;
tempTableData.splice(index + rspan, 0, {
...data,
rspan: 0
});
this.searchData(true);
this.$refs.addModel.closeDialog();
},
// 新搜索条件 end
async getLangData() {
Promise.all([this.loadLang('en_US'),this.loadLang('zh_TW'),this.loadLang('zh_CN')]).then(res=>{
this.setTableData({
en: res[0].data,
tw: res[1].data,
zh: res[2].data
});
});
},
loadLang(lang) {
return this.$api.management.getLanguage({ lang });
},
setLang(lang, content) {
let formData = new FormData();
formData.append('content', content);
return this.$api.management.setLanguage(lang, formData, {
headers: {
'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'
}
});
},
setTableData(data) {
let key1s = _.keys(data.zh);
this.moduleList = key1s;
tempTableData = [];
_.each(key1s, key1 => {
let key2s = _.keys(data.zh[key1]);
let length = key2s.length;
_.each(key2s, key2 => {
tempTableData.push({
rspan: length,
key1: key1,
key2: key2,
en: data.en[key1][key2],
tw: data.tw[key1][key2],
zh: data.zh[key1][key2],
});
length = 0;
})
});
this.tableData = tempTableData;
this.$nextTick(() => {
this.loading = false;
console.timeEnd()
})
},
tabSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex == 0) {
if (row.rspan > 0) {
return {
rowspan: row.rspan,
colspan: 1
};
} else {
return {
rowspan: 0,
colspan: 0
};
}
}
},
async saveData() {
this.loading = true;
let enObj = {}, twObj = {}, zhObj = {};
_.each(_.uniq(_.pluck(tempTableData, 'key1')), key1 => {
enObj[key1] = {};
twObj[key1] = {};
zhObj[key1] = {};
let list = _.where(tempTableData, { key1 });
_.each(list, item => {
enObj[key1][item.key2] = item.en;
twObj[key1][item.key2] = item.tw;
zhObj[key1][item.key2] = item.zh;
})
});
let res1 = this.setLang('en_US', JSON.stringify(enObj));
let res2 = this.setLang('zh_TW', JSON.stringify(twObj));
let res3 = this.setLang('zh_CN', JSON.stringify(zhObj));
this.loading = false;
this.$message({
message: '保存成功',
type: 'success'
});
},
addData() {
this.$refs.addModel.dialogInit();
}
}
}
</script>
<style scoped>
.manage-input-box {
margin-right: 10px;
}
.condition-item-text {
float: left;
position: relative;
top: 6px;
}
.btn-box:after,
.btn-box:before {
content: '';
display: table;
}
.btn-box:after {
clear: both;
}
.fl-btn+.fl-btn {
margin-right: 20px;
}
.online-column {
color: #67c23a;
}
.offline-column {
color: #f56c6c;
}
.iplink-column {
text-decoration: underline;
}
.manage-content {
padding-bottom: 0;
}
.manage-content /deep/ .nborder .el-input__inner {
border: none;
height: 30px !important;
background-color: transparent;
}
.manage-content /deep/ .cell {
padding: 0;
}
</style>