t20-common-lib 0.14.8 → 0.15.0

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.
Files changed (25) hide show
  1. package/package.json +1 -1
  2. package/packages/branch-bank-select/src/main.vue +1 -0
  3. package/packages/dynamic-form/index.js +7 -0
  4. package/packages/dynamic-form/src/components/Amount.vue +66 -0
  5. package/packages/dynamic-form/src/components/AmountRange.vue +72 -0
  6. package/packages/dynamic-form/src/components/CheckboxGroup.vue +63 -0
  7. package/packages/dynamic-form/src/components/DMY.vue +126 -0
  8. package/packages/dynamic-form/src/components/Date.vue +50 -0
  9. package/packages/dynamic-form/src/components/DateRange.vue +46 -0
  10. package/packages/dynamic-form/src/components/Dialog.vue +194 -0
  11. package/packages/dynamic-form/src/components/Input.vue +41 -0
  12. package/packages/dynamic-form/src/components/InputNumber.vue +66 -0
  13. package/packages/dynamic-form/src/components/InputNumberRange.vue +44 -0
  14. package/packages/dynamic-form/src/components/LazySelect.vue +265 -0
  15. package/packages/dynamic-form/src/components/RadioGroup.vue +60 -0
  16. package/packages/dynamic-form/src/components/Rate.vue +53 -0
  17. package/packages/dynamic-form/src/components/Select.vue +212 -0
  18. package/packages/dynamic-form/src/components/SelectTree.vue +136 -0
  19. package/packages/dynamic-form/src/components/Switch.vue +32 -0
  20. package/packages/dynamic-form/src/components/Textarea.vue +49 -0
  21. package/packages/dynamic-form/src/components/unitTreeSelect.vue +130 -0
  22. package/packages/dynamic-form/src/main.vue +401 -0
  23. package/packages/dynamic-form/src/utils/request.js +19 -0
  24. package/src/i18n.json +12 -0
  25. package/src/index.js +4 -1
