Explorar o código

feat:选择角色

zhanghui hai 1 ano
pai
achega
d8d8c13589

+ 10 - 0
pages/index/attach/attach.vue

@@ -37,6 +37,16 @@
 			</view>
 		</view>
 
+
+		<view class="flex-row">
+			<view class="flex-col justify-center">
+				<text class="roleSelectLabel">选择规则:</text>
+			</view>
+			<view class="roleSelect">
+				<uni-data-select v-model="value" :localdata="ruleList" @change="selectChange" :clear="false"></uni-data-select>
+			</view>
+		</view>
+
 		<view class="flex-row justify-center">
 			<view class="qrView" @click="qrCodePopup">
 				<uv-qrcode ref="qrcode" size="600rpx" :value="qrcodeUrl" :options="options"></uv-qrcode>

+ 12 - 0
pages/index/attach/index.rpx.css

@@ -52,3 +52,15 @@
     background: #4cd964;
     position: relative;
 }
+.roleSelect{
+    background: white;
+    width: 300rpx;
+    border-radius: 10rpx;
+    margin-top: 40rpx;
+}
+.roleSelectLabel{
+    font-size: 30rpx;
+    color: #666666;
+    margin-left: 55rpx;
+    margin-top: 40rpx;
+}

+ 12 - 0
pages/index/manager/index.rpx.css

@@ -52,3 +52,15 @@
     background: #4cd964;
     position: relative;
 }
+.roleSelect{
+    background: white;
+    width: 300rpx;
+    border-radius: 10rpx;
+    margin-top: 40rpx;
+}
+.roleSelectLabel{
+    font-size: 30rpx;
+    color: #666666;
+    margin-left: 55rpx;
+    margin-top: 40rpx;
+}

+ 15 - 3
pages/index/manager/manager.vue

@@ -47,8 +47,12 @@
 		</view>
 
 		<view class="flex-row">
-			<text>选择角色:</text>
-			<text v-for="i in roleList">{{i.name}}</text>
+			<view class="flex-col justify-center">
+				<text class="roleSelectLabel">选择角色:</text>
+			</view>
+			<view class="roleSelect">
+				<uni-data-select v-model="value" :localdata="roleList" @change="selectChange" :clear="false"></uni-data-select>
+			</view>
 		</view>
 
 		<view class="flex-row justify-center">
@@ -93,7 +97,8 @@
 					foregroundImageSrc: '/static/logo.png'
 				},
 				homeStaticsData:{},
-				roleList:[]
+				value:0,
+				roleList:[],
 			}
 		},
 		created() {
@@ -103,6 +108,9 @@
 			this.getRoleList()
 		},
 		methods: {
+			selectChange(e){
+				console.log(e)
+			},
 			formatDate() {
 				this.qrCreateTime = commonUtils.formatDate(new Date())
 			},
@@ -123,6 +131,10 @@
 				this.$api.service.getRoleList().then(res=>{
 					console.log('获取角色列表',res)
 					this.roleList = res.data.data
+					for (let i = 0;i<this.roleList.length;i++){
+						this.roleList[i].value = i;
+						this.roleList[i].text = this.roleList[i].name
+					}
 				})
 			},
 

+ 2 - 0
uni_modules/uni-data-select/changelog.md

@@ -1,3 +1,5 @@
+## 1.0.8(2024-03-28)
+- 修复 在vue2下:style动态绑定导致编译失败的bug
 ## 1.0.7(2024-01-20)
 - 修复 长文本回显超过容器的bug,超过容器部分显示省略号
 ## 1.0.6(2023-04-12)

+ 69 - 35
uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue

@@ -6,16 +6,16 @@
 				<view class="uni-select__input-box" @click="toggleSelector">
 					<view v-if="current" class="uni-select__input-text">{{textShow}}</view>
 					<view v-else class="uni-select__input-text uni-select__input-placeholder">{{typePlaceholder}}</view>
-					<view v-if="current && clear && !disabled" @click.stop="clearVal" >
-						<uni-icons type="clear" color="#c0c4cc" size="24"/>
+					<view v-if="current && clear && !disabled" @click.stop="clearVal">
+						<uni-icons type="clear" color="#c0c4cc" size="24" />
 					</view>
 					<view v-else>
 						<uni-icons :type="showSelector? 'top' : 'bottom'" size="14" color="#999" />
 					</view>
 				</view>
 				<view class="uni-select--mask" v-if="showSelector" @click="toggleSelector" />
