From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001 From: spring <2396852758@qq.com> Date: 星期三, 28 五月 2025 16:48:52 +0800 Subject: [PATCH] 初始化项目 --- components/js-checkbox/js-checkbox.vue | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 100 insertions(+), 0 deletions(-) diff --git a/components/js-checkbox/js-checkbox.vue b/components/js-checkbox/js-checkbox.vue new file mode 100644 index 0000000..de90bdb --- /dev/null +++ b/components/js-checkbox/js-checkbox.vue @@ -0,0 +1,100 @@ +<template> + <view class="u-flex-1"> + <u-checkbox-group :disabled="disabled" @change="change"> + <u-checkbox v-model="item.checked" v-for="(item, index) in options.items" :key="index" + :name="item[itemValue]">{{item[itemLabel]}}</u-checkbox> + </u-checkbox-group> + </view> +</template> +<script> +/** + * 澶嶉�夋缁勪欢 {{item[itemLabel]}} + * @property {Object} value 鐢ㄤ簬鍙屽悜缁戝畾閫夋嫨妗嗙殑鍊硷紝杩斿洖閫夋嫨妗嗙殑 Value + * @property {Boolean} disabled 鏄惁绂佺敤妯″紡锛屾槸鍚﹀彧璇绘ā寮� + * @property {String} dictType 瀛楀吀绫诲瀷锛屼粠瀛楀吀閲岃幏鍙栵紝鑷姩璁剧疆 items銆乮temLabel銆乮temValue + * @property {String} items 鍒楄〃鏁版嵁锛屽彲鎺ュ彈瀵硅薄闆嗗悎锛屽锛歔{name: '鏄�', value: '鍚�'}] + * @property {String} itemLabel 鎸囧畾鍒楄〃鏁版嵁涓殑浠�涔堝睘鎬у悕浣滀负 option 鐨勬爣绛惧悕锛屽 name + * @property {String} itemValue 鎸囧畾鍒楄〃鏁版嵁涓殑浠�涔堝睘鎬у悕浣滀负 option 鐨� value 鍊硷紝濡� value + * @example <js-select v-model="model.type" dict-type="sys_yes_no"></js-select> + * @description Copyright (c) 2013-Now http://jeesite.com All rights reserved. + * @author ThinkGem + * @version 2021-3-11 + */ +export default { + props: { + value: { + type: String, + default: '' + }, + disabled: { + type: Boolean, + default: false + }, + dictType: { + type: String, + default: '' + }, + items: { + type: Array, + default() { + return []; + } + }, + itemLabel: { + type: String, + default: 'label' + }, + itemValue: { + type: String, + default: 'value' + } + }, + data() { + return { + options: { + value: (this.value && this.value.split(',')) || [], + items: this.items + } + }; + }, + watch: { + value(val, oldVal) { + this.options.value = (val && val.split(',')) || []; + this.loadData(); + }, + items(val, oldVal){ + this.options.items = val; + this.loadData(); + } + }, + methods: { + loadData(){ + if (this.dictType != ''){ + this.$u.api.dictData({dictType: this.dictType}).then(res => { + // this.options.items = res; + this.selectValue(res.data); + }); + }else{ + // this.options.items = this.items; + this.selectValue(this.items); + } + }, + selectValue(items){ + // 寰俊灏忕▼搴忥紝闇�瑕佸欢杩熶笅锛屽惁鍒欒幏鍙栦笉 value 瀵艰嚧鏃犳硶鍥炴樉鏁版嵁 + this.$nextTick(() => { + let vals = this.options.value; + for (let i in items){ + this.$set(items[i],'checked',vals.includes(items[i][this.itemValue])) + } + this.options.items = items; + }); + }, + change(val, name){ + this.$emit('input', (val && val.join(',')) || ''); + } + } +} +</script> +<style lang="scss" scoped> + +</style> -- Gitblit v1.9.3