@bsgoal/common 1.9.4 → 1.9.5

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": "1.9.4",
3
+ "version": "1.9.5",
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-22 15:56:58
5
+ * @LastEditTime: 2023-05-22 17:56:31
6
6
  * @FilePath: \common\src\components\bsgoal-base-form\demo.vue
7
7
  * @Description: 表单公共组件演示组件
8
8
  *
@@ -29,7 +29,7 @@ const confirm = () => {
29
29
  })
30
30
  }
31
31
 
32
- const bindModel = ref({ prop1: '111', prop99: 1 ,prop101:'否'})
32
+ const bindModel = ref({ prop1: '111', prop99: 1, prop101: '否', prop102: '1' })
33
33
 
34
34
  // 配置项
35
35
  const configOptions = ref([
@@ -37,13 +37,23 @@ const configOptions = ref([
37
37
  label: 'prop1011111111111111',
38
38
  prop: 'prop101',
39
39
  type: EnumType.CHECKBOX_SINGLE,
40
+ show: { prop102: ['1'] },
40
41
  range: [
41
42
  {
42
43
  value: '是'
43
44
  },
44
45
  {
45
46
  value: '否'
46
- },
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ type: EnumType.SWITCH,
52
+ label:'prop102',
53
+ prop: 'prop102',
54
+ range: [
55
+ { label: '是', value: '1' },
56
+ { label: '否', value: '0' }
47
57
  ]
48
58
  },
49
59
  {
@@ -66,7 +76,7 @@ const configOptions = ref([
66
76
  prop: 'prop1',
67
77
  type: EnumType.INPUT,
68
78
  width: '100px',
69
- rules: true,
79
+ rules: [],
70
80
  readonly: true
71
81
  },
72
82
  {
@@ -75,7 +85,7 @@ const configOptions = ref([
75
85
  prop: 'prop20',
76
86
  type: EnumType.INPUT,
77
87
  width: '100px',
78
- rules: true,
88
+ rules: [],
79
89
  readonly: true
80
90
  },
81
91
  {
@@ -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-22 15:37:49
5
+ * @LastEditTime: 2023-05-22 18:18:44
6
6
  * @FilePath: \common\src\components\bsgoal-base-form\index.vue
7
7
  * @Description: 表单公共组件
8
8
  *
@@ -16,11 +16,13 @@ export default {
16
16
  <script setup>
17
17
  /* setup模板
18
18
  ---------------------------------------------------------------- */
19
- import { ref, computed, unref, watchEffect } from 'vue'
19
+ import { ref, computed, unref, watchEffect, watch } from 'vue'
20
20
  import EnumType from '../../enums/componentTypeEnums.js'
21
21
  import baseDirective from '../../directives/directiveBase.js'
22
- import { ElMessage } from 'element-plus'
23
22
  import BsgoalBaseTooltip from '../bsgoal-base-tooltip/index.vue'
23
+ import { ElMessage } from 'element-plus'
24
+ import { isObject } from '../../utils/common.js'
25
+ import { isBoolean } from 'lodash'
24
26
  // props
25
27
  const props = defineProps({
26
28
  /**
@@ -110,6 +112,31 @@ const vAlign = baseDirective.align
110
112
  const model = ref(props.bindModel)
111
113
  const watchPropList = []
112
114
 
115
+ // ---> S 初始值 <---
116
+ /**
117
+ * @Author: canlong.shen
118
+ * @description:
119
+ * @default:
120
+ * @return {*}
121
+ */
122
+ const watchPropsForShow = (show = {}, model = {}, prop = '') => {
123
+ // { prop1:[1,2,3] , prop2: [4,5,6] }
124
+ watchEffect(() => {
125
+ const resultList = []
126
+ for (const [name = '', values = []] of Object.entries(show)) {
127
+ resultList.push(values.includes(`${model[name]}`))
128
+ }
129
+ const { configOptions } = props
130
+ const options = unref(configOptions)
131
+ const findProp = options.find((fi) => fi.prop === prop)
132
+ if (resultList.every((ei) => !!ei)) {
133
+ findProp.visible = true
134
+ } else {
135
+ findProp.visible = false
136
+ }
137
+ })
138
+ }
139
+
113
140
  /**
114
141
  * @Author: canlong.shen
115
142
  * @description: 绑定的对象
@@ -122,16 +149,22 @@ watchEffect(() => {
122
149
  const options = unref(configOptions)
123
150
  const valuesModel = unref(values)
124
151
  options.forEach((fei) => {
125
- const { value = '', prop = '', type = '' } = fei
152
+ const { value = '', prop = '', type = '', show = null } = fei
126
153
  if (![EnumType.INPUT, EnumType.INPUT_TEXT_AREA].includes(type)) {
127
154
  watchPropList.push(prop)
128
155
  }
129
156
  const bindValue = unref(model)[prop]
130
- // console.log(prop,'valuesModel[prop]',bindValue)
157
+
131
158
  model.value[prop] = bindValue || valuesModel[prop] || value
159
+
160
+ if (isObject(show)) {
161
+ watchPropsForShow(show, unref(model), prop)
162
+ }
132
163
  })
133
164
  })
134
165
 
166
+ // ---> E 初始值 <---
167
+
135
168
  /**
136
169
  * @Author: canlong.shen
137
170
  * @description: 配置项
@@ -143,16 +176,14 @@ const configOptionsGet = computed(() => {
143
176
  const { configOptions } = props
144
177
  const options = unref(configOptions)
145
178
  const reOptions = options.map((option) => {
146
- let { rules = false, label = '' } = option
179
+ let { rules = [], label = '' } = option
147
180
  const requiredRule = { required: true, message: `${label}不能为空`, trigger: 'blur' }
148
- if (rules) {
149
- if (typeof rules === 'boolean') {
150
- rules = [requiredRule]
151
- } else if (Array.isArray(rules)) {
152
- rules = [requiredRule, ...rules]
153
- } else {
154
- rules = [requiredRule, rules]
155
- }
181
+ if (isBoolean(rules) && rules) {
182
+ rules = [requiredRule]
183
+ } else if (Array.isArray(rules) && !!rules.length) {
184
+ rules = [requiredRule, ...rules]
185
+ } else {
186
+ rules = []
156
187
  }
157
188
  option.rules = rules
158
189
  return option
@@ -375,13 +406,14 @@ defineExpose({
375
406
  format = '',
376
407
  rules = [],
377
408
  limit = limits,
378
- length = 255
409
+ length = 255,
410
+ visible = true
379
411
  } = {},
380
412
  key
381
413
  ) of configOptionsGet"
382
414
  :key="key"
383
415
  >
384
- <el-col :xs="24" :sm="24" :md="medium">
416
+ <el-col v-show="visible" :xs="24" :sm="24" :md="medium">
385
417
  <el-form-item :label="label" :prop="prop" :rules="rules">
386
418
  <slot :name="[prop]" :option="{ readonly, value: model[prop], values: model }">
387
419
  <!-- S 内容组件 -->