Commit f8eefbd7 by pangchong

feat: 复选框

parent 94a179cf
<template> <template>
<!-- 全局复选框 -->
<view class="checkbox" :style="getStyle"> <view class="checkbox" :style="getStyle">
<up-checkbox-group <up-checkbox-group
v-model="checkboxValue"
:placement="placement" :placement="placement"
@change="checkboxChange" @change="checkboxChange"
:disabled="disabled" :disabled="disabled"
...@@ -21,7 +23,7 @@ ...@@ -21,7 +23,7 @@
</template> </template>
<script setup> <script setup>
import { computed, ref } from 'vue' import { computed, ref, watch } from 'vue'
import * as dictData from 'mocp/hooks/use-dict/dict-data' import * as dictData from 'mocp/hooks/use-dict/dict-data'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
...@@ -34,7 +36,7 @@ const ps = defineProps({ ...@@ -34,7 +36,7 @@ const ps = defineProps({
}, },
dictkey: { dictkey: {
type: String, type: String,
default: '' default: 'leaderState'
}, },
modelValue: { modelValue: {
type: String, type: String,
...@@ -43,20 +45,7 @@ const ps = defineProps({ ...@@ -43,20 +45,7 @@ const ps = defineProps({
options: { options: {
type: Array, type: Array,
default: () => { default: () => {
return [ return []
{
label: '苹果',
value: 1
},
{
label: '香蕉',
value: 2
},
{
label: '橙子',
value: 3
}
]
} }
}, },
labelField: { labelField: {
...@@ -107,6 +96,7 @@ const ps = defineProps({ ...@@ -107,6 +96,7 @@ const ps = defineProps({
default: false default: false
} }
}) })
const checkboxValue = ref([])
//获取复选框样式 //获取复选框样式
const getStyle = computed(() => { const getStyle = computed(() => {
let checkboxAlign = 'flex-start' let checkboxAlign = 'flex-start'
...@@ -124,7 +114,7 @@ const getCustomStyle = computed(() => { ...@@ -124,7 +114,7 @@ const getCustomStyle = computed(() => {
...ps.customStyle ...ps.customStyle
} }
if (ps.placement == 'row') { if (ps.placement == 'row') {
_style.marginLeft = '32rpx' _style.marginLeft = '16rpx'
} }
return _style return _style
}) })
...@@ -145,6 +135,19 @@ const getColumns = computed(() => { ...@@ -145,6 +135,19 @@ const getColumns = computed(() => {
} }
} }
}) })
//监听设置默认值
watch(
[() => ps.modelValue, () => ps.options],
() => {
ps.modelValue.split(ps.valueSplit).forEach((item) => {
let option = getColumns.value.find((option) => String(option[ps.valueField]) === String(item))
if (option) {
checkboxValue.value.push(option[ps.valueField])
}
})
},
{ immediate: true }
)
const checkboxChange = (value) => { const checkboxChange = (value) => {
es('update:modelValue', value.join(ps.valueSplit)) es('update:modelValue', value.join(ps.valueSplit))
es('change', value.join(ps.valueSplit)) es('change', value.join(ps.valueSplit))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment