tianheng-ui 0.0.80 → 0.0.82

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tianheng-ui",
3
3
  "description": "A Vue.js project",
4
- "version": "0.0.80",
4
+ "version": "0.0.82",
5
5
  "author": "shu lang <403732931@qq.com>",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -17,7 +17,7 @@
17
17
  :models.sync="models"
18
18
  :widget="item"
19
19
  :slotKeys="slotKeys"
20
- :remote="remote"
20
+ :remote="remoteData"
21
21
  :config="formJson.config"
22
22
  :prop="item.type === 'grid' ? '' : item.model"
23
23
  :componentsData="componentsData"
@@ -44,7 +44,7 @@
44
44
  :models.sync="models"
45
45
  :widget="item"
46
46
  :slotKeys="slotKeys"
47
- :remote="remote"
47
+ :remote="remoteData"
48
48
  :config="formJson.config"
49
49
  :prop="item.type === 'grid' ? '' : item.model"
50
50
  :componentsData="componentsData"
@@ -71,7 +71,7 @@ export default {
71
71
  return {};
72
72
  }
73
73
  },
74
- remote: {
74
+ remoteData: {
75
75
  type: Object,
76
76
  default: () => {
77
77
  return {};
@@ -728,18 +728,14 @@ export default {
728
728
  }
729
729
  },
730
730
  created() {
731
- if (
732
- this.widget.options.remote &&
733
- this.remote[this.widget.options.remoteFunc]
734
- ) {
735
- this.remote[this.widget.options.remoteFunc](data => {
736
- this.widget.options.remoteOptions = data.map(item => {
737
- return {
738
- value: item[this.widget.options.props.value],
739
- label: item[this.widget.options.props.label],
740
- children: item[this.widget.options.props.children]
741
- };
742
- });
731
+ if (this.widget.options.remote) {
732
+ const remoteData = this.remote[this.widget.model] || [];
733
+ this.widget.options.remoteOptions = remoteData.map(item => {
734
+ return {
735
+ value: item[this.widget.options.props.value],
736
+ label: item[this.widget.options.props.label],
737
+ children: item[this.widget.options.props.children]
738
+ };
743
739
  });
744
740
  }
745
741
 
@@ -747,9 +743,8 @@ export default {
747
743
  this.widget.type === "upload" &&
748
744
  this.remote[this.widget.options.remoteFunc]
749
745
  ) {
750
- this.remote[this.widget.options.remoteFunc](data => {
751
- this.widget.options.remoteApi = data;
752
- });
746
+ const remoteData = this.remote[this.widget.options.remoteFunc] || {};
747
+ this.widget.options.remoteApi = remoteData;
753
748
  }
754
749
  },
755
750
  mounted() {
@@ -396,6 +396,7 @@ export default {
396
396
  GenerateForm
397
397
  },
398
398
  props: {
399
+ formName: String,
399
400
  data: {
400
401
  type: Object,
401
402
  default: () => {
@@ -526,6 +527,7 @@ export default {
526
527
  deep: true,
527
528
  handler: function(val) {
528
529
  this.$emit("update:data", val);
530
+ this.$emit("on-change", val);
529
531
  }
530
532
  },
531
533
  data(val) {
@@ -538,7 +540,10 @@ export default {
538
540
  this.widgetFormSelect = this.data.list[0];
539
541
  }
540
542
  if (this.data && this.data.config) {
541
- this.widgetFormData.config = this.data.config;
543
+ this.widgetFormData.config = Object.assign(
544
+ this.widgetFormData.config,
545
+ this.data.config
546
+ );
542
547
  }
543
548
  },
544
549
  methods: {
@@ -136,6 +136,9 @@ export default {
136
136
  this.$emit("on-search", this.params);
137
137
  },
138
138
  doReset() {
139
+ this.options.map(item => {
140
+ this.$set(this.params, item.prop, item.defaultValue || "");
141
+ });
139
142
  this.$emit("on-reset", this.params);
140
143
  }
141
144
  }
@@ -5,8 +5,8 @@
5
5
  v-if="searchConfig.show"
6
6
  :data="searchData"
7
7
  :options="searchConfig.options"
8
- @on-search="handleSearchSubmit"
9
- @on-reset="handleSearchReset"
8
+ @on-search="requestListData"
9
+ @on-reset="requestListData"
10
10
  />
11
11
 
12
12
  <!-- 菜单栏 -->
@@ -67,12 +67,10 @@
67
67
  v-if="formConfig"
68
68
  :data="formConfig"
69
69
  :value="dialog.data"
70
+ :remoteData="remoteData"
70
71
  ref="formGenerate"
71
72
  >
72
73
  </th-form-generate>
73
- <!-- <span slot="footer">
74
- <th-table-tools :options="dialogOptions" @on-click="handleToolsClick" />
75
- </span> -->
76
74
  </th-dialog>
77
75
  </div>
78
76
  </template>
@@ -80,30 +78,27 @@
80
78
  <script>
81
79
  import Search from "./custom/items/search";
82
80
  import Tools from "./custom/items/tools";
83
- import { toolsItemConfig, formItemConfig } from "./util/index";
81
+ import { toolsItemConfig, formItemConfig, tableItemConfig } from "./util/index";
84
82
  import * as Axios from "./util/axios";
85
83
  export default {
86
84
  name: "thTableGenerate",
87
85
  components: { Search, Tools },
88
86
  props: {
89
- data: {
87
+ config: {
90
88
  type: Object,
91
89
  default: () => {
92
- return {};
93
- }
94
- },
95
- apiConfig: {
96
- type: Object,
97
- default: () => {
98
- return {};
90
+ return {
91
+ debug: false,
92
+ appId: ""
93
+ };
99
94
  }
100
95
  }
101
96
  },
102
97
  data() {
103
98
  return {
104
- tableJson: JSON.parse(JSON.stringify(this.data)),
105
- network: {},
99
+ tableJson: {},
106
100
  axios: null,
101
+ networkConfig: {},
107
102
  searchConfig: { show: false, options: [] },
108
103
  searchData: {},
109
104
  toolsConfig: { show: false, options: [] },
@@ -111,31 +106,105 @@ export default {
111
106
  tableData: [],
112
107
  tableSelectionData: [],
113
108
  dialog: { show: false, data: {}, action: {} },
114
- formConfig: null
115
- };
116
- },
117
- watch: {
118
- data(val) {
119
- this.tableJson = val;
120
- this.initConfig();
121
- },
122
- tableJson: {
123
- deep: true,
124
- handler(val) {
125
- this.$emit("update:data", val);
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
+ ]
126
173
  }
127
- }
174
+ };
128
175
  },
129
176
  created() {
130
- this.axios = Axios.init(this.apiConfig);
131
- },
132
- mounted() {
133
177
  this.initConfig();
134
178
  },
179
+ mounted() {},
135
180
  methods: {
181
+ // 初始化组件配置
136
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);
137
206
  // 网络请求
138
- this.network = this.tableJson.network;
207
+ this.networkConfig = this.tableJson.network;
139
208
 
140
209
  // 搜索栏
141
210
  this.searchConfig = this.tableJson.search;
@@ -162,8 +231,7 @@ export default {
162
231
  if (!element.show) continue;
163
232
  if (key === "batchDelete") {
164
233
  this.tableJson.table.options.unshift({
165
- type: "selection",
166
- label: ""
234
+ type: "selection"
167
235
  });
168
236
  }
169
237
  const dic = toolsItemConfig(key, element);
@@ -184,9 +252,9 @@ export default {
184
252
  this.requestListData();
185
253
  },
186
254
  requestListData() {
187
- if (!this.network.mounted) return;
255
+ if (!this.networkConfig.mounted) return;
188
256
  this.tableConfig.loading.show = true;
189
- const apiInfo = this.network.mounted;
257
+ const apiInfo = this.networkConfig.mounted;
190
258
  const params = {
191
259
  current: this.tableConfig.pageInfo.options.currentPage,
192
260
  size: this.tableConfig.pageInfo.options.pageSize,
@@ -208,9 +276,9 @@ export default {
208
276
  });
209
277
  },
210
278
  requestAddData(data) {
211
- if (!this.network.add) return;
279
+ if (!this.networkConfig.add) return;
212
280
  this.dialog.action.loading = true;
213
- const apiInfo = this.network.add;
281
+ const apiInfo = this.networkConfig.add;
214
282
  this.axios({
215
283
  url: apiInfo.api,
216
284
  method: apiInfo.method,
@@ -225,9 +293,9 @@ export default {
225
293
  });
226
294
  },
227
295
  requestEditData(data) {
228
- if (!this.network.edit) return;
296
+ if (!this.networkConfig.edit) return;
229
297
  this.dialog.action.loading = true;
230
- const apiInfo = this.network.edit;
298
+ const apiInfo = this.networkConfig.edit;
231
299
  this.axios({
232
300
  url: apiInfo.api,
233
301
  method: apiInfo.method,
@@ -242,9 +310,9 @@ export default {
242
310
  });
243
311
  },
244
312
  requestDeleteData(data, callback) {
245
- if (!this.network.delete) return;
313
+ if (!this.networkConfig.delete) return;
246
314
  this.dialog.action.loading = true;
247
- const apiInfo = this.network.delete;
315
+ const apiInfo = this.networkConfig.delete;
248
316
  this.axios({
249
317
  url: apiInfo.api,
250
318
  method: apiInfo.method,
@@ -272,6 +340,7 @@ export default {
272
340
  },
273
341
  handleSearchReset(val) {
274
342
  console.log("handleSearchReset =>", val);
343
+ this.requestListData();
275
344
  },
276
345
  handleToolsClick(action) {
277
346
  console.log("handleToolsClick =>", action);
@@ -305,7 +374,7 @@ export default {
305
374
  },
306
375
  handlePagingChange(val) {
307
376
  console.log("handlePagingChange =>", val);
308
- this.requestListData()
377
+ this.requestListData();
309
378
  },
310
379
  handleSelectionChange(val) {
311
380
  console.log("handleSelectionChange =>", val);
@@ -56,6 +56,12 @@ export default {
56
56
  default: () => {
57
57
  return [];
58
58
  }
59
+ },
60
+ config: {
61
+ type: Object,
62
+ default: () => {
63
+ return {};
64
+ }
59
65
  }
60
66
  },
61
67
  data() {
@@ -65,8 +71,36 @@ export default {
65
71
  client: "monitor"
66
72
  };
67
73
  },
68
- mounted() {},
74
+ watch: {
75
+ fields(val) {
76
+ this.initConfig();
77
+ },
78
+ config(val) {
79
+ this.initConfig();
80
+ }
81
+ },
82
+ mounted() {
83
+ this.initConfig();
84
+ },
69
85
  methods: {
86
+ initConfig() {
87
+ this.searchFields = [];
88
+ const searchFieldsIndexs = [];
89
+ if (this.config.search) {
90
+ const search = this.config.search.options;
91
+ for (const item of search) {
92
+ for (let i = 0; i < this.fields.length; i++) {
93
+ const element = this.fields[i];
94
+ if (element.prop === item.prop) {
95
+ this.searchFields.push(item);
96
+ searchFieldsIndexs.push(i);
97
+ }
98
+ }
99
+ }
100
+ }
101
+
102
+ this.$refs.configRef.search.fields = searchFieldsIndexs;
103
+ },
70
104
  handleFieldsChange(val) {
71
105
  const type = val.type;
72
106
  const data = val.data;
@@ -113,7 +147,7 @@ export default {
113
147
  const tableConfig = this.$refs.configRef.getJson();
114
148
  tableConfig.search.options = this.searchFields;
115
149
  tableConfig.table.options = this.tableFields;
116
- return tableConfig
150
+ return tableConfig;
117
151
  }
118
152
  }
119
153
  };
@@ -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();
@@ -1,21 +1,23 @@
1
1
  import axios from "axios";
2
+ import Log from "./Log";
2
3
  import { Notification } from "element-ui";
3
4
 
4
5
  export const init = baseConfig => {
5
6
  // 创建axios实例
6
7
  const Axios = axios.create({
7
8
  baseURL: baseConfig.baseUrl,
8
- timeout: baseConfig.timeout || 60000 // 请求超时时间
9
+ timeout: 60000 // 请求超时时间
9
10
  // withCredentials: true, //允许携带cookie
10
11
  });
11
12
 
12
13
  // 添加请求拦截器
13
14
  Axios.interceptors.request.use(
14
15
  config => {
15
- config.headers = baseConfig.headers || {
16
- "Content-Type": "application/json"
17
- };
18
- if (baseConfig.token) config.headers["Authorization"] = baseConfig.token;
16
+ const info = sessionStorage.getItem("th_oauth_info");
17
+ if (info) {
18
+ const token = JSON.parse(info).token;
19
+ config.headers["Authorization"] = token;
20
+ }
19
21
  return config;
20
22
  },
21
23
  error => {
@@ -44,12 +46,9 @@ export const init = baseConfig => {
44
46
  return Promise.reject("error");
45
47
  }
46
48
 
47
- if (baseConfig.debugger) {
48
- console.log("\n");
49
- console.log("request url =>");
50
- console.log(response.request.responseURL);
51
- console.log("request res =>", response);
52
- console.log("\n");
49
+ if (baseConfig.debug) {
50
+ Log.prettyPrimary("Request Url:", response.request.responseURL);
51
+ Log.prettySuccess("Request Res:", response);
53
52
  }
54
53
 
55
54
  return response.data;