chore: initialize qiming workspace repository

This commit is contained in:
Codex
2026-05-29 14:22:48 +08:00
commit bfd67a0f2c
10750 changed files with 1885711 additions and 0 deletions

View File

@@ -0,0 +1,253 @@
@import '~@/uni_modules/lime-style/index.scss';
@import '~@/uni_modules/lime-style/functions.scss';
/* #ifdef uniVersion >= 4.75 */
$use-css-var: true !default;
/* #endif */
$checkbox: #{$prefix}-checkbox;
$icon: #{$checkbox}__icon;
$checkbox-icon-size: create-var(checkbox-icon-size, 20px);
$checkbox-font-size: create-var(checkbox-font-size, 16px);
$checkbox-small-icon-size: create-var(checkbox-small-icon-size, 14px);
$checkbox-small-font-size: create-var(checkbox-small-font-size, 15px);
$checkbox-large-icon-size: create-var(checkbox-large-icon-size, 22px);
$checkbox-large-font-size: create-var(checkbox-large-font-size, 18px);
$checkbox-icon-border-width: create-var(checkbox-icon-border-width, 1px);
// $checkbox-icon-border-color: var(--l-checkbox-border-color, $border-color);
$checkbox-icon-border-radius: create-var(checkbox-icon-border-radius, 3px);
$checkbox-icon-bg-color: create-var(checkbox-icon-bg-color, $bg-color-container);
$checkbox-icon-border-color: create-var(checkbox-border-icon-color, $gray-5);
$checkbox-icon-disabled-color: create-var(checkbox-icon-disabled-color, $gray-5);
$checkbox-icon-disabled-bg-color: create-var(checkbox-icon-disabled-bg-color, $gray-1);
$checkbox-icon-checked-color: create-var(checkbox-icon-checked-color, $primary-color);
$checkbox-text-color: create-var(checkbox-text-color, $text-color-1);
$checkbox-icon-text-gap: create-var(checkbox-icon-text-gap, $spacer-xs);
/* #ifdef MP */
:host {
display: inline-flex;
}
/* #endif */
.#{$checkbox} {
/* #ifndef UNI-APP-X */
display: inline-flex;
/* #endif */
flex-direction: row;
align-items: center;
&__icon {
position: relative;
box-sizing: border-box;
width: $checkbox-icon-size;
height: $checkbox-icon-size;
align-self: center;
transition-property: all;
// #ifdef UNI-APP-X && APP
// #ifndef APP-HARMONY || APP-ANDROID
// 鸿蒙加上时间会导致无法描边 安卓会没有尺寸
transition-duration: 200ms;
/* #endif */
/* #endif */
transition-timing-function: cubic-bezier(0.78, 0.14, 0.15, 0.86);
/* #ifndef UNI-APP-X && APP */
&:after {
box-sizing: border-box;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
opacity: 0;
content: "";
transition-property: all;
transition-duration: 200ms;
transition-timing-function: cubic-bezier(0.78, 0.14, 0.15, 0.86);
}
/* #endif */
&--rectangle {
// border-radius: $checkbox-icon-border-radius;
@include border-radius($checkbox-icon-border-radius);
}
&--dot,
&--circle {
border-radius: 99px;
}
&--rectangle,
&--dot,
&--circle{
background-color: $checkbox-icon-bg-color;
border-width: $checkbox-icon-border-width;
border-style: solid;
border-color: $checkbox-icon-border-color;
// border: $checkbox-icon-border-width solid $checkbox-icon-border-color;
}
&--rectangle,&--circle {
/* #ifndef UNI-APP-X && APP */
&:after {
top: 48%;
left: 24%;
display: table;
width: divide(100%, 20) * 7;
height: divide(100%, 20) * 12;
border: calc(#{$checkbox-icon-size} / 7) solid transparent;
border-top: 0;
border-inline-start: 0;
transform: rotate(45deg) scale(0) translate(-50%,-50%);
content: "";
}
/* #endif */
}
&--rectangle#{&}--checked,
&--circle#{&}--checked {
background-color: $checkbox-icon-checked-color;
border-color: $checkbox-icon-checked-color;
/* #ifndef UNI-APP-X && APP */
&:after {
opacity: 1;
transform: rotate(45deg) scale(1) translate(-50%,-50%);
border-color: white;
}
/* #endif */
}
&--rectangle#{&}--indeterminate,
&--circle#{&}--indeterminate{
background-color: $checkbox-icon-checked-color;
border-color: $checkbox-icon-checked-color;
/* #ifndef UNI-APP-X && APP */
&:after {
opacity: 1;
height: 0;
width: 50%;
top: 50%;
left: 50%;
transform: scale(1) translate(-50%,-50%);
border-color: white;
}
/* #endif */
}
&--dot {
/* #ifndef UNI-APP-X && APP */
&:after {
background-color: white;
border-radius: 99px;//$checkbox-icon-border-radius;
transform: scale(0) translate(-50%,-50%);
}
/* #endif */
}
&--dot#{&}--checked{
background-color: $checkbox-icon-checked-color;
border-color: $checkbox-icon-checked-color;
/* #ifndef UNI-APP-X && APP */
&:after{
opacity: 1;
width: 44%;
height: 44%;
transform: scale(1) translate(-50%,-50%);
}
/* #endif */
}
&--dot#{&}--indeterminate {
background-color: $checkbox-icon-checked-color;
border-color: $checkbox-icon-checked-color;
/* #ifndef UNI-APP-X && APP */
&:after {
opacity: 1;
border-radius: 0;
transform: scale(1) translate(-50%,-50%);
width: 50%;
height: calc(#{$checkbox-icon-size} / 7);
}
/* #endif */
}
&--line {
/* #ifndef UNI-APP-X && APP */
&:after {
top: 46%;
left: 0%;
inset-inline-start: 10%;
display: table;
width: divide(100%, 14) * 7;
height: divide(100%, 14) * 12;
border: calc(#{$checkbox-icon-size} / 7) solid transparent;
border-top: 0;
border-inline-start: 0;
transform: rotate(45deg) scale(0) translate(-50%,-50%);
content: "";
transition-timing-function: cubic-bezier(0.78, 0.14, 0.15, 0.86);
}
/* #endif */
}
&--line#{&}--checked {
/* #ifndef UNI-APP-X && APP */
&:after {
opacity: 1;
transform: rotate(45deg) scale(1) translate(-50%,-50%);
border-color: $checkbox-icon-checked-color;
}
/* #endif */
}
&--line#{&}--indeterminate {
/* #ifndef UNI-APP-X && APP */
&:after {
opacity: 1;
height: 0;
left: 50%;
width: 70%;
transform: scale(1) translate(-50%,-50%);
border-color: $checkbox-icon-checked-color;
}
/* #endif */
}
&--rectangle#{&}--disabled,
&--circle#{&}--disabled,
&--dot#{&}--disabled {
border-color: $checkbox-icon-disabled-color;
background-color: $checkbox-icon-disabled-bg-color;
}
&--rectangle#{&}--disabled#{&}--checked,
&--circle#{&}--disabled#{&}--checked,
&--dot#{&}--disabled#{&}--checked,
&--rectangle#{&}--disabled#{&}--indeterminate,
&--circle#{&}--disabled#{&}--indeterminate,
&--dot#{&}--disabled#{&}--indeterminate {
/* #ifndef UNI-APP-X && APP */
&:after {
border-color: $checkbox-icon-disabled-color;
}
/* #endif */
}
&--dot#{&}--disabled#{&}--checked,
&--dot#{&}--disabled#{&}--indeterminate {
/* #ifndef UNI-APP-X && APP */
&:after {
background-color: $checkbox-icon-disabled-color;
}
/* #endif */
}
&--line#{&}--disabled#{&}--checked,
&--line#{&}--disabled#{&}--indeterminate{
/* #ifndef UNI-APP-X && APP */
&:after {
border-color: $checkbox-icon-disabled-color;
}
/* #endif */
}
}
&__label {
padding-left: $checkbox-icon-text-gap;//$spacer-xs;
// padding-right: $spacer-xs;
font-size: $checkbox-font-size;
color: $checkbox-text-color;//$text-color-1;
white-space: nowrap; //ios
&--disabled {
color: $checkbox-icon-disabled-color;
}
}
}