@@ -0,0 +1,66 @@
1
+ <template>
2
+ <N20-input-number
3
+ :max="999999999999.99"
4
+ :type="type"
5
+ :is-clearable="true"
6
+ :format="_dNum"
7
+ v-model="_value"
8
+ :d-num="dnum"
9
+ placeholder="请输入"
10
+ :suffix="_suffix"
11
+ />
12
+ </template>
13
+ <script>
14
+ export default {
15
+ name: "InputNumber",
16
+ props: {
17
+ value: {
18
+ type: [String, Number],
19
+ defalut: "",
20
+ },
21
+ items: {
22
+ type: Object,
23
+ default: () => {},
24
+ },
25
+ },
26
+ computed: {
27
+ _value: {
28
+ get() {
29
+ return this.value;
30
+ },
31
+ set(value) {
32
+ this.$emit("input", value);
33
+ },
34
+ },
35
+ _dNum() {
36
+ if (this.items.format == "money") {
37
+ return "0,0.00";
38
+ }
39
+ if (this.items.format == "rate") {
40
+ this.type = "rate";
41
+
42
+ let dnum = this.items.dNum.split(".")[1];
43
+ this.dnum = dnum.split("").length;
44
+ return this.items.dNum;
45
+ }
46
+ if (this.items.format == "float") {
47
+ let dnum = this.items.dNum.split(".")[1];
48
+ this.dnum = dnum.split("").length;
49
+ return this.items.dNum;
50
+ }
51
+ },
52
+ _suffix() {
53
+ if (this.items.format == "rate") {
54
+ return this.items.suffix ? this.items.suffix : "%";
55
+ }
56
+ return "";
57
+ },
58
+ },
59
+ data() {
60
+ return {
61
+ type: "money",
62
+ dnum: 4,
63
+ };
64
+ },
65
+ };
66
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <N20-input-number-range
3
+ :startValue.sync="startValue"
4
+ :endValue.sync="endValue"
5
+ @change="changeTime"
6
+ />
7
+ </template>
8
+ <script>
9
+ export default {
10
+ name: "InputNumberRange",
11
+ props: {
12
+ value: {
13
+ type: [Array],
14
+ defalut:()=>[],
15
+ },
16
+ },
17
+ data() {
18
+ return {
19
+ startValue: "",
20
+ endValue: "",
21
+ };
22
+ },
23
+ methods: {
24
+ changeTime() {
25
+ this.$emit("update:label", this.startValue + "~" + this.endValue);
26
+ this.$emit("input", [this.startValue, this.endValue]);
27
+ },
28
+ },
29
+ watch: {
30
+ value: {
31
+ handler(val) {
32
+ if (val) {
33
+ const [s, e] = val || ["", ""];
34
+ this.startValue = s;
35
+ this.endValue = e;
36
+ this.$emit("update:label", this.startValue + "~" + this.endValue);
37
+ }
38
+ },
39
+ deep: true,
40
+ immediate: true,
41
+ },
42
+ },
43
+ };
44
+ </script>
@@ -0,0 +1,265 @@
1
+ <template>
2
+ <N20-select-lazy
3
+ v-model="_value"
4
+ :filter-method="(val) => filterFn(val)"
5
+ @scroll-bottom="getNextList"
6
+ class="input-w"
7
+ filterable
8
+ :clearable="items.clearable ? items.clearable : true"
9
+ v-bind="$attrs"
10
+ @change="changeFn"
11
+ >
12
+ <el-option
13
+ v-for="item in options"
14
+ v-title="item.label"
15
+ :style="{'max-width': $attrs['show-overflow-tooltip'] ? '224px' : 'none'}"
16
+ :show-overflow-tooltip="true"
17
+ class="text-ellipsis"
18
+ :key="item.value + items.prop"
19
+ :label="item.label | $l"
20
+ :value="item.value"
21
+ >
22
+ {{labelKey ? item._label : item.label | $l}}
23
+ </el-option>
24
+ </N20-select-lazy>
25
+ </template>
26
+
27
+ <script>
28
+ import dayjs from 'dayjs'
29
+ /* 各属性,方法参考el-select */
30
+ import { getDataForPost, getDataForGet } from '../utils/request'
31
+ export default {
32
+ name: "SelectLazy",
33
+ props: {
34
+ value: {
35
+ type: String,
36
+ defalut: "",
37
+ },
38
+ items: {
39
+ type: Object,
40
+ defalut: () => {
41
+ return {
42
+ options: [],
43
+ };
44
+ },
45
+ },
46
+ variable: {
47
+ type: Object,
48
+ defalut: () => {
49
+ return {};
50
+ },
51
+ },
52
+ label: {
53
+ type: String,
54
+ defalut: "",
55
+ },
56
+ },
57
+ computed: {
58
+ _value: {
59
+ get() {
60
+ return !['', null, undefined].includes(this.value) ? this.value : this.label;
61
+ },
62
+ set(value) {
63
+ if (['', null, undefined].includes(value)) {
64
+ this.$emit(`update:label`, "");
65
+ this.$emit("input", "");
66
+ return
67
+ }
68
+ let res = this.getName(value);
69
+ if (res.length == 0) {
70
+ this.$emit(`update:label`, value);
71
+ } else {
72
+ this.$emit(`update:label`, res.join(","));
73
+ this.$emit("input", value);
74
+ }
75
+ },
76
+ },
77
+ labelKey() {
78
+ return this.items?.api?.labelKey.includes(",") || this.items?.api?.labelKey.includes("{");
79
+ },
80
+ // 判断数据类型,格式化回显数据
81
+ valueType() {
82
+ return typeof this.value
83
+ }
84
+ },
85
+ data() {
86
+ return {
87
+ options: null,
88
+ query: "",
89
+ current: 1,
90
+ total: 0,
91
+ requestBody: {},
92
+ useDefaule: true
93
+ };
94
+ },
95
+ mounted() {
96
+ this.init();
97
+ },
98
+ methods: {
99
+ getName(value) {
100
+ let temp = [];
101
+ if (Array.isArray(value)) {
102
+ for (let i of value) {
103
+ let res = (this.options || []).find((row) => row.value === i);
104
+ // 如果label显示的2个字段,则取第一个字段的值
105
+ if (res) temp.push(res[this.items?.api?.labelKey.split(",")[0] || 'label']);
106
+ }
107
+ } else {
108
+ let res = (this.options || []).find((row) => row.value === value);
109
+ if (res) temp.push(res[this.items?.api?.labelKey.split(",")[0] || 'label']);
110
+ }
111
+ return temp
112
+ this.$emit(`update:label`, temp.join(","));
113
+ },
114
+ async init(status) {
115
+ if (!this.items?.api?.apiUrl || !this.items?.api?.requestMethod) {
116
+ this.options = this.items.options || [];
117
+ return;
118
+ }
119
+ let res = null;
120
+ await this.setRequestBody();
121
+
122
+ ["GET", "get"].includes(this.items?.api?.requestMethod) &&
123
+ (res = await getDataForGet(
124
+ this.items?.api?.apiUrl,
125
+ this.requestBody,
126
+ this.$attrs.headers
127
+ ));
128
+
129
+ ["POST", "post"].includes(this.items?.api?.requestMethod) &&
130
+ (res = await getDataForPost(
131
+ this.items?.api?.apiUrl,
132
+ this.requestBody,
133
+ this.$attrs.headers
134
+ ));
135
+
136
+ let temp = ((this.items?.api?.dataProp ? new Function('res', `return res.${this.items?.api?.dataProp}`)(res) : (res.data)) || []);
137
+ temp = temp?.map((item) => {
138
+ if (this.items?.api?.labelKey.includes(",")) {
139
+ let keyArr = this.items?.api?.labelKey.split(",");
140
+ let label = "";
141
+ keyArr.map((key, index) => {
142
+ if (index == keyArr.length - 1) {
143
+ label += item[key]
144
+ } else {
145
+ label += item[key] + ' ';
146
+ }
147
+ })
148
+ item._label = label;
149
+ item.label = item[keyArr[0]];
150
+ } else if (this.items?.api?.labelKey && this.items?.api?.labelKey.includes("{")) {
151
+ let regex = /\{([^}]+)\}/g;
152
+ var modifiedStr = this.items?.api?.labelKey.replace(regex, (match, p1) => {
153
+ if (p1.includes('label:')){
154
+ item.label = item[p1.replace("label:", "")];
155
+ return item[p1.replace("label:", "")]
156
+ }
157
+ return item[p1];
158
+ })
159
+ item._label = modifiedStr
160
+ } else {
161
+ item.label = item[this.items?.api?.labelKey || "label"];
162
+ }
163
+ if (this.items?.api?.valueKey.includes(",")) {
164
+ let keyArr = this.items?.api?.valueKey.split(",");
165
+ let value = "";
166
+ keyArr.map((key, index) => {
167
+ if (index == keyArr.length - 1) {
168
+ value += item[key]
169
+ } else {
170
+ value += item[key] + ',';
171
+ }
172
+ })
173
+ item.value = value;
174
+ } else {
175
+ item.value = item[this.items?.api?.valueKey || "value"];
176
+ }
177
+ if (this.valueType == 'string') {
178
+ item.value = String(item.value)
179
+ }
180
+ if (this.valueType == 'number') {
181
+ item.value = Number(item.value)
182
+ }
183
+ return item;
184
+ });
185
+ this.useDefaule = false
186
+ if (status) {
187
+ this.options = [...this.options, ...temp];
188
+ } else {
189
+ this.options = temp;
190
+ }
191
+ this.total = res?.total || 0;
192
+ },
193
+ async setRequestBody() {
194
+ let page = {};
195
+ if (!this.items?.api?.page?.reqKey) {
196
+ page = {
197
+ [this.items?.api?.page?.size]: 20,
198
+ [this.items?.api?.page?.current]: this.current,
199
+ }
200
+ } else if (this.items?.api?.page?.reqKey) {
201
+ page = {
202
+ [this.items?.api?.page?.reqKey]: {
203
+ [this.items?.api?.page?.size]: 20,
204
+ [this.items?.api?.page?.current]: this.current,
205
+ }
206
+ }
207
+ }
208
+ if (!this.items?.api?.page?.size) {
209
+ page = {}
210
+ }
211
+ // 模糊搜索关键字查询
212
+ let searchObj = JSON.parse(JSON.stringify(this.items?.api?.reqKeys ? this.items?.api?.reqKeys : {}))
213
+ Object.keys(searchObj).map(t => {
214
+ searchObj[t] = this.changVariable(searchObj[t]);
215
+ if(Object.prototype.toString.call(searchObj[t])=="[object String]"&&searchObj[t].includes('.')){
216
+ let [key,subkey]=searchObj[t].split('.');
217
+ this.$attrs.formData[key]&&(searchObj[t]=this.$attrs.formData[key][subkey])
218
+ }
219
+ })
220
+ // 接口请求参数
221
+ this.requestBody = {
222
+ ...(this.items?.api?.data || {}),
223
+ ...searchObj,
224
+ ...page,
225
+ };
226
+ },
227
+ filterFn(val) {
228
+ this.query = val;
229
+ this.useDefaule = false
230
+ if ((this.items?.api?.reqKeys ? this.items?.api?.reqKeys : {}).canInput) {
231
+ this.$emit("input", "");
232
+ this.$emit(`update:label`, val);
233
+ }
234
+ this.init();
235
+ },
236
+ getNextList() {
237
+ if (!this.items?.api?.page?.size) {
238
+ return
239
+ }
240
+ if ((this.current * 20) > this.total) return;
241
+ this.current += 1;
242
+ this.init(true);
243
+ },
244
+ changeFn(val) {
245
+ let item = this.options.find(t => t.value == val);
246
+ this.$emit("change", item)
247
+ },
248
+ changVariable(val){
249
+ if (val == '${inputValue}') return this.useDefaule ? (this.items?.api?.defaultInputValue || this.label ||this._value || "") : this.query;
250
+ if (!val) {
251
+ return val || "";
252
+ }
253
+ let str = String(val)
254
+ if (str == "${nowDate}") {
255
+ return dayjs().format("YYYY-MM-DD")
256
+ }
257
+ if (str && str.includes("$")) {
258
+ let key = str.replace("${", '').replace("}", "");
259
+ return this.variable[key] || "";
260
+ }
261
+ return val || "";
262
+ }
263
+ },
264
+ };
265
+ </script>
@@ -0,0 +1,60 @@
1
+ <template>
2
+ <div>
3
+ <el-radio-group v-model="_value" v-bind="$attrs" v-on="$listeners">
4
+ <el-radio :label="item.value" v-for="(item, index) in _options || []" :key="index">
5
+ {{ item.label }}
6
+ <el-tooltip v-if="item.isShowtoolTip" effect="dark" :content="item.toolTip" placement="top">
7
+ <i class="n20-icon-xinxitishi m-l-ss" style="color: var(--color-text-secondary);"></i>
8
+ </el-tooltip>
9
+ </el-radio>
10
+ </el-radio-group>
11
+ <el-tooltip v-if="$attrs.showTipAfter" effect="dark" :content="$attrs.afterTipContent" placement="top">
12
+ <i class="n20-icon-xinxitishi m-l-ss" style="color: var(--color-text-secondary); position: absolute; top: 10px;"></i>
13
+ </el-tooltip>
14
+ </div>
15
+ </template>
16
+ <script>
17
+ export default {
18
+ name: 'RadioGroup',
19
+ props: {
20
+ value: {
21
+ type: [String, Number],
22
+ defalut: '1'
23
+ },
24
+ items: {
25
+ type: Object,
26
+ defalut: () => {
27
+ return {
28
+ options: []
29
+ }
30
+ }
31
+ }
32
+ },
33
+ computed: {
34
+ _value: {
35
+ get() {
36
+ let res = (this.items.options || []).find(row => row.value == this.value)
37
+ this.$emit(`update:label`, res?.label)
38
+ return this.value
39
+ },
40
+ set(value) {
41
+ let res = (this.items.options || []).find(row => row.value == value)
42
+ this.$emit(`update:label`, res?.label)
43
+ this.$emit('input', value)
44
+ }
45
+ },
46
+ _options: {
47
+ get() {
48
+ return this.items.options.filter(row => row.isShow)
49
+ }
50
+ }
51
+ },
52
+ watch: {
53
+ value: {
54
+ handler(val) {
55
+ this._value = val
56
+ }
57
+ }
58
+ }
59
+ }
60
+ </script>
@@ -0,0 +1,53 @@
1
+ <!--
2
+ * @fileName Rate
3
+ * @filePath E:\code\jiuhengxing\T20\gts-invest_web 投资理财\invset\src\views\dynamicForms\components\Rate.vue
4
+ * @author wanghailing
5
+ * @date 2023-08-14 13:43:43
6
+ * @description 参数1
7
+ !-->
8
+ <template>
9
+ <N20-input-number
10
+ :max="999.999999"
11
+ :min="0"
12
+ :type="type"
13
+ :is-clearable="true"
14
+ v-model="_value"
15
+ :d-num="6"
16
+ :placeholder="$attrs.placeholder ? $attrs.placeholder : '请输入' | $l"
17
+ v-bind="$attrs"
18
+ v-on="$listeners"
19
+ />
20
+ </template>
21
+
22
+ <script>
23
+ export default {
24
+ name: 'Rate',
25
+ props: {
26
+ value: {
27
+ type: [String, Number],
28
+ defalut: "",
29
+ },
30
+ items: {
31
+ type: Object,
32
+ default: () => {},
33
+ },
34
+ },
35
+ computed: {
36
+ _value: {
37
+ get() {
38
+ return this.value;
39
+ },
40
+ set(value) {
41
+ this.$emit("input", value);
42
+ },
43
+ },
44
+ },
45
+ data() {
46
+ return {
47
+ type: "rate",
48
+ };
49
+ },
50
+ }
51
+ </script>
52
+ <style scoped lang='scss'>
53
+ </style>
@@ -0,0 +1,212 @@
1
+ <template>
2
+ <el-select
3
+ class="input-w"
4
+ v-model="_value"
5
+ :placeholder="$attrs.placeholder ? $attrs.placeholder : '请选择' | $l"
6
+ :multiple="items.multiple || false"
7
+ :filterable="items.filterable || true"
8
+ :key="items.prop"
9
+ v-bind="$attrs"
10
+ :disabled="disabled"
11
+ @change="changeFn"
12
+ :clearable="items.clearable ? items.clearable : true"
13
+ :filter-method="$attrs['filter-method'] || filterMethod"
14
+ @clear="clearFn"
15
+ @click.native="clickFn"
16
+ >
17
+ <el-option
18
+ v-for="(item) in options"
19
+ v-title="item.label"
20
+ :style="{'max-width': $attrs['show-overflow-tooltip'] ? '224px' : 'none'}"
21
+ :show-overflow-tooltip="true"
22
+ class="text-ellipsis"
23
+ :key="item.value + items.prop"
24
+ :label="item.label | $l"
25
+ :value="item.value"
26
+ >
27
+ {{labelKey ? item._label : item.label | $l}}
28
+ </el-option>
29
+ </el-select>
30
+ </template>
31
+ <script>
32
+ import dayjs from 'dayjs'
33
+ import clickoutside from 'element-ui/src/utils/clickoutside'
34
+ import { getDataForPost, getDataForGet } from '../utils/request'
35
+ export default {
36
+ name: "Select",
37
+ props: {
38
+ value: {
39
+ type: [String,Array,Number],
40
+ defalut: undefined,
41
+ },
42
+ disabled: {
43
+ type: [Boolean,Array,Number],
44
+ defalut: false,
45
+ },
46
+ items: {
47
+ type: Object,
48
+ defalut: () => {
49
+ return {
50
+ options: [],
51
+ };
52
+ },
53
+ },
54
+ variable: {
55
+ type: Object,
56
+ defalut: () => {
57
+ return {};
58
+ },
59
+ },
60
+ label: {
61
+ type: String,
62
+ defalut: "",
63
+ }
64
+ },
65
+ directives: {
66
+ clickoutside
67
+ },
68
+ computed: {
69
+ _value: {
70
+ get() {
71
+ return !['', null, undefined].includes(this.value) ? this.value : this.label;
72
+ },
73
+ set(value) {
74
+ if (['', null, undefined].includes(value)) {
75
+ this.$emit(`update:label`, "");
76
+ this.$emit("input", "");
77
+ return
78
+ }
79
+ let res = this.getName(value);
80
+ if (res.length == 0) {
81
+ this.$emit(`update:label`, value);
82
+ } else {
83
+ this.$emit(`update:label`, res.join(","));
84
+ this.$emit("input", value);
85
+ }
86
+ },
87
+ },
88
+ labelKey() {
89
+ return this.items?.api?.labelKey.includes(",") || this.items?.api?.labelKey.includes("{");
90
+ },
91
+ // 判断数据类型,格式化回显数据
92
+ valueType() {
93
+ return typeof this.value
94
+ }
95
+ },
96
+ watch: {
97
+ items: {
98
+ handler(newVal) {
99
+ this.init()
100
+ },
101
+ deep: true,
102
+ immediate: true,
103
+ }
104
+ },
105
+ data() {
106
+ return {
107
+ options: [],
108
+ optionsCopy: [],
109
+ };
110
+ },
111
+ mounted() {
112
+ this.init();
113
+ },
114
+ methods: {
115
+ getName(value) {
116
+ let temp = [];
117
+ if (Array.isArray(value)) {
118
+ for (let i of value) {
119
+ let res = (this.options || []).find((row) => row.value === i);
120
+ // 如果label显示的2个字段,则取第一个字段的值
121
+ if (res) temp.push(res['label']);
122
+ }
123
+ } else {
124
+ let res = (this.options || []).find((row) => row.value === value);
125
+ if (res) temp.push(res['label']);
126
+ }
127
+ return temp
128
+ },
129
+ changeFn(val) {
130
+ let item = this.options.find(t => t.value == val);
131
+ this.$emit("change", item)
132
+ },
133
+ async init() {
134
+ // 1、JSON模板中有自定义的取自定义的options
135
+ if (!this.items?.api?.apiUrl || !this.items?.api?.requestMethod) {
136
+ this.options = (this.items.options || {}) || [];
137
+ this.optionsCopy = (this.items.options || {}) || [];
138
+ return;
139
+ }
140
+ // 2、JSON模板中没有自定义的取接口的options,取api中接口获取options
141
+ let searchObj = this.items?.api?.reqKeys || {}
142
+ let headerConfig = this.items?.api?.headerConfig || {};
143
+ let res = null;
144
+ ["GET", "get"].includes(this.items?.api?.requestMethod) &&
145
+ (res = await getDataForGet(
146
+ this.items?.api?.apiUrl,
147
+ (searchObj || {}),
148
+ headerConfig
149
+ // this.$attrs.headers
150
+ ));
151
+
152
+ ["POST", "post"].includes(this.items?.api?.requestMethod) &&
153
+ (res = await getDataForPost(
154
+ this.items?.api?.apiUrl,
155
+ (searchObj || {}),
156
+ headerConfig
157
+ // this.$attrs.headers
158
+ ));
159
+ ;
160
+ this.options = ((this.items?.api?.dataProp ? new Function('res', `return res.${this.items?.api?.dataProp}`)(res) : (res.data)) || []).map((item) => {
161
+ item.label = item[this.items?.api?.labelKey || "label"];
162
+ item.value = item[this.items?.api?.valueKey || "value"];
163
+ if (this.valueType == 'string') {
164
+ item.value = String(item.value)
165
+ }
166
+ if (this.valueType == 'number') {
167
+ item.value = Number(item.value)
168
+ }
169
+ return item;
170
+ });
171
+ this.optionsCopy = this.options;
172
+ },
173
+ filterMethod(val) {
174
+ if ((this.items?.api?.reqKeys ? this.items?.api?.reqKeys : {}).canInput) {
175
+ this.$emit("input", "");
176
+ this.$emit(`update:label`, val);
177
+ }
178
+ if (val || val == 0) {
179
+ this.options = this.optionsCopy.filter(item => {
180
+ if (item.label.includes(val)) {
181
+ return true
182
+ }
183
+ })
184
+ return
185
+ }
186
+ this.options = this.optionsCopy
187
+ },
188
+ clickFn() {
189
+ if (this.options.length < 1) {
190
+ this.options = this.optionsCopy
191
+ }
192
+ },
193
+ clearFn() {
194
+ this.options = this.optionsCopy
195
+ },
196
+ changVariable(val){
197
+ if (!val) {
198
+ return val || "";
199
+ }
200
+ let str = String(val)
201
+ if (str == "${nowDate}") {
202
+ return dayjs().format("YYYY-MM-DD")
203
+ }
204
+ if (str && str.includes("$")) {
205
+ let key = str.replace("${", '').replace("}", "");
206
+ return this.variable[key] || "";
207
+ }
208
+ return val || "";
209
+ }
210
+ },
211
+ };
212
+ </script>