hookehuyr

fix 修复多选组件默认值还原和只读状态的显示问题

1 <!-- 1 <!--
2 * @Date: 2022-08-30 11:34:19 2 * @Date: 2022-08-30 11:34:19
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-06-06 15:41:04 4 + * @LastEditTime: 2024-06-13 15:27:37
5 * @FilePath: /data-table/src/components/CheckboxField/index.vue 5 * @FilePath: /data-table/src/components/CheckboxField/index.vue
6 * @Description: 多项选择控件 6 * @Description: 多项选择控件
7 --> 7 -->
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
21 :max="item.component_props.max" style="width: 100%"> 21 :max="item.component_props.max" style="width: 100%">
22 <div v-for="x in item.component_props.options" :key="x.title" class="checkbox-wrapper"> 22 <div v-for="x in item.component_props.options" :key="x.title" class="checkbox-wrapper">
23 <div v-if="item.component_props.readonly"> 23 <div v-if="item.component_props.readonly">
24 - <div v-if="item.component_props.default.includes(x.value)" role="checkbox" class="van-checkbox van-checkbox--vertical" tabindex="0" aria-checked="true" data-v-3722f8ba="" style="margin-bottom: 0.25rem;"><div class="van-checkbox__icon van-checkbox__icon--square van-checkbox__icon--checked" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success" style="border-color: rgb(194, 145, 95); background-color: rgb(194, 145, 95);"><!----><!----><!----></i></div><span class="van-checkbox__label">{{ x.title }}</span></div> 24 + <div v-if="checkbox_value.includes(x.value)" role="checkbox" class="van-checkbox van-checkbox--vertical" tabindex="0" aria-checked="true" data-v-3722f8ba="" style="margin-bottom: 0.25rem;"><div class="van-checkbox__icon van-checkbox__icon--square van-checkbox__icon--checked" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success" style="border-color: rgb(194, 145, 95); background-color: rgb(194, 145, 95);"><!----><!----><!----></i></div><span class="van-checkbox__label">{{ x.title }}</span></div>
25 <div v-else role="checkbox" class="van-checkbox van-checkbox--vertical" tabindex="0" aria-checked="false" data-v-3722f8ba="" style="margin-bottom: 0.25rem;"><div class="van-checkbox__icon van-checkbox__icon--square" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success" style=""><!----><!----><!----></i></div><span class="van-checkbox__label">{{ x.title }}</span></div> 25 <div v-else role="checkbox" class="van-checkbox van-checkbox--vertical" tabindex="0" aria-checked="false" data-v-3722f8ba="" style="margin-bottom: 0.25rem;"><div class="van-checkbox__icon van-checkbox__icon--square" style="font-size: 1rem;"><i class="van-badge__wrapper van-icon van-icon-success" style=""><!----><!----><!----></i></div><span class="van-checkbox__label">{{ x.title }}</span></div>
26 </div> 26 </div>
27 <van-checkbox v-else @click="onClick(x)" :name="x.title" icon-size="1rem" shape="square" 27 <van-checkbox v-else @click="onClick(x)" :name="x.title" icon-size="1rem" shape="square"
28 :checked-color="themeVars.radioColor" style="margin-bottom: 0.25rem">{{ x.title }}</van-checkbox> 28 :checked-color="themeVars.radioColor" style="margin-bottom: 0.25rem">{{ x.title }}</van-checkbox>
29 - <van-field v-if="checkbox_value.includes(x.value) && x.is_input && (item.component_props.readonly && x.affix)" @blur="onBlur(x)" v-model="x.affix" 29 + <van-field v-if="checkbox_value.includes(x.value) && x.is_input" @blur="onBlur(x)" v-model="x.affix"
30 label=" " label-width="5px" :placeholder="x.input_placeholder" :rules="x.input_required ? rules : ''" 30 label=" " label-width="5px" :placeholder="x.input_placeholder" :rules="x.input_required ? rules : ''"
31 :required="x.input_required" :readonly="item.component_props.readonly" class="affix-input" /> 31 :required="x.input_required" :readonly="item.component_props.readonly" class="affix-input" />
32 </div> 32 </div>
...@@ -96,6 +96,38 @@ const handleEmit = (item) => { ...@@ -96,6 +96,38 @@ const handleEmit = (item) => {
96 emit("active", props.item.value); 96 emit("active", props.item.value);
97 } 97 }
98 onMounted(() => { 98 onMounted(() => {
99 + // TAG:默认值处理
100 + let arr = props.item.component_props.default;
101 + let hasColonSome = arr.some(item => item.includes(':')); // 检查是否有元素包含冒号
102 + if (hasColonSome) { // 带补充信息输入框
103 + // 提取冒号前的部分生成新的数组
104 + let titles = arr.map(item => {
105 + if (item.includes(':')) {
106 + return item.split(': ')[0]
107 + } else {
108 + return item
109 + }
110 + });
111 + // 生成对象
112 + let obj = {};
113 + arr.forEach(item => {
114 + if (item.includes(':')) {
115 + let parts = item.split(': ');
116 + obj[parts[0]] = parseInt(parts[1]);
117 + }
118 + });
119 + checkbox_value.value = titles;
120 + //
121 + props.item.component_props.options.forEach(item => {
122 + for (const key in obj) {
123 + if (item.value === key) {
124 + item.affix = obj[key]
125 + }
126 + }
127 + })
128 + } else { // 纯多选情况
129 + checkbox_value.value = arr;
130 + }
99 // 发送自定义数据结构 131 // 发送自定义数据结构
100 props.item.value = { key: props.item.key, value: checkbox_value.value, affix: affix_value.value, type: "checkbox" }; 132 props.item.value = { key: props.item.key, value: checkbox_value.value, affix: affix_value.value, type: "checkbox" };
101 emit("active", props.item.value); 133 emit("active", props.item.value);
......