View File

@@ -0,0 +1,424 @@
<template>
<view class="l-checkbox" :class="[rootCasses]" :style="[styles]" @click="handleChange">
<slot name="checkbox" :checked="isChecked" :disabled="isDisabled">
<slot name="icon" :checked="isChecked" :disabled="isDisabled">
<view class="l-checkbox__icon" ref="iconRef"
:class="[
`l-checkbox__icon--${icon}`,
{
'l-checkbox__icon--checked': isChecked,
'l-checkbox__icon--disabled': isDisabled,
'l-checkbox__icon--indeterminate': isIndeterminate,
}
]" :style="[iconStyle]"></view>
</slot>
<text class="l-checkbox__label" :style="[labelStyles]" :class="labelClass" v-if="label!= null || $slots['default'] !=null">
<slot>{{label}}</slot>
</text>
</slot>
</view>
</template>
<script lang="ts" setup>
/**
* Checkbox 复选框组件
* @description 用于在多个选项中进行选择的表单组件,支持单选、全选和不确定态
* <br> 插件类型LCheckboxComponentPublicInstance
* @tutorial https://ext.dcloud.net.cn/plugin?name=lime-checkbox
*
* @property {boolean} defaultChecked 默认选中状态(非受控属性)
* @property {string} label 显示文本(支持插槽)
* @property {boolean} indeterminate 半选状态优先级高于checked
* @property {boolean} disabled 禁用状态覆盖Group设置
* @property {'small' | 'medium' | 'large'} size 组件尺寸
* @value small
* @value medium
* @value large
* @property {string} name 唯一标识符(表单提交使用)
* @property {boolean} checkAll 标记为全选选项需在Group中使用
* @property {string} value 选项值Group模式下必填
* @property {'circle' | 'line' | 'rectangle' | 'dot'} icon 图标样式类型
* @value circle 圆
* @value line 线
* @value rectangle 方
* @value dot 点
* @property {string} fontSize 文本字号支持CSS单位
* @property {string} iconSize 图标尺寸支持CSS单位
* @property {string} checkedColor 选中状态主题色
* @property {string} iconBgColor 图标背景色
* @property {string} iconBorderColor 图标边框色
* @property {string} iconDisabledColor 禁用状态图标颜色
* @property {string} iconDisabledBgColor 禁用状态背景色
* @property {string|object} labelStyle label的样式
* @event {Function} change 状态变化时触发参数CheckboxChangeOptions
*/
import type { CheckboxProps, ManageChildInList, CheckboxStatus, OnCheckedChange, CheckboxChangeOptions, ComputedRef } from './type';
// import { isDarkMode, themeTokens } from '@/uni_modules/lime-style'
const themeVars = inject('limeConfigProviderThemeVars', computed(()=> ({})))
defineSlots<{
checkbox(props : { checked : boolean, disabled: boolean}) : any,
icon(props : { checked : boolean, disabled: boolean}) : any,
default(props : { checked : boolean, disabled: boolean}) : any,
}>()
const name = 'l-checkbox';
const emit = defineEmits(['update:modelValue', 'change']);
const props = withDefaults(defineProps<CheckboxProps>(), {
defaultChecked: false,
indeterminate: false,
disabled: false,
readonly: false,
// checked: null,
// modelValue: null,
size: 'medium',
checkAll: false,
icon: 'rectangle'
})
defineOptions({
mixins: [{
props: {
checked: {
type: [null, Boolean],
default: null,
},
modelValue: {
type: [null, Boolean],
default: null,
},
}
}]
})
const instance = getCurrentInstance()!
const formDisabled = inject<Ref<boolean|null>|null>('formDisabled', null)
const formReadonly = inject<Ref<boolean|null>|null>('formReadonly', null)
const checkboxGroup = inject<LCheckboxGroupComponentPublicInstance|null>('limeCheckboxGroup', null);
const checkboxGroupValue = inject<ComputedRef<any[]>|null>('limeCheckboxGroupValue', null);
const checkboxGroupStatus = inject<ComputedRef<CheckboxStatus>|null>('limeCheckboxGroupStatus', null);
const checkboxGroupCheckedSet = inject<ComputedRef<Set<any>>|null>('limeCheckboxGroupCheckedSet', null);
const manageChildInList = inject<ManageChildInList|null>('limeCheckboxGroupManageChildInList', null);
const onCheckedChange = inject<OnCheckedChange|null>('limeCheckboxGroupOnCheckedChange', null);
if(manageChildInList != null) {
manageChildInList(instance.proxy as LCheckboxComponentPublicInstance, true)
}
const max = computed(():number => checkboxGroup?.max ?? -1)
const _innerChecked = ref(props.defaultChecked)
const innerChecked = computed({
set(value: boolean) {
_innerChecked.value = value
emit('update:modelValue', value)
emit('change', value)
},
get():boolean {
const value = (props.checked ?? props.modelValue)
if(value != null) return value
return _innerChecked.value
}
} as WritableComputedOptions<boolean>)
const isChecked = computed(():boolean=>{
if (props.checkAll) {
const checkAllStatus = checkboxGroupStatus?.value ?? 'uncheck';
return checkAllStatus == 'checked' || checkAllStatus == 'indeterminate'
}
const value = props.value ?? props.name;
if (checkboxGroupCheckedSet != null && value != null) {
return checkboxGroupCheckedSet.value.has(value)
}
return innerChecked.value;
})
const isDisabled = computed(():boolean=>{
if(max.value > -1 && checkboxGroupValue != null) {
return max.value <= checkboxGroupValue.value.length && !isChecked.value;
}
if (props.disabled) return props.disabled;
return formDisabled?.value ?? checkboxGroup?.disabled ?? false;
})
const isReadonly= computed(():boolean=>{
if (props.readonly) return props.readonly;
return formReadonly?.value ?? checkboxGroup?.readonly ?? false;
})
const isIndeterminate = computed(():boolean=>{
if (props.checkAll && checkboxGroupStatus != null) return checkboxGroupStatus.value == 'indeterminate';
return props.indeterminate;
})
const innerIcon = computed(():string => checkboxGroup?.icon ?? props.icon)
const innerSize = computed(():string => checkboxGroup?.size ?? props.size)
const innerIconSize = computed(():string|null => checkboxGroup?.iconSize ?? props.iconSize)
const innerFontSize = computed(():string|null => checkboxGroup?.fontSize ?? props.fontSize)
const innerCheckedColor = computed(():string|null => checkboxGroup?.checkedColor ?? props.checkedColor)
const innerIconBgColor = computed(():string|null => props.iconBgColor ?? checkboxGroup?.iconBgColor)
const innerIconBorderColor = computed(():string|null => props.iconBorderColor ?? checkboxGroup?.iconBorderColor )
const innerIconDisabledColor = computed(():string|null => props.iconDisabledColor ?? checkboxGroup?.iconDisabledColor )
const innerIconDisabledBgColor = computed(():string|null => props.iconDisabledBgColor ?? checkboxGroup?.iconDisabledBgColor)
const rootCasses = computed(():Map<string, boolean>=>{
const cls = new Map<string, boolean>()
cls.set(`${name}--${props.size}`, true)
cls.set(`${name}--disabled`, isDisabled.value)
return cls
})
const iconClasses = computed(():Map<string, boolean>=>{
const cls = new Map<string, boolean>()
cls.set(`${name}__icon--disabled`, isDisabled.value)
cls.set(`${name}__icon--${props.icon}`, true)
// #ifdef APP
cls.set(`${name}__icon--checked`, isChecked.value && innerCheckedColor.value == null)
cls.set(`${name}__icon--indeterminate`, isIndeterminate.value && innerCheckedColor.value == null)
// #endif
// #ifndef APP
cls.set(`${name}__icon--checked`, isChecked.value)
cls.set(`${name}__icon--indeterminate`, isIndeterminate.value)
// #endif
return cls
})
const labelClass = computed(():Map<string, boolean>=>{
const cls = new Map<string, boolean>();
cls.set(`${name}__label--disabled`, isDisabled.value)
return cls
})
const styles = computed(():Map<string, any>=>{
const style = new Map<string, any>();
if(checkboxGroup != null && checkboxGroup.gap != null) {
style.set(checkboxGroup.direction == 'horizontal' ? 'margin-right' : 'margin-bottom', checkboxGroup.gap!)
}
// #ifndef APP
if(innerCheckedColor.value != null) {
style.set('--l-checkbox-icon-checked-color', innerCheckedColor.value!)
}
if(innerIconBorderColor.value != null) {
style.set('--l-checkbox-icon-border-color', innerIconBorderColor.value!)
}
if(innerIconDisabledColor.value != null) {
style.set('--l-checkbox-icon-disabled-color', innerIconDisabledColor.value!)
}
if(innerIconDisabledBgColor.value != null) {
style.set('--l-checkbox-icon-disabled-bg-color', innerIconDisabledBgColor.value!)
}
if(innerFontSize.value != null) {
style.set('--l-checkbox-font-size', innerFontSize.value!)
}
// #endif
return style
})
const iconStyle = computed(():Map<string, any>=>{
const style = new Map<string, any>();
if(innerIconSize.value != null) {
style.set('width', innerIconSize.value!)
style.set('height', innerIconSize.value!)
// #ifndef APP
style.set('--l-checkbox-icon-size', innerIconSize.value!)
// #endif
}
if(innerCheckedColor.value != null) {
// #ifndef APP
style.set('--l-checkbox-icon-checked-color', innerCheckedColor.value!)
// #endif
// #ifdef APP
if(!isDisabled.value && !isChecked.value && ['dot', 'circle', 'rectangle'].includes(innerIcon.value)) {
if(innerIconBgColor.value!=null) {
style.set('background-color', innerIconBgColor.value!)
}
if(innerIconBorderColor.value!=null) {
style.set('border-color', innerIconBorderColor.value!)
}
}
if(isDisabled.value && ['dot', 'circle', 'rectangle'].includes(innerIcon.value)) {
if(innerIconDisabledBgColor.value!=null) {
style.set('background-color', innerIconDisabledBgColor.value!)
}
if(innerIconDisabledColor.value!=null) {
style.set('border-color', innerIconDisabledColor.value!)
}
}
if(isChecked.value && ['dot', 'circle', 'rectangle'].includes(innerIcon.value)) {
style.set('background-color', innerCheckedColor.value!)
style.set('border-color', innerCheckedColor.value!)
}
// #endif
}
return style
})
// const labelStyle = computed(():Map<string, any>=>{
// const style = new Map<string, any>();
// const fontSize = props.fontSize ?? checkboxGroup?.fontSize
// if(fontSize != null) {
// style.set('font-size', fontSize)
// }
// return style
// })
const labelStyles = computed(():any => {
if(typeof props.labelStyle == 'string') {
return `${props.labelStyle};` + (innerIconSize.value != null ? `font-size: ${innerIconSize.value}`: '')
}
if(typeof props.labelStyle == 'object') {
return UTSJSONObject.assign({}, (props.labelStyle??{}) as UTSJSONObject, innerFontSize.value != null ? {'font-size': innerFontSize.value}: {})
}
return {}
})
const handleChange = (e: UniPointerEvent) => {
if (isDisabled.value || isReadonly.value) return;
const value = !isChecked.value;
innerChecked.value = value;
if(onCheckedChange != null) {
onCheckedChange({
checked: value,
checkAll: props.checkAll,
value: props.value ?? props.name //?? instance.uid
})
}
}
// #ifdef APP
const iconRef = ref<UniElement|null>(null)
const update = () => {
if(iconRef.value == null) return
const ctx = iconRef.value!.getDrawableContext()!;
const rect = iconRef.value!.getBoundingClientRect();
// #ifndef APP-HARMONY
const iconSize = rect.width
// #endif
// #ifdef APP-HARMONY
const iconSize = rect.width - 1.5
// #endif
const x = iconSize / 2;
const y = iconSize / 2;
const primaryColor = `${themeVars.value['checkboxIconCheckedColor'] ?? '#3283ff'}`
const disabledColor = `${themeVars.value['checkboxIconDisabledColor'] ?? '#c5c5c5'}`
ctx.reset();
const drawIndeterminate = () => {
ctx.strokeStyle = isDisabled.value
? innerIconDisabledColor.value ?? disabledColor//themes.get(isDarkMode.value ? 'dark' :'light')!
: innerIcon.value == 'line'
? props.checkedColor ?? primaryColor //'#3283ff'
: 'white';
ctx.lineWidth = innerIcon.value == 'line' ? iconSize * 0.16 : iconSize * 0.12;
const width = innerIcon.value == 'line' ? iconSize * 0.8 : iconSize * 0.5;
ctx.beginPath();
ctx.moveTo((iconSize - width) / 2, iconSize * 0.5);
ctx.lineTo((iconSize - width) / 2 + width, iconSize * 0.5);
ctx.stroke();
};
const drawCheckedIcon = () => {
if (isDisabled.value) {
ctx.strokeStyle = innerIconDisabledColor.value ?? disabledColor;
ctx.fillStyle = innerIconDisabledColor.value ?? disabledColor;
} else if (innerIcon.value == 'line') {
ctx.strokeStyle = props.checkedColor ?? primaryColor //'#3283ff';
} else {
ctx.strokeStyle = 'white';
ctx.fillStyle = 'white';
}
ctx.lineWidth = innerIcon.value == 'line' ? iconSize * 0.16 : iconSize * 0.12;
ctx.lineCap = 'round';
if (innerIcon.value == 'circle' || innerIcon.value == 'rectangle') {
ctx.beginPath();
// #ifndef APP-HARMONY
ctx.moveTo(iconSize * 0.2967, iconSize * 0.53);
ctx.lineTo(iconSize * 0.4342, iconSize * 0.6675);
ctx.lineTo(iconSize * 0.7092, iconSize * 0.3925);
// #endif
// #ifdef APP-HARMONY
// 鸿蒙不支持lineCap
ctx.moveTo(iconSize * 0.23, iconSize * 0.45);
ctx.lineTo(iconSize * 0.44, iconSize * 0.6675);
ctx.lineTo(iconSize * 0.73, iconSize * 0.3);
// #endif
ctx.stroke();
} else if (innerIcon.value == 'line') {
ctx.beginPath();
ctx.moveTo(iconSize * 0.10, iconSize * 0.5466);
ctx.lineTo(iconSize * 0.3666, iconSize * 0.8134);
ctx.lineTo(iconSize * 0.90, iconSize * 0.28);
ctx.stroke();
} else if (innerIcon.value == 'dot') {
ctx.beginPath();
ctx.arc(x, y, iconSize * 0.22, 0, Math.PI * 2);
ctx.fill();
}
};
if (isIndeterminate.value) {
drawIndeterminate();
}else if (isChecked.value) {
drawCheckedIcon();
}
ctx.update();
}
const resizeObserver = new UniResizeObserver((entries : Array<UniResizeObserverEntry>) => {
update()
})
const stopWatch = watch(():UniElement|null => iconRef.value, (el:UniElement|null) => {
if(el== null) return
resizeObserver.observe(el)
})
let init = ref(false)
// 在list-view里一开始没有尺寸
watchEffect(()=>{
if(iconRef.value == null) return
if(init.value) {
update()
return
}
iconRef.value?.getBoundingClientRectAsync()?.then(res=>{
requestAnimationFrame(update)
init.value = true
});
})
onBeforeUnmount(()=>{
try {
// 鸿蒙在hbx4.66 由导航返回时会报错
stopWatch()
resizeObserver.disconnect()
} catch(err) {
}
})
// #endif
onBeforeUnmount(()=>{
if(manageChildInList != null) {
manageChildInList(instance.proxy as LCheckboxComponentPublicInstance, false)
}
})
</script>
<style lang="scss">
@import './index-u';
</style>

