当前位置: 首页 > news >正文

四川航天中瑞建设工程有限公司网站百度一下首页官网百度

四川航天中瑞建设工程有限公司网站,百度一下首页官网百度,推荐西安知名的集团门户网站建设公司,网站建设创业uniapp中多选组件很少,故个人简单开发了一个,可简单使用,也可根据个人需求稍微改进 支持的功能 单选多选(默认)限制选择数量默认选中禁用选项 属性说明 属性默认值说明singlefalsetrue为开启单选,否则为…

uniapp中多选组件很少,故个人简单开发了一个,可简单使用,也可根据个人需求稍微改进

支持的功能

  • 单选
  • 多选(默认)
  • 限制选择数量
  • 默认选中
  • 禁用选项

属性说明

属性默认值说明
singlefalsetrue为开启单选,否则为多选
max-可选最多项
maxMessage-超出最多项的提示信息,没有的话则默认清掉最旧的数据,添加当前选择数据
list-数据集合
defaults-默认选中项主键值的集合
keyName-主键名,为空的话则视为list集合为字符串数组,直接将项当作值
disabledKey-禁用属性名,前提是一定要有keyName属性
disabledValue-禁用值,前提是有disabledKey属性

简单使用

<template><view><button @click="onMultiplePick">选择</button><multiple-pick ref="multiplePick" :list="multiplePickList" key-name="id" disabled-key="disabled"disabled-value="1" :defaults="[]" @confirm="onMultiplePickConfirm" :max="2" max-message="已超出最大选项"></multiple-pick></view>
</template><script>export default {data() {return {multiplePickList: []}},methods: {onMultiplePick() {this.$refs.multiplePick.show();},onMultiplePickConfirm(selectedList) {console.log(selectedList);this.$refs.containerMultiplePick.close();}}}
</script>

代码

下面是多选弹窗组件代码,使用了uView的u-popup来作为弹出容器,可根据项目框架自行更改弹出组件。

<template><u-popup :show="pickShow" mode="bottom" :round="10" closeOnClickOverlay @close="onCancel"><view class="multiple-pick-content"><view class="top"><view class="cancel" @tap="onCancel">取消</view><view class="confirm" @tap="onConfirm">确认</view></view><view class="list-container"><view class="item-container"><view class="item" :class="{'selected': isSelected(item), 'disabled': isDisabled(item)}"v-for="(item, index) in list" :key="index" @tap="onClick(item, index)"><view>{{ keyName ? item[keyName] : item }}</view><u-icon v-if="isSelected(item)" name="checkmark" :color="isDisabled(item) ? '#959595' : '#2979ff'"size="18"></u-icon></view></view></view></view></u-popup>
</template><script>
export default {name: "multiplePick",data() {return {pickShow: false,selecteds: []};},props: {/*** 开启单选*/single: Boolean,/*** 可选最多项*/max: Number,/*** 超出最大项提示*/maxMessage: String,/*** 数据集合*/list: Array,/*** 默认选择*/defaults: Array,/*** 主键名,如果没有,则识别为字符串数组*/keyName: String,/*** 禁用属性名,前提是有keyName*/disabledKey: String,/*** 禁用值,前提是有disabledKey*/disabledValue: String},watch: {defaults: {handler(n) {// 不能直接赋值,否则selecteds变化时会改变默认值this.selecteds = n.slice(0, n.length);},immediate: true}},methods: {/*** 当前项是否禁用*/isDisabled(item) {return this.keyName && this.disabledKey && this.disabledValue && item[this.disabledKey] === this.disabledValue;},/*** 当前项是否选中*/isSelected(item) {return this.selecteds.includes(this.keyName ? item[this.keyName] : item);},/*** 打开选择器*/show() {this.pickShow = true;},/*** 关闭选择器*/close() {this.pickShow = false;},/*** 数据项点击监听*/onClick(item, index) {if (this.isDisabled(item)) {// 如果是禁用的,不执行return;}// 获取当前项值const value = this.keyName ? item[this.keyName] : item;if (this.single) {// 开启单选this.selecteds = [];this.selecteds.push(value);} else {// 获取当前项在已选中的集合中的位置const i = this.selecteds.indexOf(value);// 存在则删除,不存在则添加if (i !== -1) {this.selecteds.splice(i, 1);} else {if (this.max && this.selecteds.length >= this.max) {// 如果有最大值且已选超过最大值if (this.maxMessage) {// 有提示提示内容uni.showToast({icon: 'none',title: this.maxMessage});return;}// 否则删掉最旧的数据this.selecteds.shift();}this.selecteds.push(value);}}},/*** 确认按钮事件*/onConfirm() {this.$emit('confirm', this.selecteds);},/*** 取消按钮事件*/onCancel() {// 重新赋值选中的集合this.selecteds = this.defaults.slice(0, this.defaults.length);this.pickShow = false;this.$emit('cancel');}}
}
</script><style lang="scss" scoped>
.multiple-pick-content {padding: 20px;box-sizing: border-box;min-height: 200px;max-height: 50vh;.top {padding: 0 0 10px 0;width: 100%;display: flex;justify-content: space-between;line-height: 32px;.cancel {color: #f43d18;}.confirm {color: #0066ff;}}.list-container {padding: 10px 0px 40px 0px;box-sizing: border-box;max-height: calc(50vh - 42px);height: 100%;overflow-y: auto;}.item-container {width: 100%;.item {padding: 10px 0;box-sizing: border-box;width: 100%;display: flex;justify-content: space-between;&.selected {color: #2979ff !important;}&.disabled {color: #959595 !important;}}}
}
</style>

预览

以下为打包app后的预览截图
在这里插入图片描述
在这里插入图片描述

http://www.hkea.cn/news/727234/

相关文章:

  • 网站不兼容ie6自助建站模板
  • 甘肃网站建设公司百中搜优化软件
  • 国内外贸网站建设公司seo教程 百度网盘
  • 一物一码二维码生成系统最好用的系统优化软件
  • 如何在大网站做外链镇江网站建站
  • 杭州网站建设公司导航短视频营销案例
  • 昆明做网站建设有哪些长尾关键词排名工具
  • 一女被多男做的视频网站网站seo系统
  • 网站建设 青海网站建设找哪家好
  • win7 网站配置优化方案官网电子版
  • 广州seo优化公司排名浙江seo博客
  • 全网推广的方式有哪些抖音seo推荐算法
  • 网站开发开源架构抖音营销软件
  • 自己做的网站能放到网上么青岛seo经理
  • 营业推广策划方案邵阳网站seo
  • 手机网站横向切换kol合作推广
  • 专门做超市海报的网站宁波seo咨询
  • 仿网站上的焦点图在线看seo网站
  • 做网站的业务员艾滋病阻断药有哪些
  • web集团网站建设广告投放平台有哪些
  • 大连做网站建设广告资源对接平台
  • 做网站怎么写工作日志泉州网站seo公司
  • wordpress外链站内打开搜索引擎是什么意思啊
  • 做论坛网站需要什么备案新站seo优化快速上排名
  • 动漫网站html百度网盘搜索
  • 怎么看一个网站什么语言做的宝鸡seo培训
  • 数据库网站建设公司他达拉非片
  • 英文商城网站建设搜索引擎营销的特点
  • 易优建站系统图片百度搜索
  • 网站开发不用框架web网站设计