tianheng-ui 0.0.78 → 0.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,428 @@
1
+ <template>
2
+ <div>
3
+ <!-- 搜索栏 -->
4
+ <search
5
+ v-if="searchConfig.show"
6
+ :data="searchData"
7
+ :options="searchConfig.options"
8
+ @on-search="requestListData"
9
+ @on-reset="requestListData"
10
+ />
11
+
12
+ <!-- 菜单栏 -->
13
+ <tools
14
+ v-if="toolsConfig.show"
15
+ :options="toolsConfig.options"
16
+ :disabled="{
17
+ batchDelete: tableSelectionData.length === 0,
18
+ export: tableSelectionData.length === 0
19
+ }"
20
+ @on-click="handleToolsClick"
21
+ />
22
+
23
+ <!-- 表格 -->
24
+ <th-table
25
+ v-if="tableConfig.options.length"
26
+ ref="tableRef"
27
+ :data="tableData"
28
+ :options="tableConfig.options"
29
+ :page-info="tableConfig.pageInfo.options"
30
+ :show-page="tableConfig.pageInfo.show"
31
+ :loading="tableConfig.loading.show"
32
+ :loading-text="tableConfig.loading.text"
33
+ :empty-text="tableConfig.empty.text"
34
+ select-type="single"
35
+ border
36
+ @selection-change="handleSelectionChange"
37
+ @pagination-change="handlePagingChange"
38
+ >
39
+ <template #action="{scope, option }">
40
+ <th-table-action
41
+ :actions="option.actions"
42
+ @on-click="
43
+ (action, callback) => {
44
+ handleActionClick(
45
+ scope.$index,
46
+ scope.row,
47
+ action,
48
+ callback,
49
+ option
50
+ );
51
+ }
52
+ "
53
+ >
54
+ </th-table-action>
55
+ </template>
56
+ </th-table>
57
+
58
+ <!-- 表单 -->
59
+ <th-dialog
60
+ v-model="dialog.show"
61
+ :title="dialog.action.name"
62
+ :modal-append-to-body="false"
63
+ @on-affirm="handleDialogAffirm"
64
+ @on-close="handleDialogClose"
65
+ >
66
+ <th-form-generate
67
+ v-if="formConfig"
68
+ :data="formConfig"
69
+ :value="dialog.data"
70
+ :remoteData="remoteData"
71
+ ref="formGenerate"
72
+ >
73
+ </th-form-generate>
74
+ </th-dialog>
75
+ </div>
76
+ </template>
77
+
78
+ <script>
79
+ import Search from "./custom/items/search";
80
+ import Tools from "./custom/items/tools";
81
+ import { toolsItemConfig, formItemConfig, tableItemConfig } from "./util/index";
82
+ import * as Axios from "./util/axios";
83
+ export default {
84
+ name: "thTableGenerate",
85
+ components: { Search, Tools },
86
+ props: {
87
+ config: {
88
+ type: Object,
89
+ default: () => {
90
+ return {
91
+ debug: false,
92
+ appId: ""
93
+ };
94
+ }
95
+ }
96
+ },
97
+ data() {
98
+ return {
99
+ tableJson: {},
100
+ axios: null,
101
+ networkConfig: {},
102
+ searchConfig: { show: false, options: [] },
103
+ searchData: {},
104
+ toolsConfig: { show: false, options: [] },
105
+ tableConfig: { options: [], pageInfo: {} },
106
+ tableData: [],
107
+ tableSelectionData: [],
108
+ dialog: { show: false, data: {}, action: {} },
109
+ formConfig: null,
110
+ remoteData: {
111
+ projectTypeId: [
112
+ {
113
+ id: "1597785308467281921",
114
+ name: "自然资源",
115
+ sort: "1",
116
+ tenantId: "1514528042264793089",
117
+ createBy: "舒浪",
118
+ createTime: 1669776678000,
119
+ updateBy: "舒浪",
120
+ updateTime: 1669787428000
121
+ },
122
+ {
123
+ id: "1597785379552346114",
124
+ name: "智慧政务",
125
+ sort: "2",
126
+ tenantId: "1514528042264793089",
127
+ createBy: "舒浪",
128
+ createTime: 1669776695000,
129
+ updateBy: "舒浪",
130
+ updateTime: 1669776893000
131
+ },
132
+ {
133
+ id: "1597785424695640065",
134
+ name: "数字乡村",
135
+ sort: "3",
136
+ tenantId: "1514528042264793089",
137
+ createBy: "舒浪",
138
+ createTime: 1669776705000,
139
+ updateBy: null,
140
+ updateTime: null
141
+ },
142
+ {
143
+ id: "1597885800635691009",
144
+ name: "测试分类啊啊啊",
145
+ sort: "0",
146
+ tenantId: "1514528042264793089",
147
+ createBy: "舒浪",
148
+ createTime: 1669800637000,
149
+ updateBy: null,
150
+ updateTime: null
151
+ },
152
+ {
153
+ id: "1597886150885240833",
154
+ name: "123123123",
155
+ sort: "0",
156
+ tenantId: "1514528042264793089",
157
+ createBy: "舒浪",
158
+ createTime: 1669800720000,
159
+ updateBy: null,
160
+ updateTime: null
161
+ },
162
+ {
163
+ id: "1597886566523990017",
164
+ name: "2222",
165
+ sort: "0",
166
+ tenantId: "1514528042264793089",
167
+ createBy: "舒浪",
168
+ createTime: 1669800819000,
169
+ updateBy: null,
170
+ updateTime: null
171
+ }
172
+ ]
173
+ }
174
+ };
175
+ },
176
+ created() {
177
+ this.initConfig();
178
+ },
179
+ mounted() {},
180
+ methods: {
181
+ // 初始化组件配置
182
+ initConfig() {
183
+ this.axios = Axios.init(this.config);
184
+ const info = sessionStorage.getItem("th_oauth_info");
185
+ if (info) {
186
+ const code = this.$route.params.id;
187
+ this.requestConfigData(code);
188
+ } else {
189
+ // 模拟授权认证流程
190
+ this.axios({
191
+ url: this.config.network.url,
192
+ method: this.config.network.method,
193
+ data: this.config.network.params,
194
+ headers: this.config.network.headers
195
+ }).then(res => {
196
+ const oauthInfo = { token: res.data };
197
+ sessionStorage.setItem("th_oauth_info", JSON.stringify(oauthInfo));
198
+ const code = this.$route.params.id;
199
+ this.requestConfigData(code);
200
+ });
201
+ }
202
+ },
203
+ // 获取配置信息
204
+ requestConfigData(code) {
205
+ this.tableJson = tableItemConfig(code);
206
+ // 网络请求
207
+ this.networkConfig = this.tableJson.network;
208
+
209
+ // 搜索栏
210
+ this.searchConfig = this.tableJson.search;
211
+ if (this.searchConfig.show) {
212
+ this.searchConfig.options.map(item => {
213
+ this.$set(this.searchData, item.prop, item.defaultValue || "");
214
+ });
215
+ }
216
+
217
+ // table
218
+ for (let i = 0; i < this.tableJson.table.options.length; i++) {
219
+ const element = this.tableJson.table.options[i];
220
+ delete element.type;
221
+ }
222
+ if (this.tableJson.table.sequence) {
223
+ this.tableJson.table.options.unshift({ type: "index", label: "序号" });
224
+ }
225
+ const action = { label: "操作", hide: true, slot: "action", actions: [] };
226
+
227
+ // 按position处理按钮,1:公共区,2:行内区
228
+ for (const key in this.tableJson.tools) {
229
+ if (Object.hasOwnProperty.call(this.tableJson.tools, key)) {
230
+ const element = this.tableJson.tools[key];
231
+ if (!element.show) continue;
232
+ if (key === "batchDelete") {
233
+ this.tableJson.table.options.unshift({
234
+ type: "selection"
235
+ });
236
+ }
237
+ const dic = toolsItemConfig(key, element);
238
+ dic.form = element.form;
239
+ if (element.position === 1) {
240
+ this.toolsConfig.show = true;
241
+ this.toolsConfig.options.push(dic);
242
+ } else if (element.position === 2) {
243
+ action.hide = false;
244
+ action.actions.push(dic);
245
+ }
246
+ }
247
+ }
248
+ action.width = action.actions.length * 60 + 20;
249
+ this.tableJson.table.options.push(action);
250
+
251
+ this.tableConfig = this.tableJson.table;
252
+ this.requestListData();
253
+ },
254
+ requestListData() {
255
+ if (!this.networkConfig.mounted) return;
256
+ this.tableConfig.loading.show = true;
257
+ const apiInfo = this.networkConfig.mounted;
258
+ const params = {
259
+ current: this.tableConfig.pageInfo.options.currentPage,
260
+ size: this.tableConfig.pageInfo.options.pageSize,
261
+ ...this.searchData
262
+ };
263
+ this.axios({
264
+ url: apiInfo.api,
265
+ method: apiInfo.method,
266
+ data: params
267
+ })
268
+ .then(res => {
269
+ const data = res.data.records;
270
+ this.tableData = data;
271
+ this.tableConfig.loading.show = false;
272
+ this.tableConfig.pageInfo.options.total = Number(res.data.total);
273
+ })
274
+ .catch(err => {
275
+ this.tableConfig.loading.show = false;
276
+ });
277
+ },
278
+ requestAddData(data) {
279
+ if (!this.networkConfig.add) return;
280
+ this.dialog.action.loading = true;
281
+ const apiInfo = this.networkConfig.add;
282
+ this.axios({
283
+ url: apiInfo.api,
284
+ method: apiInfo.method,
285
+ data
286
+ })
287
+ .then(res => {
288
+ this.dialog.action.loading = false;
289
+ this.requestListData();
290
+ })
291
+ .catch(err => {
292
+ this.dialog.action.loading = false;
293
+ });
294
+ },
295
+ requestEditData(data) {
296
+ if (!this.networkConfig.edit) return;
297
+ this.dialog.action.loading = true;
298
+ const apiInfo = this.networkConfig.edit;
299
+ this.axios({
300
+ url: apiInfo.api,
301
+ method: apiInfo.method,
302
+ data
303
+ })
304
+ .then(res => {
305
+ this.dialog.action.loading = false;
306
+ this.requestListData();
307
+ })
308
+ .catch(err => {
309
+ this.dialog.action.loading = false;
310
+ });
311
+ },
312
+ requestDeleteData(data, callback) {
313
+ if (!this.networkConfig.delete) return;
314
+ this.dialog.action.loading = true;
315
+ const apiInfo = this.networkConfig.delete;
316
+ this.axios({
317
+ url: apiInfo.api,
318
+ method: apiInfo.method,
319
+ data
320
+ })
321
+ .then(res => {
322
+ callback(true);
323
+ this.dialog.action.loading = false;
324
+ this.requestListData();
325
+ })
326
+ .catch(err => {
327
+ this.dialog.action.loading = false;
328
+ });
329
+ },
330
+ getFormConfig() {
331
+ setTimeout(() => {
332
+ const form = this.dialog.action.form;
333
+ const config = formItemConfig(form.id);
334
+ this.formConfig = config;
335
+ }, 1000);
336
+ },
337
+ handleSearchSubmit(val) {
338
+ console.log("handleSearchSubmit =>", val);
339
+ this.requestListData();
340
+ },
341
+ handleSearchReset(val) {
342
+ console.log("handleSearchReset =>", val);
343
+ this.requestListData();
344
+ },
345
+ handleToolsClick(action) {
346
+ console.log("handleToolsClick =>", action);
347
+ switch (action.act) {
348
+ case "add":
349
+ this.dialog = { show: true, data: {}, action: action };
350
+ this.getFormConfig();
351
+ break;
352
+ case "batchDelete":
353
+ action.loading = true;
354
+ setTimeout(() => {
355
+ action.loading = false;
356
+ this.tableSelectionData = [];
357
+ this.$refs.tableRef.getTable().clearSelection();
358
+ }, 1000);
359
+ break;
360
+ case "export":
361
+ action.loading = true;
362
+ setTimeout(() => {
363
+ action.loading = false;
364
+ this.tableSelectionData = [];
365
+ this.$refs.tableRef.getTable().clearSelection();
366
+ }, 1000);
367
+ break;
368
+ case "import":
369
+ break;
370
+
371
+ default:
372
+ break;
373
+ }
374
+ },
375
+ handlePagingChange(val) {
376
+ console.log("handlePagingChange =>", val);
377
+ this.requestListData();
378
+ },
379
+ handleSelectionChange(val) {
380
+ console.log("handleSelectionChange =>", val);
381
+ this.tableSelectionData = val;
382
+ },
383
+ handleActionClick(index, item, action, callback) {
384
+ console.log("handleActionClick =>", item, action);
385
+ switch (action.act) {
386
+ case "edit":
387
+ this.dialog = { show: true, data: item, action: action };
388
+ this.getFormConfig();
389
+ break;
390
+ case "detail":
391
+ this.dialog = { show: true, data: item, action: action };
392
+ this.getFormConfig();
393
+ break;
394
+ case "delete":
395
+ this.requestDeleteData({ ids: item.id }, callback);
396
+ break;
397
+
398
+ default:
399
+ break;
400
+ }
401
+ },
402
+ handleDialogAffirm(val) {
403
+ this.$refs.formGenerate.getData().then(data => {
404
+ console.log("handleDialogAffirm =>", data);
405
+ switch (this.dialog.action.act) {
406
+ case "add":
407
+ this.requestAddData(data);
408
+ break;
409
+ case "edit":
410
+ this.dialog.data = Object.assign(this.dialog.data, data);
411
+ this.requestEditData(this.dialog.data);
412
+ break;
413
+
414
+ default:
415
+ break;
416
+ }
417
+ this.formConfig = null;
418
+ this.dialog.show = false;
419
+ });
420
+ },
421
+ handleDialogClose() {
422
+ this.formConfig = null;
423
+ }
424
+ }
425
+ };
426
+ </script>
427
+
428
+ <style lang="scss" scoped></style>
@@ -0,0 +1,99 @@
1
+ function Log() {}
2
+
3
+ Log.prototype.type = ["primary", "success", "warn", "error", "info"];
4
+
5
+ Log.prototype.typeColor = function(type) {
6
+ let color = "";
7
+ switch (type) {
8
+ case "primary":
9
+ color = "#2d8cf0";
10
+ break;
11
+ case "success":
12
+ color = "#19be6b";
13
+ break;
14
+ case "info":
15
+ color = "#909399";
16
+ break;
17
+ case "warn":
18
+ color = "#ff9900";
19
+ break;
20
+ case "error":
21
+ color = "#f03f14";
22
+ break;
23
+ default:
24
+ color = "#35495E";
25
+ break;
26
+ }
27
+ return color;
28
+ };
29
+
30
+ Log.prototype.isArray = function(obj) {
31
+ return Object.prototype.toString.call(obj) === "[object Array]";
32
+ };
33
+
34
+ Log.prototype.print = function(text, type = "default", back = false) {
35
+ if (typeof text === "object") {
36
+ // 如果是對象則調用打印對象方式
37
+ this.isArray(text) ? console.table(text) : console.dir(text);
38
+ return;
39
+ }
40
+ if (back) {
41
+ // 如果是打印帶背景圖的
42
+ console.log(`%c ${text} `, `background:${this.typeColor(type)}; padding: 2px; border-radius: 4px; color: #fff;`);
43
+ } else {
44
+ console.log(
45
+ `%c ${text} `,
46
+ `border: 1px solid ${this.typeColor(type)};
47
+ padding: 2px; border-radius: 4px;
48
+ color: ${this.typeColor(type)};`
49
+ );
50
+ }
51
+ };
52
+
53
+ Log.prototype.printBack = function(type = "primary", title) {
54
+ this.print(type, title, true);
55
+ };
56
+
57
+ Log.prototype.pretty = function(type = "primary", title, text) {
58
+ if (typeof text === "object") {
59
+ // console.group("Console Group", title);
60
+ console.log(
61
+ `%c ${title}`,
62
+ `background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)};
63
+ padding: 1px; border-radius: 4px; color: #fff;`
64
+ );
65
+ this.isArray(text) ? console.table(text) : console.dir(text);
66
+ console.groupEnd();
67
+ return;
68
+ }
69
+ console.log(
70
+ `%c ${title} %c ${text} %c`,
71
+ `background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)};
72
+ padding: 1px; border-radius: 4px 0 0 4px; color: #fff;`,
73
+ `border:1px solid ${this.typeColor(type)};
74
+ padding: 1px; border-radius: 0 4px 4px 0; color: ${this.typeColor(type)};`,
75
+ "background:transparent"
76
+ );
77
+ };
78
+
79
+ Log.prototype.prettyPrimary = function(title, ...text) {
80
+ text.forEach(t => this.pretty("primary", title, t));
81
+ };
82
+
83
+ Log.prototype.prettySuccess = function(title, ...text) {
84
+ text.forEach(t => this.pretty("success", title, t));
85
+ };
86
+
87
+ Log.prototype.prettyWarn = function(title, ...text) {
88
+ text.forEach(t => this.pretty("warn", title, t));
89
+ };
90
+
91
+ Log.prototype.prettyError = function(title, ...text) {
92
+ text.forEach(t => this.pretty("error", title, t));
93
+ };
94
+
95
+ Log.prototype.prettyInfo = function(title, ...text) {
96
+ text.forEach(t => this.pretty("info", title, t));
97
+ };
98
+
99
+ export default new Log();
@@ -0,0 +1,85 @@
1
+ import axios from "axios";
2
+ import Log from "./Log";
3
+ import { Notification } from "element-ui";
4
+
5
+ export const init = baseConfig => {
6
+ // 创建axios实例
7
+ const Axios = axios.create({
8
+ baseURL: baseConfig.baseUrl,
9
+ timeout: 60000 // 请求超时时间
10
+ // withCredentials: true, //允许携带cookie
11
+ });
12
+
13
+ // 添加请求拦截器
14
+ Axios.interceptors.request.use(
15
+ config => {
16
+ const info = sessionStorage.getItem("th_oauth_info");
17
+ if (info) {
18
+ const token = JSON.parse(info).token;
19
+ config.headers["Authorization"] = token;
20
+ }
21
+ return config;
22
+ },
23
+ error => {
24
+ // Do something with request error
25
+ console.log(error); // for debug
26
+ Promise.reject(error);
27
+ }
28
+ );
29
+
30
+ // 添加响应拦截器
31
+ Axios.interceptors.response.use(
32
+ response => {
33
+ const code = response.status;
34
+ if (code < 200 || code > 300) {
35
+ Notification.error({
36
+ title: response.message
37
+ });
38
+ return Promise.reject("error");
39
+ }
40
+
41
+ const dataCode = response.data.code;
42
+ if (dataCode && dataCode !== 200) {
43
+ Notification.error({
44
+ title: response.data.message
45
+ });
46
+ return Promise.reject("error");
47
+ }
48
+
49
+ if (baseConfig.debug) {
50
+ Log.prettyPrimary("Request Url:", response.request.responseURL);
51
+ Log.prettySuccess("Request Res:", response);
52
+ }
53
+
54
+ return response.data;
55
+ },
56
+ error => {
57
+ let code = 0;
58
+ try {
59
+ code = error.response.data.status;
60
+ } catch (e) {
61
+ if (error.toString().indexOf("Error: timeout") !== -1) {
62
+ Notification.error({
63
+ title: "网络请求超时",
64
+ duration: 5000
65
+ });
66
+ return Promise.reject(error);
67
+ }
68
+ }
69
+ if (code) {
70
+ const errorMsg = error.response.data.message;
71
+ Notification.error({
72
+ title: errorMsg || "未知错误",
73
+ duration: 5000
74
+ });
75
+ } else {
76
+ Notification.error({
77
+ title: "接口请求失败",
78
+ duration: 5000
79
+ });
80
+ }
81
+ return Promise.reject(error);
82
+ }
83
+ );
84
+ return Axios;
85
+ };