View File

@@ -0,0 +1,240 @@
<template>
<view class="l-checkbox" :class="[rootCasses]" :style="[styles]" @click="handleChange">
<slot name="checkbox" :checked="isChecked" :disabled="isDisabled">
<slot name="icon" :checked="isChecked" :disabled="isDisabled">
<view class="l-checkbox__icon" ref="iconRef" :class="iconClasses" :style="[iconStyle]"></view>
</slot>
<text class="l-checkbox__label" :style="[labelStyle]" :class="labelClass" v-if="label || $slots['default']">
<slot>{{label}}</slot>
</text>
</slot>
</view>
</template>
<script lang="ts">
//@ts-nocheck
/**
* Checkbox 复选框组件
* @description 用于在多个选项中进行选择的表单组件,支持单选、全选和不确定态
* @tutorial https://ext.dcloud.net.cn/plugin?name=lime-checkbox
*
* @property {boolean} defaultChecked 默认选中状态(非受控属性)
* @property {string} label 显示文本(支持插槽)
* @property {boolean} indeterminate 半选状态优先级高于checked
* @property {boolean} disabled 禁用状态覆盖Group设置
* @property {'small' | 'medium' | 'large'} size 组件尺寸
* @value small
* @value medium
* @value large
* @property {string} name 唯一标识符(表单提交使用)
* @property {boolean} checkAll 标记为全选选项需在Group中使用
* @property {string} value 选项值Group模式下必填
* @property {'circle' | 'line' | 'rectangle' | 'dot'} icon 图标样式类型
* @value circle 圆
* @value line 线
* @value rectangle 方
* @value dot 点
* @property {string} fontSize 文本字号支持CSS单位
* @property {string} iconSize 图标尺寸支持CSS单位
* @property {string} checkedColor 选中状态主题色
* @property {string} iconBgColor 图标背景色
* @property {string} iconBorderColor 图标边框色
* @property {string} iconDisabledColor 禁用状态图标颜色
* @property {string} iconDisabledBgColor 禁用状态背景色
* @property {string|object} labelStyle label的样式
* @event {Function} change 状态变化时触发参数CheckboxChangeOptions
*/
import { type ManageChildInList, type CheckboxStatus, type OnCheckedChange, type CheckboxChangeOptions, type ComputedRef } from './type';
import { computed, defineComponent, ref, inject, getCurrentInstance, onBeforeUnmount } from '@/uni_modules/lime-shared/vue'
import checkboxProps from './props'
const name = 'l-checkbox';
export default defineComponent({
name,
props: checkboxProps,
emits: ['update:modelValue', 'input', 'change'],
setup(props, { emit }) {
const instance = getCurrentInstance()!
const formDisabled = inject<Ref<boolean|null>|null>('formDisabled', null)
const formReadonly = inject<Ref<boolean|null>|null>('formReadonly', null)
const checkboxGroup = inject<LCheckboxGroupComponentPublicInstance|null>('limeCheckboxGroup', null);
const checkboxGroupValue = inject<ComputedRef<any[]>|null>('limeCheckboxGroupValue', null);
const checkboxGroupStatus = inject<ComputedRef<CheckboxStatus>|null>('limeCheckboxGroupStatus', null);
const checkboxGroupCheckedSet = inject<ComputedRef<Set<any>>|null>('limeCheckboxGroupCheckedSet', null);
const manageChildInList = inject<ManageChildInList|null>('limeCheckboxGroupManageChildInList', null);
const onCheckedChange = inject<OnCheckedChange|null>('limeCheckboxGroupOnCheckedChange', null);
if(manageChildInList != null) {
manageChildInList(instance.proxy as LCheckboxComponentPublicInstance, true)
}
const max = computed(():number => checkboxGroup?.max ?? -1)
const _innerChecked = ref(props.checked || props.modelValue || props.value || props.defaultChecked)
const innerChecked = computed({
set(value: boolean) {
_innerChecked.value = value
emit('update:modelValue', value)
emit('change', value)
// #ifdef VUE2
emit('input', value)
// #endif
},
get():boolean {
const value = (props.checked ?? props.modelValue ?? props.value)
if(value != null) return value
return _innerChecked.value
// return props.checked || props.modelValue || props.value || _innerChecked.value
}
} as WritableComputedOptions<boolean>)
const isChecked = computed(():boolean=>{
if (props.checkAll) {
const checkAllStatus = checkboxGroupStatus?.value || 'uncheck';
return checkAllStatus == 'checked' || checkAllStatus == 'indeterminate'
}
const value = props.value || props.name;
if (checkboxGroupCheckedSet && value) {
return checkboxGroupCheckedSet.value.has(value)
}
return innerChecked.value;
})
const isDisabled = computed(():boolean=>{
if(max.value > -1 && checkboxGroupValue) {
return max.value <= checkboxGroupValue.value.length && !isChecked.value;
}
if (props.disabled) return props.disabled;
// return checkboxGroup?.disabled || false;
return formDisabled?.value || checkboxGroup?.disabled || false;
})
const isReadonly= computed(():boolean=>{
if (props.readonly) return props.readonly;
return formReadonly?.value ?? checkboxGroup?.readonly ?? false;
})
const isIndeterminate = computed(():boolean=>{
if (props.checkAll && checkboxGroupStatus) return checkboxGroupStatus.value == 'indeterminate';
return props.indeterminate;
})
const innerIcon = computed(():string => checkboxGroup?.icon || props.icon)
const innerSize = computed(():string => checkboxGroup?.size || props.size)
const innerIconSize = computed(():string|null => checkboxGroup?.iconSize || props.iconSize)
const innerFontSize = computed(():string|null => checkboxGroup?.fontSize || props.fontSize)
const innerCheckedColor = computed(():string|null => checkboxGroup?.checkedColor || props.checkedColor)
const innerIconBgColor = computed(():string => props.iconBgColor || checkboxGroup?.iconBgColor)
const innerIconBorderColor = computed(():string => props.iconBorderColor || checkboxGroup?.iconBorderColor)
const innerIconDisabledColor = computed(():string => props.iconDisabledColor || checkboxGroup?.iconDisabledColor)
const innerIconDisabledBgColor = computed(():string => props.iconDisabledBgColor || checkboxGroup?.iconDisabledBgColor)
const rootCasses = computed(()=>{
const cls = [`${name}--${props.size}`]
if(isDisabled.value) {
cls.push(`${name}--disabled`)
}
return cls.join(' ')
})
const iconClasses = computed(()=>{
const cls = [`${name}__icon--${props.icon}`]
if(isChecked.value) {
cls.push(`${name}__icon--checked`)
}
if(isDisabled.value) {
cls.push(`${name}__icon--disabled`)
}
if(isIndeterminate.value) {
cls.push(`${name}__icon--indeterminate`)
}
return cls.join(' ')
})
const labelClass = computed(()=>{
const cls = [];
if(isDisabled.value) {
cls.push(`${name}__label--disabled`)
}
return cls.join(' ')
})
const styles = computed(()=>{
const style:Record<string, any> = {};
if(checkboxGroup && checkboxGroup.gap) {
style[checkboxGroup.direction == 'horizontal' ? 'margin-right' : 'margin-bottom'] = checkboxGroup.gap!
}
if(innerCheckedColor.value) {
style['--l-checkbox-icon-checked-color'] = innerCheckedColor.value!
}
if(innerIconBorderColor.value) {
style['--l-checkbox-icon-border-color'] = innerIconBorderColor.value!
}
if(innerIconDisabledColor.value) {
style['--l-checkbox-icon-disabled-color'] = innerIconDisabledColor.value!
}
if(innerIconDisabledBgColor.value) {
style['--l-checkbox-icon-disabled-bg-color'] = innerIconDisabledBgColor.value!
}
if(innerFontSize.value) {
style['--l-checkbox-font-size'] = innerFontSize.value!
}
return style
})
const iconStyle = computed(()=>{
const style:Record<string, any> = {}
if(innerIconSize.value) {
style['width'] = innerIconSize.value!
style['height'] = innerIconSize.value!
style['--l-checkbox-icon-size'] = innerIconSize.value!
}
return style
})
// const labelStyle = computed(()=>{
// const style:Record<string, any> = {}
// const fontSize = props.fontSize || checkboxGroup?.fontSize
// if(fontSize) {
// style['font-size'] = fontSize
// }
// return style
// })
const handleChange = (e: UniPointerEvent) => {
if (isDisabled.value || isReadonly.value) return;
const value = !isChecked.value;
innerChecked.value = value;
if(onCheckedChange) {
onCheckedChange({
checked: value,
checkAll: props.checkAll,
value: props.value || props.name //?? instance.uid
})
}
}
onBeforeUnmount(()=>{
if(manageChildInList) {
manageChildInList(instance.proxy as LCheckboxComponentPublicInstance, false)
}
})
return {
isChecked,
isDisabled,
rootCasses,
iconClasses,
labelClass,
styles,
iconStyle,
// labelStyle,
handleChange
}
}
})
</script>
<style lang="scss">
@import './index-u';
</style>

