| | |
| | | /** |
| | | * CSelect |
| | | * 下拉选择组件,用于在表单中提供选项选择功能 |
| | | * 支持两种选择模式:下拉选择模式和跳转页面选择模式 |
| | | * 可配置为只读模式,并支持自定义占位文本 |
| | | * @author Tevin |
| | | */ |
| | | |
| | |
| | | <script> |
| | | import Taro from '@tarojs/taro'; |
| | | import { AtInput } from 'taro-ui-vue'; |
| | | import { $pagePoster } from '@components/common/PagePoster'; |
| | | import './cSelect.scss'; |
| | | |
| | | export default { |
| | |
| | | type: Boolean, |
| | | default: false, |
| | | }, |
| | | // 开启选择菜单跳转选择页面模式,并指定功能页面,url or 'on' |
| | | // url 模式已经废弃,即将删除代码,请勿再使用 |
| | | // 开启选择菜单跳转选择页面模式,值为 'on' |
| | | selectByPage: String, |
| | | // 页面跳转URL模式下,选择完成后的回调 |
| | | onSelectFromPage: Function, |
| | | // 页面跳转on模式下,发起选择的回调 |
| | | onOpenSelectorPage: Function, |
| | | }, |
| | |
| | | this.onOpenSelectorPage && this.onOpenSelectorPage(); |
| | | return; |
| | | } |
| | | // 页面跳转URL模式,已废弃,即将删除代码 |
| | | console.warn('CSelect:警告,url跳转已废弃,即将删除代码,请勿使用!'); |
| | | let url = this.selectByPage; |
| | | if (this.selectByPage.indexOf('?') > 0) { |
| | | url += '&mode=CSelect'; |
| | | } else { |
| | | url += '?mode=CSelect'; |
| | | } |
| | | 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 }); |
| | | // 页面跳转URL模式已废弃 |
| | | console.warn('CSelect:警告,url跳转已废弃,无法再使用!'); |
| | | }, |
| | | }, |
| | | mounted() { |
| | | if (this.selectByPage && this.selectByPage !== 'on') { |
| | | // 页面跳转URL模式已废弃 |
| | | console.warn('CSelect:警告,url跳转已废弃,无法再使用!'); |
| | | } |
| | | }, |
| | | }; |
| | | </script> |