From 3b03f87a02458f719e2eb4bf112a13441b427d14 Mon Sep 17 00:00:00 2001 From: ‘chensiAb’ <‘chenchenco03@163.com’> Date: Tue, 25 Mar 2025 13:54:34 +0800 Subject: [PATCH] Merge branch 'master' of ssh://dev.zhiheiot.com:29418/mob-components --- forms/select/CSelect.vue | 77 ++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 33 deletions(-) diff --git a/forms/select/CSelect.vue b/forms/select/CSelect.vue index 9270195..aae68bb 100644 --- a/forms/select/CSelect.vue +++ b/forms/select/CSelect.vue @@ -1,10 +1,16 @@ /** * CSelect + * 下拉选择组件,用于在表单中提供选项选择功能 + * 支持两种选择模式:下拉选择模式和跳转页面选择模式 + * 可配置为只读模式,并支持自定义占位文本 * @author Tevin */ <template> - <view class="c-select"> + <view + class="c-select" + :class="readOnly?'read-only':''" + > <!-- 下拉选择模式 --> <view v-if="!selectByPage" @@ -28,7 +34,10 @@ :placeholder="placeholder" :value="selected" > - <view class="at-icon at-icon-chevron-right" /> + <view + v-show="!readOnly" + class="at-icon at-icon-chevron-right" + /> </AtInput> </picker> <view class="c-select-slot"> @@ -37,8 +46,8 @@ </view> <!-- 跳转页面模式 --> <view - v-else-if="selectByPage.length > 5" - @tap="evt => onGoToSelectorPage()" + v-else-if="selectByPage.length > 5 || selectByPage === 'on'" + @tap="evt => onGoSelectorPage()" > <AtInput :name="itemRes.name" @@ -47,9 +56,12 @@ :disabled="itemRes.disabled" :error="itemRes.error" :placeholder="placeholder" - :value="choose.name" + :value="choose.name || selected" > - <view class="at-icon at-icon-chevron-right" /> + <view + v-show="!readOnly" + class="at-icon at-icon-chevron-right" + /> </AtInput> </view> </view> @@ -58,7 +70,6 @@ <script> import Taro from '@tarojs/taro'; import { AtInput } from 'taro-ui-vue'; -import { $pagePoster } from '@components/common/PagePoster'; import './cSelect.scss'; export default { @@ -73,10 +84,15 @@ options: Array, // 占位提示 placeholder: String, - // 开启选择菜单跳转选择页面模式,并指定功能页面 + // 只读模式 + readOnly: { + type: Boolean, + default: false, + }, + // 开启选择菜单跳转选择页面模式,值为 'on' selectByPage: String, - // 页面模式下,选择完成后的回调 - onSelectFromPage: Function, + // 页面跳转on模式下,发起选择的回调 + onOpenSelectorPage: Function, }, data() { return { @@ -111,32 +127,27 @@ }, methods: { handleChange(evt) { - const item = this.options[evt.value]; - this.itemRes.onChange(item[this.optionKey]); - }, - onGoToSelectorPage() { - let url = this.selectByPage; - if (this.selectByPage.indexOf('?') > 0) { - url += '&mode=CSelect'; + if (typeof this.optionKey === 'undefined') { + this.itemRes.onChange(); } else { - url += '?mode=CSelect'; + const item = this.options[evt.value]; + this.itemRes.onChange(item[this.optionKey]); } - if (this._eventor) { - // 销毁上次事件收发器 - this._eventor.destroy(); - } - this._eventor = $pagePoster.createEventor(); - this._eventor.on('@linked', () => { - this._eventor.emit('lastValue', this.choose.value); - }); - this._eventor.on('selected', data => { - this.choose.name = data.name; - this.choose.value = data.value; - this.itemRes.onChange(data.value); - this.onSelectFromPage && this.onSelectFromPage(data.value); - }); - Taro.navigateTo({ url: url + '&eventorId=' + this._eventor.id }); }, + onGoSelectorPage() { + if (this.selectByPage === 'on') { + this.onOpenSelectorPage && this.onOpenSelectorPage(); + return; + } + // 页面跳转URL模式已废弃 + console.warn('CSelect:警告,url跳转已废弃,无法再使用!'); + }, + }, + mounted() { + if (this.selectByPage && this.selectByPage !== 'on') { + // 页面跳转URL模式已废弃 + console.warn('CSelect:警告,url跳转已废弃,无法再使用!'); + } }, }; </script> \ No newline at end of file -- Gitblit v1.9.1