hookehuyr

✨ feat(单选控件): 支持选项说明

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: 2023-02-10 11:04:38 4 + * @LastEditTime: 2023-02-21 20:58:52
5 * @FilePath: /data-table/src/components/RadioField/index.vue 5 * @FilePath: /data-table/src/components/RadioField/index.vue
6 * @Description: 单项选择控件 6 * @Description: 单项选择控件
7 --> 7 -->
...@@ -19,6 +19,13 @@ ...@@ -19,6 +19,13 @@
19 <div v-for="x in item.component_props.options" :key="x.value" class="radio-wrapper"> 19 <div v-for="x in item.component_props.options" :key="x.value" class="radio-wrapper">
20 <van-radio :name="x.value" icon-size="1rem" :checked-color="themeVars.radioColor" 20 <van-radio :name="x.value" icon-size="1rem" :checked-color="themeVars.radioColor"
21 style="margin-bottom: 0.25rem">{{ x.title }}</van-radio> 21 style="margin-bottom: 0.25rem">{{ x.title }}</van-radio>
22 + <div class="van-multi-ellipsis--l3 rule-desc-text">{{ x.desc_text }}</div>
23 + <div v-if="x.desc_type === 'text'" class="rule-box" @click="showRule(x)">
24 + {{ x.desc_btn_name }}&nbsp;>>
25 + </div>
26 + <div v-if="x.desc_type === 'url'" class="rule-box" @click="showUrl(x)">
27 + {{ x.desc_btn_name }}&nbsp;<van-icon name="link-o" />
28 + </div>
22 <van-field v-if="radio_value === x.value && x.is_input" @blur="onBlur(x)" v-model="x.affix" label=" " label-width="5px" 29 <van-field v-if="radio_value === x.value && x.is_input" @blur="onBlur(x)" v-model="x.affix" label=" " label-width="5px"
23 :placeholder="x.input_placeholder" :rules="x.input_required ? rules : ''" :required="x.input_required" 30 :placeholder="x.input_placeholder" :rules="x.input_required ? rules : ''" :required="x.input_required"
24 class="affix-input" /> 31 class="affix-input" />
...@@ -27,10 +34,25 @@ ...@@ -27,10 +34,25 @@
27 </template> 34 </template>
28 </van-field> 35 </van-field>
29 </div> 36 </div>
37 +
38 + <van-overlay :show="show" :lock-scroll="false">
39 + <div class="rule-wrapper" @click.stop>
40 + <div class="rule-block">
41 + <div style="height: 70vh; min-height: 70vh; overflow: scroll; white-space: pre-wrap; line-height: 1.5;" v-html="rule_content"></div>
42 + <div class="close-btn">
43 + <van-button type="primary" block @click="closeRule"
44 + >关&nbsp;&nbsp;闭</van-button
45 + >
46 + </div>
47 + <div></div>
48 + </div>
49 + </div>
50 + </van-overlay>
30 </template> 51 </template>
31 52
32 <script setup> 53 <script setup>
33 import { styleColor } from "@/constant.js"; 54 import { styleColor } from "@/constant.js";
55 +import $ from "jquery";
34 56
35 const props = defineProps({ 57 const props = defineProps({
36 item: Object, 58 item: Object,
...@@ -93,7 +115,25 @@ onMounted(() => { ...@@ -93,7 +115,25 @@ onMounted(() => {
93 // 发送自定义数据结构 115 // 发送自定义数据结构
94 props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" }; 116 props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" };
95 emit("active", props.item.value); 117 emit("active", props.item.value);
118 + //
119 + $(".rule-box").css("color", themeVars.radioColor);
96 }) 120 })
121 +
122 +// 补充信息弹框
123 +const show = ref(false);
124 +const showRule = (rule) => {
125 + show.value = true;
126 + rule.desc_text = rule.desc_text.replace(/\\n/g, "<br>")
127 + rule_content.value = rule.desc_text;
128 +};
129 +const closeRule = () => {
130 + show.value = false;
131 + rule_content.value = "";
132 +};
133 +const showUrl = (rule) => {
134 + location.href = rule.desc_url
135 +}
136 +const rule_content = ref("");
97 </script> 137 </script>
98 138
99 <style lang="less" scoped> 139 <style lang="less" scoped>
...@@ -129,6 +169,46 @@ onMounted(() => { ...@@ -129,6 +169,46 @@ onMounted(() => {
129 margin-top: 0.5rem; 169 margin-top: 0.5rem;
130 margin-bottom: 0.25rem; 170 margin-bottom: 0.25rem;
131 } 171 }
172 + .rule-desc-text {
173 + margin: 0.35rem 0.5rem 0.5rem 1.75rem;
174 + font-size: 0.8rem;
175 + color: #808080;
176 + }
177 + .rule-box {
178 + font-size: 0.85rem;
179 + margin-left: 1.8rem;
180 + padding-bottom: 0.5rem;
181 + width: fit-content;
182 + }
183 +}
184 +
185 +.rule-wrapper {
186 + display: flex;
187 + align-items: center;
188 + justify-content: center;
189 + height: 100%;
190 +}
191 +
192 +.rule-block {
193 + position: relative;
194 + width: 80vw;
195 + height: 80vh;
196 + background-color: #fff;
197 + overflow: scroll;
198 + padding: 1rem;
199 + .close-btn {
200 + position: absolute;
201 + bottom: 1rem;
202 + // transform: translateX(100%);
203 + width: calc(100% - 2rem);
204 + }
205 +}
206 +.multi-rule-field-box {
207 + border: 1px solid #eaeaea;
208 + border-radius: 0.25rem;
209 + padding: 1rem 0.5rem 0 0.5rem;
210 + // width: 100vw;
211 + margin-bottom: 0.5rem;
132 } 212 }
133 213
134 :deep(.van-radio) { 214 :deep(.van-radio) {
......