Browse Source

优化checkbox组件

ming 3 years ago
parent
commit
f9574bdef2

+ 17 - 2
components/fs-checkbox-group/fs-checkbox-group.vue

@@ -50,7 +50,11 @@ watch(() => props.modelValue, val => {
 
 const checkStrategy = value => {
 	state.children.forEach(item => {
-		item.selected = state.selectedValue.indexOf(item.value) > -1
+		if (typeof item.value === 'object') {
+			item.selected = state.selectedValue.filter(selected => selected.id === item.value.id).length > 0
+		} else{
+			item.selected = state.selectedValue.indexOf(item.value) > -1
+		}
 	})
 }
 const updateChildren = child => {
@@ -58,7 +62,18 @@ const updateChildren = child => {
 	checkStrategy()
 }
 const updateValue = value => {
-	const index = state.selectedValue.indexOf(value)
+	let index = -1
+	
+	if (typeof value === 'object') {
+		state.selectedValue.forEach((item, key) => {
+			if(item.id === value.id) {
+				index = key
+			}
+		})
+	} else{
+		index = state.selectedValue.indexOf(value)
+	}
+	
 	if (state.selectedValue.length < props.max || props.max === -1) {
 		if (index === -1) {
 			state.selectedValue.push(value)

+ 2 - 1
components/fs-checkbox/fs-checkbox.vue

@@ -6,7 +6,7 @@
 		<fs-icon 
 			v-if="icon" 
 			source="out" 
-			:type="icon" 
+			:type="selected ? (selectIcon || icon) : icon" 
 			:colorType="selected ? checkedColorType : 'gray'" 
 			:size="iconSize"
 			:color="checkedColor">
@@ -31,6 +31,7 @@ import { inject, watch, toRefs, ref, computed } from 'vue'
 const props = defineProps({
 	label: String,
 	icon: String,
+	selectIcon: String,
 	iconSize: {
 		type: String,
 		default: '40rpx'

+ 2 - 0
components/fs-loadmore/fs-loadmore.vue

@@ -61,6 +61,8 @@ const refresh = () => {
 	query()
 }
 
+query()
+
 defineExpose({
 	query,
 	refresh,

+ 2 - 1
components/fs-radio/fs-radio.vue

@@ -6,7 +6,7 @@
 	  <fs-icon 
 			v-if="icon" 
 			source="out" 
-			:type="icon" 
+			:type="selected ? (selectIcon || icon) : icon" 
 			:color-type="selected ? checkedColorType : 'gray'" 
 			:size="iconSize" 
 			:color="checkedColor">
@@ -39,6 +39,7 @@ const props = defineProps({
 		required: true
 	},
 	icon: String,
+	selectIcon: String,
 	checkedColor: String,
 	checkedColorType: {
 		type: String,

+ 2 - 2
components/fs-sidebar/fs-sidebar.vue

@@ -3,9 +3,9 @@
 		<view class="fs-side-bar-left">
 			<view 
 				class="fs-side-bar-item line1"
-				:class="{'fs-side-bar-active': activeId === item[valueKey]}"
+				:class="{'fs-side-bar-active': activeId ? (activeId === item[valueKey]) : (index === 0)}"
 				v-for="(item, index) in list"
-				:key="index"
+				:key="item[valueKey]"
 				@click="handleClick(item, index)">
 				{{item.title}}
 			</view>

+ 0 - 2
hooks/useLoadmore/index.js

@@ -10,8 +10,6 @@ export default loadmoreRef => {
 	
 	onMounted(() => {
 		refs = getCurrentInstance().refs
-		console.log(refs);
-		refs[loadmoreRef].query()
 	})
 	
 	onPullDownRefresh(() => {