View File

@@ -0,0 +1,87 @@
//@ts-nocheck
export default {
checked: {
type: Boolean,
default: undefined,
},
modelValue: {
type: Boolean,
default: undefined,
},
/** 是否选中,非受控属性 */
defaultChecked: {
type: Boolean,
default: false,
},
/** 是否禁用组件。如果父组件存在 CheckboxGroup默认值由 CheckboxGroup.disabled 控制。Checkbox.disabled 优先级高于 CheckboxGroup.disabled */
disabled: {
type: Boolean,
default: false,
},
readonly: {
type: Boolean,
default: false,
},
/** 主文案 */
label: {
type: String,
default: null
},
indeterminate: {
type: Boolean,
default: false
},
name: {
type: String,
default: null
},
/** 用于标识是否为「全选选项」。单独使用无效,需在 CheckboxGroup 中使用 */
checkAll: {
type: Boolean,
default: false,
},
/** 多选框的值 */
value: {
type: [String, Number, Boolean],
default: null
},
checkedColor: {
type: String,
default: null
},
iconBgColor: {
type: String,
default: null
},
iconBorderColor: {
type: String,
default: null
},
iconDisabledColor: {
type: String,
default: null
},
iconDisabledBgColor: {
type: String,
default: null
},
icon: {
type: String,
default: 'rectangle'
}, //?: 'circle' | 'line' | 'dot';
size: {
type: String,
default: 'medium'
}, //?: 'small' | 'medium' | 'large';
iconSize: {
type: String,
defalut: null
},
fontSize: {
type: String,
defalut: null
},
labelStyle: {
type: [String, Object]
}
}

