mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	uView版本升级到2.0.34
This commit is contained in:
		| @@ -1,146 +1,127 @@ | ||||
| <template> | ||||
| 	<view class="u-drawdown-item"> | ||||
| 		<u-overlay | ||||
| 			customStyle="top: 126px" | ||||
| 			:show="show" | ||||
| 			:closeOnClickOverlay="closeOnClickOverlay" | ||||
| 			@click="overlayClick" | ||||
| 		></u-overlay> | ||||
| 		<view | ||||
| 			class="u-drawdown-item__content" | ||||
| 			:style="[style]" | ||||
| 			:animation="animationData" | ||||
| 			ref="animation" | ||||
| 		> | ||||
| 			<slot /> | ||||
| 		</view> | ||||
| 	</view> | ||||
|   <view class="u-drawdown"> | ||||
|     <view | ||||
|       class="u-dropdown__menu" | ||||
|       :style="{ | ||||
| 				height: $u.addUnit(height) | ||||
| 			}" | ||||
|       ref="u-dropdown__menu" | ||||
|     > | ||||
|       <view | ||||
|         class="u-dropdown__menu__item" | ||||
|         v-for="(item, index) in menuList" | ||||
|         :key="index" | ||||
|         @tap.stop="clickHandler(item, index)" | ||||
|       > | ||||
|         <view class="u-dropdown__menu__item__content"> | ||||
|           <text | ||||
|             class="u-dropdown__menu__item__content__text" | ||||
|             :style="[index === current ? activeStyle : inactiveStyle]" | ||||
|           >{{item.title}}</text> | ||||
|           <view | ||||
|             class="u-dropdown__menu__item__content__arrow" | ||||
|             :class="[index === current && 'u-dropdown__menu__item__content__arrow--rotate']" | ||||
|           > | ||||
|             <u-icon | ||||
|               :name="menuIcon" | ||||
|               :size="$u.addUnit(menuIconSize)" | ||||
|             ></u-icon> | ||||
|           </view> | ||||
|         </view> | ||||
|       </view> | ||||
|     </view> | ||||
|     <view class="u-dropdown__content"> | ||||
|       <slot /> | ||||
|     </view> | ||||
|   </view> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| 	// #ifdef APP-NVUE | ||||
| 	const animation = uni.requireNativePlugin('animation') | ||||
| 	const dom = uni.requireNativePlugin('dom') | ||||
| 	// #endif | ||||
| 	import props from './props.js'; | ||||
| 	/** | ||||
| 	 * Drawdownitem | ||||
| 	 * @description  | ||||
| 	 * @tutorial url | ||||
| 	 * @property {String} | ||||
| 	 * @event {Function} | ||||
| 	 * @example | ||||
| 	 */ | ||||
| 	export default { | ||||
| 		name: 'u-drawdown-item', | ||||
| 		mixins: [uni.$u.mpMixin, uni.$u.mixin, props], | ||||
| 		data() { | ||||
| 			return { | ||||
| 				show: false, | ||||
| 				top: '126px', | ||||
| 				// uni.createAnimation的导出数据 | ||||
| 				animationData: {}, | ||||
| 			} | ||||
| 		}, | ||||
| 		mounted() { | ||||
| 			this.init() | ||||
| 		}, | ||||
| 		watch: { | ||||
| 			// 发生变化时,需要去更新父组件对应的值 | ||||
| 			dataChange(newValue, oldValue) { | ||||
| 				this.updateParentData() | ||||
| 			} | ||||
| 		}, | ||||
| 		computed: { | ||||
| 			// 监听对应变量的变化 | ||||
| 			dataChange() { | ||||
| 				return [this.title, this.disabled] | ||||
| 			}, | ||||
| 			style() { | ||||
| 				const style = { | ||||
| 					zIndex: 10071, | ||||
| 					position: 'fixed', | ||||
| 					display: 'flex', | ||||
| 					left: 0, | ||||
| 					right: 0 | ||||
| 				} | ||||
| 				style.top = uni.$u.addUnit(this.top) | ||||
| 				return style | ||||
| 			} | ||||
| 		}, | ||||
| 		methods: { | ||||
| 			init() { | ||||
| 				this.updateParentData() | ||||
| 			}, | ||||
| 			// 更新父组件所需的数据 | ||||
| 			updateParentData() { | ||||
| 				// 获取父组件u-dropdown | ||||
| 				this.getParentData('u-dropdown') | ||||
| 				if (!this.parent) uni.$u.error('u-dropdown-item必须配合u-dropdown使用') | ||||
| 				// 查找父组件menuList数组中对应的标题数据 | ||||
| 				const menuIndex = this.parent.menuList.findIndex(item => item.title === this.title) | ||||
| 				const menuContent = { | ||||
| 					title: this.title, | ||||
| 					disabled: this.disabled | ||||
| 				} | ||||
| 				if (menuIndex >= 0) { | ||||
| 					// 如果能找到,则直接修改 | ||||
| 					this.parent.menuList[menuIndex] = menuContent; | ||||
| 				} else { | ||||
| 					// 如果无法找到,则为第一次添加,直接push即可 | ||||
| 					this.parent.menuList.push(menuContent); | ||||
| 				} | ||||
| 			}, | ||||
| 			async setContentAnimate(height) { | ||||
| 				this.animating = true | ||||
| 				// #ifdef APP-NVUE | ||||
| 				const ref = this.$refs['animation'].ref | ||||
| 				animation.transition(ref, { | ||||
| 					styles: { | ||||
| 						height: uni.$u.addUnit(height) | ||||
| 					}, | ||||
| 					duration: this.duration, | ||||
| 					timingFunction: 'ease-in-out', | ||||
| 				}, () => { | ||||
| 					this.animating = false | ||||
| 				}) | ||||
| 				// #endif | ||||
| 			 | ||||
| 				// #ifndef APP-NVUE | ||||
| 				const animation = uni.createAnimation({ | ||||
| 					timingFunction: 'ease-in-out', | ||||
| 				}); | ||||
| 				animation | ||||
| 					.height(height) | ||||
| 					.step({ | ||||
| 						duration: this.duration, | ||||
| 					}) | ||||
| 					.step() | ||||
| 				// 导出动画数据给面板的animationData值 | ||||
| 				this.animationData = animation.export() | ||||
| 				// 标识动画结束 | ||||
| 				uni.$u.sleep(this.duration).then(() => { | ||||
| 					this.animating = false | ||||
| 				}) | ||||
| 				// #endif | ||||
| 			}, | ||||
| 			overlayClick() { | ||||
| 				this.show = false | ||||
| 				this.setContentAnimate(0) | ||||
| 			} | ||||
| 		}, | ||||
| 	} | ||||
| import props from './props.js'; | ||||
| /** | ||||
|  * Dropdown | ||||
|  * @description | ||||
|  * @tutorial url | ||||
|  * @property {String} | ||||
|  * @event {Function} | ||||
|  * @example | ||||
|  */ | ||||
| export default { | ||||
|   name: 'u-dropdown', | ||||
|   mixins: [uni.$u.mixin, props], | ||||
|   data() { | ||||
|     return { | ||||
|       // <20>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD> | ||||
|       menuList: [], | ||||
|       current: 0 | ||||
|     } | ||||
|   }, | ||||
|   computed: { | ||||
|    | ||||
|   }, | ||||
|   created() { | ||||
|     // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(u-dropdown-item)<29><>this<69><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>data<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CEA2>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD> | ||||
|     this.children = []; | ||||
|   }, | ||||
|   methods: { | ||||
|     clickHandler(item, index) { | ||||
|       this.children.map(child => { | ||||
|         if(child.title === item.title) { | ||||
|           // this.queryRect('u-dropdown__menu').then(size => { | ||||
|           child.$emit('click') | ||||
|           child.setContentAnimate(child.show ? 0 : 300) | ||||
|           child.show = !child.show | ||||
|           // }) | ||||
|         } else { | ||||
|           child.show = false | ||||
|           child.setContentAnimate(0) | ||||
|         } | ||||
|       }) | ||||
|     }, | ||||
|     // <20><>ȡ<EFBFBD><C8A1>ǩ<EFBFBD>ijߴ<C4B3>λ<EFBFBD><CEBB> | ||||
|     queryRect(el) { | ||||
|       // #ifndef APP-NVUE | ||||
|       // $uGetRectΪuView<65>Դ<EFBFBD><D4B4>Ľڵ<C4BD><DAB5>ѯ<EFBFBD><EFBFBD><F2BBAFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ܣ<EFBFBD>https://www.uviewui.com/js/getRect.html | ||||
|       // <20><><EFBFBD><EFBFBD>ڲ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>this.$uGetRect<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊthis.$u.getRect<63><74><EFBFBD><EFBFBD><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD>Ʋ<EFBFBD>ͬ | ||||
|       return new Promise(resolve => { | ||||
|         this.$uGetRect(`.${el}`).then(size => { | ||||
|           resolve(size) | ||||
|         }) | ||||
|       }) | ||||
|       // #endif | ||||
|        | ||||
|       // #ifdef APP-NVUE | ||||
|       // nvue<75>£<EFBFBD>ʹ<EFBFBD><CAB9>domģ<6D><C4A3><EFBFBD>ѯԪ<D1AF>ظ߶<D8B8> | ||||
|       // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>promise<73><65><EFBFBD>õ<EFBFBD><C3B5>ô˷<C3B4><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>then<65>ص<EFBFBD> | ||||
|       return new Promise(resolve => { | ||||
|         dom.getComponentRect(this.$refs[el], res => { | ||||
|           resolve(res.size) | ||||
|         }) | ||||
|       }) | ||||
|       // #endif | ||||
|     }, | ||||
|   }, | ||||
| } | ||||
| </script> | ||||
|  | ||||
| <style lang="scss" scoped> | ||||
| 	@import '../../libs/css/components.scss'; | ||||
| 	 | ||||
| 	.u-drawdown-item { | ||||
| 		 | ||||
| 		&__content { | ||||
| 			background-color: #FFFFFF; | ||||
| 			overflow: hidden; | ||||
| 			height: 0; | ||||
| 		} | ||||
| 	} | ||||
| <style lang="scss"> | ||||
| @import '../../libs/css/components.scss'; | ||||
|  | ||||
| .u-dropdown { | ||||
|    | ||||
|   &__menu { | ||||
|     @include flex; | ||||
|      | ||||
|     &__item { | ||||
|       flex: 1; | ||||
|       @include flex; | ||||
|       justify-content: center; | ||||
|        | ||||
|       &__content { | ||||
|         @include flex; | ||||
|         align-items: center; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| </style> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sfmind
					sfmind