index.vue
3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-11-24 14:33:47
* @FilePath: /data-table/src/components/RuleField/index.vue
* @Description: 多选规则确认控件
-->
<template>
<div class="multi-rule-field-page">
<div class="label">
{{ item.component_props.label
}}<span v-if="item.component_props.required"> *</span>(最少选{{
item.component_props.count
}}项)
</div>
<van-field :name="item.key" :rules="rules" :border="false" style="padding-bottom: 0">
<template #input>
<van-checkbox-group v-model="item.value">
<template v-for="(rule, idx) in item.component_props.rules" :key="idx">
<van-checkbox
:name="idx"
shape="square"
:checked-color="themeVars.radioColor"
>{{ rule.rule_desc }}</van-checkbox
>
<div class="rule-box" @click="showRule(rule)">
{{ rule.rule_link }} >>
</div>
</template>
</van-checkbox-group>
</template>
</van-field>
</div>
<van-overlay :show="show">
<div class="rule-wrapper" @click.stop>
<div class="rule-block">
<div style="height: 70vh; overflow: scroll" v-html="rule_content"></div>
<div class="close-btn">
<van-button type="primary" block @click="closeRule"
>关 闭</van-button
>
</div>
<div></div>
</div>
</div>
</van-overlay>
</template>
<script setup>
import { styleColor } from "@/constant.js";
import $ from "jquery";
const props = defineProps({
item: Object,
});
// TAG: 自定义主题颜色
const themeVars = {
radioColor: styleColor.baseColor,
};
onMounted(() => {
$(".rule-box").css("color", themeVars.radioColor);
});
const show = ref(false);
const checked = ref([]);
const showRule = (rule) => {
show.value = true;
rule_content.value = rule.rule_content;
};
const closeRule = () => {
show.value = false;
rule_content.value = "";
};
const rule_content = ref("");
const validator = (val) => {
if (!props.item.component_props.required) {
// 非必填
return true;
} else {
return props.item.value.length >= props.item.component_props.count ? true : false;
}
};
// 错误提示文案
const validatorMessage = (val, rule) => {
if (!val) {
return "选择项不能为空";
} else if (props.item.value.length < props.item.component_props.count) {
return `最少选择${props.item.component_props.count}项`;
}
};
const rules = [{ validator, message: validatorMessage }];
</script>
<style lang="less" scoped>
.multi-rule-field-page {
.label {
padding: 1rem 1rem 0 1rem;
font-size: 0.9rem;
font-weight: bold;
span {
color: red;
}
}
.rule-box {
font-size: 0.85rem;
margin-left: 1.8rem;
padding-bottom: 0.5rem;
}
}
.rule-wrapper {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.rule-block {
position: relative;
width: 80vw;
height: 80vh;
background-color: #fff;
overflow: scroll;
padding: 1rem;
.close-btn {
position: absolute;
bottom: 1rem;
// transform: translateX(100%);
width: calc(100% - 2rem);
}
}
</style>