View File

@@ -0,0 +1,72 @@
//@ts-nocheck
export type CheckboxProps = {
/**
* 是否选中
*/
// checked ?: boolean;
/**
* 是否选中,非受控属性
*/
defaultChecked: boolean;
/**
* 是否选中
*/
// modelValue ?: boolean;
/**
* 主文案
*/
label ?: string;
/**
* 是否为半选
*/
indeterminate: boolean;
/**
* 是否禁用组件。如果父组件存在 CheckboxGroup默认值由 CheckboxGroup.disabled 控制。Checkbox.disabled 优先级高于 CheckboxGroup.disabled
*/
disabled : boolean;
/**
* 只读
*/
readonly : boolean;
size : 'small' | 'medium' | 'large'
/**
* 标识符,通常为一个唯一的字符串或数字
*/
name ?: any //string,
/**
* 用于标识是否为「全选选项」。单独使用无效,需在 CheckboxGroup 中使用
*/
checkAll : boolean
/**
* 多选框的值
*/
value?: any; // string | number
icon: 'circle' | 'line' | 'rectangle' | 'dot';
fontSize?: string;
iconSize?: string;
checkedColor?: string;
iconBgColor?: string;
iconBorderColor?: string;
iconDisabledColor?: string;
iconDisabledBgColor?: string;
labelStyle?: string | UTSJSONObject
}
export type ManageChildInList = (child: LCheckboxComponentPublicInstance, shouldAdd: boolean) => void;
export type CheckboxStatus = 'checked' | 'uncheck' | 'indeterminate';
export type CheckboxChangeOptions = {
checked : boolean,
checkAll : boolean,
value?: any
};
export type OnCheckedChange = (options: CheckboxChangeOptions) => void
// #ifndef APP-ANDROID || APP-IOS
export type {ComputedRef} from 'vue';
// #endif
// #ifdef APP-ANDROID || APP-IOS
export type ComputedRef<T> = ComputedRefImpl<T>;
// export type WritableComputedRef<T> = ComputedRefImpl<T>;
// #endif