Showing
1 changed file
with
44 additions
and
24 deletions
| 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: 2022-11-24 14:33:47 | 4 | + * @LastEditTime: 2022-12-30 17:17:26 |
| 5 | - * @FilePath: /data-table/src/components/RuleField/index.vue | 5 | + * @FilePath: /data-table/src/components/MultiRuleField/index.vue |
| 6 | * @Description: 多选规则确认控件 | 6 | * @Description: 多选规则确认控件 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | - <div class="multi-rule-field-page"> | 9 | + <div v-if="HideShow" class="multi-rule-field-page"> |
| 10 | - <div class="label"> | 10 | + <div class="label"> {{ item.component_props.label }}<span v-if="item.component_props.required" class="required"> *</span> |
| 11 | - {{ item.component_props.label | 11 | + <span v-if="item.component_props.min_count" style="color: #999; font-size: 0.85rem;">(最少选{{ item.component_props.min_count }}项)</span> |
| 12 | - }}<span v-if="item.component_props.required"> *</span>(最少选{{ | ||
| 13 | - item.component_props.count | ||
| 14 | - }}项) | ||
| 15 | </div> | 12 | </div> |
| 16 | <van-field :name="item.key" :rules="rules" :border="false" style="padding-bottom: 0"> | 13 | <van-field :name="item.key" :rules="rules" :border="false" style="padding-bottom: 0"> |
| 17 | <template #input> | 14 | <template #input> |
| 18 | <van-checkbox-group v-model="item.value" style="width: 100%"> | 15 | <van-checkbox-group v-model="item.value" style="width: 100%"> |
| 19 | - <template v-for="(rule, idx) in item.component_props.rules" :key="idx"> | 16 | + <template v-for="(rule, idx) in item.component_props.options" :key="idx"> |
| 20 | <div class="multi-rule-field-box"> | 17 | <div class="multi-rule-field-box"> |
| 21 | <van-checkbox | 18 | <van-checkbox |
| 22 | - :name="idx" | 19 | + :name="rule.value" |
| 23 | shape="square" | 20 | shape="square" |
| 24 | :checked-color="themeVars.radioColor" | 21 | :checked-color="themeVars.radioColor" |
| 25 | - >{{ rule.rule_desc }}</van-checkbox | 22 | + >{{ rule.title }}</van-checkbox |
| 26 | > | 23 | > |
| 27 | - <div class="rule-box" @click="showRule(rule)"> | 24 | + <div class="van-multi-ellipsis--l3 rule-desc-text">{{ rule.desc_text }}</div> |
| 28 | - {{ rule.rule_link }} >> | 25 | + <div v-if="rule.desc_type === 'text'" class="rule-box" @click="showRule(rule)"> |
| 26 | + {{ rule.desc_btn_name }} >> | ||
| 27 | + </div> | ||
| 28 | + <div v-if="rule.desc_type === 'url'" class="rule-box" @click="showUrl(rule)"> | ||
| 29 | + {{ rule.desc_btn_name }} <van-icon name="link-o" /> | ||
| 29 | </div> | 30 | </div> |
| 30 | </div> | 31 | </div> |
| 31 | </template> | 32 | </template> |
| ... | @@ -56,7 +57,10 @@ import $ from "jquery"; | ... | @@ -56,7 +57,10 @@ import $ from "jquery"; |
| 56 | const props = defineProps({ | 57 | const props = defineProps({ |
| 57 | item: Object, | 58 | item: Object, |
| 58 | }); | 59 | }); |
| 59 | - | 60 | +// 隐藏显示 |
| 61 | +const HideShow = computed(() => { | ||
| 62 | + return !props.item.component_props.disabled | ||
| 63 | +}) | ||
| 60 | // TAG: 自定义主题颜色 | 64 | // TAG: 自定义主题颜色 |
| 61 | const themeVars = { | 65 | const themeVars = { |
| 62 | radioColor: styleColor.baseColor, | 66 | radioColor: styleColor.baseColor, |
| ... | @@ -68,28 +72,39 @@ const show = ref(false); | ... | @@ -68,28 +72,39 @@ const show = ref(false); |
| 68 | const checked = ref([]); | 72 | const checked = ref([]); |
| 69 | const showRule = (rule) => { | 73 | const showRule = (rule) => { |
| 70 | show.value = true; | 74 | show.value = true; |
| 71 | - rule_content.value = rule.rule_content; | 75 | + rule.desc_text = rule.desc_text.replace(/\\n/g, "<br>") |
| 76 | + rule_content.value = rule.desc_text; | ||
| 72 | }; | 77 | }; |
| 73 | const closeRule = () => { | 78 | const closeRule = () => { |
| 74 | show.value = false; | 79 | show.value = false; |
| 75 | rule_content.value = ""; | 80 | rule_content.value = ""; |
| 76 | }; | 81 | }; |
| 82 | +const showUrl = (rule) => { | ||
| 83 | + location.href = rule.desc_url | ||
| 84 | +} | ||
| 77 | const rule_content = ref(""); | 85 | const rule_content = ref(""); |
| 78 | - | 86 | +const required = props.item.component_props.required; |
| 87 | +const min_count = props.item.component_props.min_count; | ||
| 88 | +const max_count = props.item.component_props.max_count; | ||
| 79 | const validator = (val) => { | 89 | const validator = (val) => { |
| 80 | - if (!props.item.component_props.required) { | 90 | + if (required && !val.length) { |
| 81 | - // 非必填 | 91 | + return false; |
| 82 | - return true; | 92 | + } else if (min_count && props.item.value.length < min_count) { |
| 93 | + return false; | ||
| 94 | + } else if (max_count && props.item.value.length > max_count) { | ||
| 95 | + return false; | ||
| 83 | } else { | 96 | } else { |
| 84 | - return props.item.value.length >= props.item.component_props.count ? true : false; | 97 | + return true; |
| 85 | } | 98 | } |
| 86 | }; | 99 | }; |
| 87 | // 错误提示文案 | 100 | // 错误提示文案 |
| 88 | const validatorMessage = (val, rule) => { | 101 | const validatorMessage = (val, rule) => { |
| 89 | - if (!val) { | 102 | + if (required && !val.length) { |
| 90 | return "选择项不能为空"; | 103 | return "选择项不能为空"; |
| 91 | - } else if (props.item.value.length < props.item.component_props.count) { | 104 | + } else if (min_count && props.item.value.length < min_count) { |
| 92 | - return `最少选择${props.item.component_props.count}项`; | 105 | + return `最少选择${min_count}项`; |
| 106 | + } else if (max_count && props.item.value.length > max_count) { | ||
| 107 | + return `最多选择${max_count}项`; | ||
| 93 | } | 108 | } |
| 94 | }; | 109 | }; |
| 95 | const rules = [{ validator, message: validatorMessage }]; | 110 | const rules = [{ validator, message: validatorMessage }]; |
| ... | @@ -101,10 +116,15 @@ const rules = [{ validator, message: validatorMessage }]; | ... | @@ -101,10 +116,15 @@ const rules = [{ validator, message: validatorMessage }]; |
| 101 | padding: 1rem 1rem 0 1rem; | 116 | padding: 1rem 1rem 0 1rem; |
| 102 | font-size: 0.9rem; | 117 | font-size: 0.9rem; |
| 103 | font-weight: bold; | 118 | font-weight: bold; |
| 104 | - span { | 119 | + span.required { |
| 105 | color: red; | 120 | color: red; |
| 106 | } | 121 | } |
| 107 | } | 122 | } |
| 123 | + .rule-desc-text { | ||
| 124 | + margin: 0.35rem 0.5rem 0.5rem 1.75rem; | ||
| 125 | + font-size: 0.8rem; | ||
| 126 | + color: #808080; | ||
| 127 | + } | ||
| 108 | .rule-box { | 128 | .rule-box { |
| 109 | font-size: 0.85rem; | 129 | font-size: 0.85rem; |
| 110 | margin-left: 1.8rem; | 130 | margin-left: 1.8rem; | ... | ... |
-
Please register or login to post a comment