-				<view class="uni-select__selector" v-if="showSelector">
-					<view class="uni-popper__arrow"></view>
+				<view class="uni-select__selector" :style="getOffsetByPlacement" v-if="showSelector">
+					<view :class="placement=='bottom'?'uni-popper__arrow_bottom':'uni-popper__arrow_top'"></view>
 					<scroll-view scroll-y="true" class="uni-select__selector-scroll">
 						<view class="uni-select__selector-empty" v-if="mixinDatacomResData.length === 0">
 							<text>{{emptyTips}}</text>
@@ -43,6 +43,9 @@
 	 * @property {String} label 左侧标题
 	 * @property {String} placeholder 输入框的提示文字
 	 * @property {Boolean} disabled 是否禁用
+	 * @property {String} placement 弹出位置
+	 * 	@value top   		顶部弹出
+	 * 	@value bottom		底部弹出(default)
 	 * @event {Function} change  选中发生变化触发
 	 */
 
@@ -93,6 +96,10 @@
 				type: String,
 				default: ''
 			},
+			placement: {
+				type: String,
+				default: 'bottom'
+			}
 		},
 		data() {
 			return {
@@ -125,7 +132,7 @@
 					common + placeholder :
 					common
 			},
-			valueCom(){
+			valueCom() {
 				// #ifdef VUE3
 				return this.modelValue;
 				// #endif
@@ -133,13 +140,21 @@
 				return this.value;
 				// #endif
 			},
-			textShow(){
+			textShow() {
 				// 长文本显示
 				let text = this.current;
 				if (text.length > 10) {
 					return text.slice(0, 25) + '...';
 				}
 				return text;
+			},
+			getOffsetByPlacement() {
+				switch (this.placement) {
+					case 'top':
+						return "bottom:calc(100% + 12px);";
+					case 'bottom':
+						return "top:calc(100% + 12px);";
+				}
 			}
 		},
 
@@ -166,7 +181,7 @@
 
 		},
 		methods: {
-			debounce(fn, time = 100){
+			debounce(fn, time = 100) {
 				let timer = null
 				return function(...args) {
 					if (timer) clearTimeout(timer)
@@ -176,11 +191,11 @@
 				}
 			},
 			// 执行数据库查询
-			query(){
+			query() {
 				this.mixinDatacomEasyGet();
 			},
 			// 监听查询条件变更事件
-			onMixinDatacomPropsChange(){
+			onMixinDatacomPropsChange() {
 				if (this.collection) {
 					this.debounceGet();
 				}
@@ -203,9 +218,9 @@
 						}
 						defValue = defItem
 					}
-          if (defValue || defValue === 0) {
-					  this.emit(defValue)
-          }
+					if (defValue || defValue === 0) {
+						this.emit(defValue)
+					}
 				}
 				const def = this.mixinDatacomResData.find(item => item.value === defValue)
 				this.current = def ? this.formatItemName(def) : ''
@@ -268,7 +283,7 @@
 					let str = "";
 					str = this.format;
 					for (let key in item) {
-						str = str.replace(new RegExp(`{${key}}`,"g"),item[key]);
+						str = str.replace(new RegExp(`{${key}}`, "g"), item[key]);
 					}
 					return str;
 				} else {
@@ -282,26 +297,26 @@
 				}
 			},
 			// 获取当前加载的数据
-			getLoadData(){
+			getLoadData() {
 				return this.mixinDatacomResData;
 			},
 			// 获取当前缓存key
-			getCurrentCacheKey(){
+			getCurrentCacheKey() {
 				return this.collection;
 			},
 			// 获取缓存
-			getCache(name=this.getCurrentCacheKey()){
+			getCache(name = this.getCurrentCacheKey()) {
 				let cacheData = uni.getStorageSync(this.cacheKey) || {};
 				return cacheData[name];
 			},
 			// 设置缓存
-			setCache(value, name=this.getCurrentCacheKey()){
+			setCache(value, name = this.getCurrentCacheKey()) {
 				let cacheData = uni.getStorageSync(this.cacheKey) || {};
 				cacheData[name] = value;
 				uni.setStorageSync(this.cacheKey, cacheData);
 			},
 			// 删除缓存
-			removeCache(name=this.getCurrentCacheKey()){
+			removeCache(name = this.getCurrentCacheKey()) {
 				let cacheData = uni.getStorageSync(this.cacheKey) || {};
 				delete cacheData[name];
 				uni.setStorageSync(this.cacheKey, cacheData);
@@ -316,7 +331,6 @@
 	$uni-secondary-color: #909399 !default;
 	$uni-border-3: #e5e5e5;
 
-
 	/* #ifndef APP-NVUE */
 	@media screen and (max-width: 500px) {
 		.hide-on-phone {
@@ -332,8 +346,7 @@
 		/* #ifdef H5 */
 		cursor: pointer;
 		/* #endif */
-		/*width: 100%;*/
-		width: 500rpx;
+		width: 100%;
 		flex: 1;
 		box-sizing: border-box;
 	}
@@ -359,7 +372,7 @@
 
 	.uni-select {
 		font-size: 14px;
-		/*<!--border: 1px solid $uni-border-3;-->*/
+		border: 1px solid $uni-border-3;
 		box-sizing: border-box;
 		border-radius: 4px;
 		padding: 0 5px;
@@ -371,7 +384,7 @@
 		/* #endif */
 		flex-direction: row;
 		align-items: center;
-		/*<!--border-bottom: solid 1px $uni-border-3;-->*/
+		border-bottom: solid 1px $uni-border-3;
 		width: 100%;
 		flex: 1;
 		height: 35px;
@@ -418,7 +431,6 @@
 		box-sizing: border-box;
 		/* #endif */
 		position: absolute;
-		top: calc(100% + 12px);
 		left: 0;
 		width: 100%;
 		background-color: #FFFFFF;
@@ -442,6 +454,7 @@
 			max-height: 600px;
 		}
 	}
+
 	/* #endif */
 
 	.uni-select__selector-empty,
@@ -474,18 +487,21 @@
 	}
 
 	/* picker 弹出层通用的指示小三角 */
-	.uni-popper__arrow,
-	.uni-popper__arrow::after {
-		position: absolute;
-		display: block;
-		width: 0;
-		height: 0;
-		border-color: transparent;
-		border-style: solid;
-		border-width: 6px;
+	.uni-popper__arrow_bottom,
+	.uni-popper__arrow_bottom::after,
+	.uni-popper__arrow_top,
+	.uni-popper__arrow_top::after,
+	{
+	position: absolute;
+	display: block;
+	width: 0;
+	height: 0;
+	border-color: transparent;
+	border-style: solid;
+	border-width: 6px;
 	}
 
-	.uni-popper__arrow {
+	.uni-popper__arrow_bottom {
 		filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
 		top: -6px;
 		left: 10%;
@@ -494,7 +510,7 @@
 		border-bottom-color: #EBEEF5;
 	}
 
-	.uni-popper__arrow::after {
+	.uni-popper__arrow_bottom::after {
 		content: " ";
 		top: 1px;
 		margin-left: -6px;
@@ -502,6 +518,24 @@
 		border-bottom-color: #fff;
 	}
 
+	.uni-popper__arrow_top {
+		filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
+		bottom: -6px;
+		left: 10%;
+		margin-right: 3px;
+		border-bottom-width: 0;
+		border-top-color: #EBEEF5;
+	}
+
+	.uni-popper__arrow_top::after {
+		content: " ";
+		bottom: 1px;
+		margin-left: -6px;
+		border-bottom-width: 0;
+		border-top-color: #fff;
+	}
+
+
 	.uni-select__input-text {
 		// width: 280px;
 		width: 100%;

+ 3 - 2
uni_modules/uni-data-select/package.json

@@ -1,7 +1,7 @@
 {
   "id": "uni-data-select",
   "displayName": "uni-data-select 下拉框选择器",
-  "version": "1.0.7",
+  "version": "1.0.8",
   "description": "通过数据驱动的下拉框选择器",
   "keywords": [
     "uni-ui",
@@ -43,7 +43,8 @@
     "platforms": {
       "cloud": {
         "tcb": "y",
-        "aliyun": "y"
+        "aliyun": "y",
+        "alipay": "n"
       },
       "client": {
         "App": {