@@ -100,7 +100,6 @@ export default {
100100 mounted () {
101101 this .getUsers ()
102102 this .getConfigs ()
103- window .test = this ;
104103 },
105104 methods: {
106105 getUsers () {
@@ -121,24 +120,26 @@ export default {
121120 ' get'
122121 )
123122 .then (res => {
123+ const valueMap = this .valueMap ;
124124 Object .keys (res || {}).forEach (key => {
125- this . valueMap [key] = {};
125+ valueMap[key] = {};
126126 Object .keys (res[key]).forEach (k => {
127127 const formatKey = k .replace (/ \. / g , ' /' );
128- this . valueMap [key][formatKey] = res[key][k];
128+ valueMap[key][formatKey] = res[key][k];
129129 })
130130 })
131131 Object .keys (this .diyMap ).forEach (key => {
132- if (Object .keys (this . valueMap ).includes (key)) {
133- let keyValue = Object .keys (this . valueMap [key] || {}).map (k => ({key: k .replace (/ \/ / g , ' .' ), value: this . valueMap [key][k]}));
134- this . valueMap [key] = {};
132+ if (Object .keys (valueMap).includes (key)) {
133+ let keyValue = Object .keys (valueMap[key] || {}).map (k => ({key: k .replace (/ \/ / g , ' .' ), value: valueMap[key][k]}));
134+ valueMap[key] = {};
135135 if (! keyValue .length ) keyValue = [{value: ' ' , key: ' ' }];
136136 this .diyMap = {
137137 ... this .diyMap ,
138138 [key]: keyValue
139139 }
140140 }
141141 })
142+ this .valueMap = cloneDeep (valueMap);
142143 })
143144 .catch (e => console .warn (e))
144145 },
@@ -151,9 +152,11 @@ export default {
151152 .then (res => {
152153 console .log (res)
153154 let configs = res .def ;
155+ const valueMap = {};
156+ const rule = {};
154157 configs = configs .map (conf => {
155- this . valueMap [conf .key ] = {};
156- this . rule [conf .key ] = {};
158+ valueMap[conf .key ] = {};
159+ rule[conf .key ] = {};
157160 if (! conf .child_def ) return conf;
158161 if (! conf .child_def .length ) {
159162 this .diyMap = {... this .diyMap , [conf .key ]: [{value: ' ' , key: ' ' }]};
@@ -164,19 +167,21 @@ export default {
164167 const defaultValue = def .default_value || ' ' ;
165168 const defKey = def .key .replace (/ \. / g , ' /' );
166169 def .key = defKey;
167- this . valueMap [conf .key ][defKey] = defaultValue;
170+ valueMap[conf .key ][defKey] = defaultValue;
168171 const rules = [{required: def .required , message: this .$t (' message.streamis.formItems.notEmpty' ), trigger: ' blur' }];
169172 if (def .type !== ' SELECT' ) {
170173 if (def .validate_rule ) rules .push ({
171174 pattern: new RegExp (def .validate_rule ),
172175 message: this .$t (' message.streamis.formItems.wrongFormat' ),
173176 })
174177 }
175- this . rule [conf .key ][defKey] = rules;
178+ rule[conf .key ][defKey] = rules;
176179 return def;
177- }).filter (def => [' SELECT' , ' INPUT' , ' NUMBER' ].includes (def .type ));
180+ }).filter (def => [' SELECT' , ' INPUT' , ' NUMBER' ].includes (def .type )). filter ( def => !! def . visiable ) ;
178181 return conf;
179182 });
183+ this .valueMap = cloneDeep (valueMap);
184+ this .rule = cloneDeep (rule);
180185 this .configs = configs;
181186 this .getValues ()
182187 })
@@ -212,14 +217,20 @@ export default {
212217 })
213218 });
214219 let warning = false ;
220+ let emptyWarning = false ;
215221 Object .keys (this .diyMap ).forEach (key => {
216222 configuration[key] = {};
217223 (this .diyMap [key] || []).forEach (mapKey => {
224+ emptyWarning = ! mapKey .key || ! mapKey .key .trim ();
218225 if (configuration[key][mapKey .key ]) warning = true ;
219- configuration[key][mapKey .key ] = mapKey .value ;
226+ configuration[key][mapKey .key ] = mapKey .value || ' ' ;
220227 })
221228 });
222229 console .log (' configuration' , configuration, this .valueMap )
230+ if (emptyWarning) {
231+ this .saveLoading = false ;
232+ return this .$Message .error ({ content: ' 请删除多余自定义字段,key值不能为空' });
233+ }
223234 if (warning) {
224235 this .saveLoading = false ;
225236 return this .$Message .error ({ content: ' 自定义字段名称不能重复' });
0 commit comments