@bsgoal/common 2.7.5 → 2.7.8

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsgoal/common",
3
- "version": "2.7.5",
3
+ "version": "2.7.8",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -2,7 +2,7 @@
2
2
  * @Author: canlong.shen
3
3
  * @Date: 2023-04-10 15:00:00
4
4
  * @LastEditors: canlong.shen
5
- * @LastEditTime: 2023-05-26 15:55:40
5
+ * @LastEditTime: 2023-05-30 14:07:00
6
6
  * @FilePath: \common\src\components\bsgoal-base-form\demo.vue
7
7
  * @Description: 表单公共组件演示组件
8
8
  *
@@ -33,13 +33,26 @@ const confirm = () => {
33
33
  })
34
34
  }
35
35
 
36
- const bindModel = ref({ prop1: '111', prop99: 1, prop101: '否', prop102: '0' })
36
+ const bindModel = ref({ prop1: '111', prop99: 1, prop101: '否', prop102: '0', _prop104: '' })
37
+
38
+
37
39
 
38
40
  // 配置项
39
41
  const configOptions = ref([
40
- {
42
+ {
41
43
  label: 'prop104',
42
44
  prop: '_prop104',
45
+ validator:true,
46
+ rules: [
47
+ {
48
+ validator: (rule, value, callback) => {
49
+ console.log('value', value)
50
+
51
+ return callback(new Error('Please input the age'))
52
+ },
53
+ trigger: 'change'
54
+ }
55
+ ]
43
56
  },
44
57
  {
45
58
  label: 'prop103',
@@ -248,9 +261,9 @@ const configOptions = ref([
248
261
  :config-options="configOptions"
249
262
  :bind-model="bindModel"
250
263
  >
251
- <template #_prop104="{option}">
252
- <div>666 </div>
253
- </template>
264
+ <template #_prop104>
265
+ 6666
266
+ </template>
254
267
  </BsgoalBaseForm>
255
268
  <el-button type="primary" @click="confirm">提交</el-button>
256
269
  </div>
@@ -2,7 +2,7 @@
2
2
  * @Author: canlong.shen
3
3
  * @Date: 2023-04-17 11:44:29
4
4
  * @LastEditors: canlong.shen
5
- * @LastEditTime: 2023-05-23 15:37:32
5
+ * @LastEditTime: 2023-05-30 14:05:39
6
6
  * @FilePath: \common\src\components\bsgoal-base-form\index.vue
7
7
  * @Description: 表单公共组件
8
8
  *
@@ -154,12 +154,10 @@ watchEffect(() => {
154
154
  }
155
155
  const bindValue = unref(model)[prop]
156
156
  // '_xxx 开头都是内容插槽'
157
- if (!prop.startsWith('_')) {
158
- model.value[prop] = bindValue || valuesModel[prop] || value
157
+ model.value[prop] = bindValue || valuesModel[prop] || value
159
158
 
160
- if (isObject(show)) {
161
- watchPropsForShow(show, unref(model), prop)
162
- }
159
+ if (isObject(show)) {
160
+ watchPropsForShow(show, unref(model), prop)
163
161
  }
164
162
  })
165
163
  })
@@ -177,15 +175,13 @@ const configOptionsGet = computed(() => {
177
175
  const { configOptions } = props
178
176
  const options = unref(configOptions)
179
177
  const reOptions = options.map((option) => {
180
- let { rules = [], label = '' } = option
178
+ let { rules = [], label = '', validator = false } = option
181
179
  const requiredRule = { required: true, message: `${label}不能为空`, trigger: 'blur' }
182
180
  if (isBoolean(rules) && rules) {
183
181
  rules = [requiredRule]
184
- } else if (Array.isArray(rules) && !!rules.length) {
185
- rules = [requiredRule, ...rules]
186
- } else {
187
- rules = []
188
- }
182
+ } else if ( !validator && Array.isArray(rules) && !!rules.length ) {
183
+ rules = [ requiredRule ,...rules,]
184
+ }
189
185
  option.rules = rules
190
186
  return option
191
187
  })
@@ -317,6 +313,22 @@ const triggerValueChange = (type, prop) => {
317
313
  emits('on-change', emitValue)
318
314
  }
319
315
 
316
+ /**
317
+ * @Author: canlong.shen
318
+ * @description: 过滤掉插槽字段
319
+ * @default:
320
+ * @return {*}
321
+ */
322
+ const filterSlotProps = (model = {}) => {
323
+ const rebuildModel = {}
324
+ for (const prop of Object.keys(model)) {
325
+ if (!prop.startsWith('_')) {
326
+ rebuildModel[prop] = model[prop]
327
+ }
328
+ }
329
+ return rebuildModel
330
+ }
331
+
320
332
  /**
321
333
  * @Author: canlong.shen
322
334
  * @description: 表单校验
@@ -327,7 +339,8 @@ const validateForm = (callback = () => {}) => {
327
339
  EL_FORM_REF.value.validate((valid = false, field = {}) => {
328
340
  if (valid) {
329
341
  const validModel = triggerOperationForm()
330
- callback(validModel)
342
+ const cleanModel = filterSlotProps(validModel)
343
+ callback(cleanModel)
331
344
  } else {
332
345
  callback(false)
333
346