From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 11:46:57 +0800 Subject: [PATCH] 项目初始化 --- uni_modules/uview-ui/components/u-dropdown-item/u-dropdown-item.vue | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 146 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/components/u-dropdown-item/u-dropdown-item.vue b/uni_modules/uview-ui/components/u-dropdown-item/u-dropdown-item.vue new file mode 100644 index 0000000..07de583 --- /dev/null +++ b/uni_modules/uview-ui/components/u-dropdown-item/u-dropdown-item.vue @@ -0,0 +1,146 @@ +<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> +</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() { + // 鑾峰彇鐖剁粍浠秛-dropdown + this.getParentData('u-dropdown') + if (!this.parent) uni.$u.error('u-dropdown-item蹇呴』閰嶅悎u-dropdown浣跨敤') + // 鏌ユ壘鐖剁粍浠秏enuList鏁扮粍涓搴旂殑鏍囬鏁版嵁 + 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) + } + }, + } +</script> + +<style lang="scss" scoped> + @import '../../libs/css/components.scss'; + + .u-drawdown-item { + + &__content { + background-color: #FFFFFF; + overflow: hidden; + height: 0; + } + } +</style> -- Gitblit v1.9.3