¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | <template> |
| | | <u-popup |
| | | :show="show" |
| | | mode="bottom" |
| | | @close="closeHandler" |
| | | :safeAreaInsetBottom="safeAreaInsetBottom" |
| | | :round="round" |
| | | > |
| | | <view class="u-action-sheet"> |
| | | <view |
| | | class="u-action-sheet__header" |
| | | v-if="title" |
| | | > |
| | | <text class="u-action-sheet__header__title u-line-1">{{title}}</text> |
| | | <view |
| | | class="u-action-sheet__header__icon-wrap" |
| | | @tap.stop="cancel" |
| | | > |
| | | <u-icon |
| | | name="close" |
| | | size="17" |
| | | color="#c8c9cc" |
| | | bold |
| | | ></u-icon> |
| | | </view> |
| | | </view> |
| | | <text |
| | | class="u-action-sheet__description" |
| | | :style="[{ |
| | | marginTop: `${title && description ? 0 : '18px'}` |
| | | }]" |
| | | v-if="description" |
| | | >{{description}}</text> |
| | | <slot> |
| | | <u-line v-if="description"></u-line> |
| | | <view class="u-action-sheet__item-wrap"> |
| | | <template v-for="(item, index) in actions"> |
| | | <!-- #ifdef MP --> |
| | | <button |
| | | :key="index" |
| | | class="u-reset-button" |
| | | :openType="item.openType" |
| | | @getuserinfo="onGetUserInfo" |
| | | @contact="onContact" |
| | | @getphonenumber="onGetPhoneNumber" |
| | | @error="onError" |
| | | @launchapp="onLaunchApp" |
| | | @opensetting="onOpenSetting" |
| | | :lang="lang" |
| | | :session-from="sessionFrom" |
| | | :send-message-title="sendMessageTitle" |
| | | :send-message-path="sendMessagePath" |
| | | :send-message-img="sendMessageImg" |
| | | :show-message-card="showMessageCard" |
| | | :app-parameter="appParameter" |
| | | @tap="selectHandler(index)" |
| | | :hover-class="!item.disabled && !item.loading ? 'u-action-sheet--hover' : ''" |
| | | > |
| | | <!-- #endif --> |
| | | <view |
| | | class="u-action-sheet__item-wrap__item" |
| | | @tap.stop="selectHandler(index)" |
| | | :hover-class="!item.disabled && !item.loading ? 'u-action-sheet--hover' : ''" |
| | | :hover-stay-time="150" |
| | | > |
| | | <template v-if="!item.loading"> |
| | | <text |
| | | class="u-action-sheet__item-wrap__item__name" |
| | | :style="[itemStyle(index)]" |
| | | >{{ item.name }}</text> |
| | | <text |
| | | v-if="item.subname" |
| | | class="u-action-sheet__item-wrap__item__subname" |
| | | >{{ item.subname }}</text> |
| | | </template> |
| | | <u-loading-icon |
| | | v-else |
| | | custom-class="van-action-sheet__loading" |
| | | size="18" |
| | | mode="circle" |
| | | /> |
| | | </view> |
| | | <!-- #ifdef MP --> |
| | | </button> |
| | | <!-- #endif --> |
| | | <u-line v-if="index !== actions.length - 1"></u-line> |
| | | </template> |
| | | </view> |
| | | </slot> |
| | | <u-gap |
| | | bgColor="#eaeaec" |
| | | height="6" |
| | | v-if="cancelText" |
| | | ></u-gap> |
| | | <view hover-class="u-action-sheet--hover"> |
| | | <text |
| | | @touchmove.stop.prevent |
| | | :hover-stay-time="150" |
| | | v-if="cancelText" |
| | | class="u-action-sheet__cancel-text" |
| | | @tap="cancel" |
| | | >{{cancelText}}</text> |
| | | </view> |
| | | </view> |
| | | </u-popup> |
| | | </template> |
| | | |
| | | <script> |
| | | import openType from '../../libs/mixin/openType' |
| | | import button from '../../libs/mixin/button' |
| | | import props from './props.js'; |
| | | /** |
| | | * ActionSheet æä½èå |
| | | * @description æ¬ç»ä»¶ç¨äºä»åºé¨å¼¹åºä¸ä¸ªæä½èåï¼ä¾ç¨æ·éæ©å¹¶è¿åç»æãæ¬ç»ä»¶åè½ç±»ä¼¼äºuniçuni.showActionSheetAPIï¼é
ç½®æ´å çµæ´»ï¼ææå¹³å°é½è¡¨ç°ä¸è´ã |
| | | * @tutorial https://www.uviewui.com/components/actionSheet.html |
| | | * |
| | | * @property {Boolean} show æä½è忝å¦å±ç¤º ï¼é»è®¤ false ï¼ |
| | | * @property {String} title æä½èåæ é¢ |
| | | * @property {String} description é项䏿¹çæè¿°ä¿¡æ¯ |
| | | * @property {Array<Object>} actions æé®çæåæ°ç»ï¼è§å®æ¹ææ¡£ç¤ºä¾ |
| | | * @property {String} cancelText åæ¶æé®çæç¤ºæå,ä¸ä¸ºç©ºæ¶æ¾ç¤ºæé® |
| | | * @property {Boolean} closeOnClickAction ç¹å»æä¸ªèåé¡¹æ¶æ¯å¦å
³éå¼¹çª ï¼é»è®¤ true ï¼ |
| | | * @property {Boolean} safeAreaInsetBottom å¤çåºé¨å®å
¨åº ï¼é»è®¤ true ï¼ |
| | | * @property {String} openType å°ç¨åºçæå¼æ¹å¼ (contact | launchApp | getUserInfo | openSetting ï½getPhoneNumber ï½error ) |
| | | * @property {Boolean} closeOnClickOverlay ç¹å»é®ç½©æ¯å¦å
许å
³é (é»è®¤ true ) |
| | | * @property {Number|String} round åè§å¼ï¼é»è®¤æ åè§ (é»è®¤ 0 ) |
| | | * @property {String} lang æå®è¿åç¨æ·ä¿¡æ¯çè¯è¨ï¼zh_CN ç®ä½ä¸æï¼zh_TW ç¹ä½ä¸æï¼en è±æ |
| | | * @property {String} sessionFrom ä¼è¯æ¥æºï¼openType="contact"æ¶ææ |
| | | * @property {String} sendMessageTitle ä¼è¯å
æ¶æ¯å¡çæ é¢ï¼openType="contact"æ¶ææ |
| | | * @property {String} sendMessagePath ä¼è¯å
æ¶æ¯å¡çç¹å»è·³è½¬å°ç¨åºè·¯å¾ï¼openType="contact"æ¶ææ |
| | | * @property {String} sendMessageImg ä¼è¯å
æ¶æ¯å¡çå¾çï¼openType="contact"æ¶ææ |
| | | * @property {Boolean} showMessageCard æ¯å¦æ¾ç¤ºä¼è¯å
æ¶æ¯å¡çï¼è®¾ç½®æ¤åæ°ä¸º trueï¼ç¨æ·è¿å
¥å®¢æä¼è¯ä¼å¨å³ä¸è§æ¾ç¤º"å¯è½è¦åéçå°ç¨åº"æç¤ºï¼ç¨æ·ç¹å»åå¯ä»¥å¿«éåéå°ç¨åºæ¶æ¯ï¼openType="contact"æ¶ææ ï¼é»è®¤ false ï¼ |
| | | * @property {String} appParameter æå¼ APP æ¶ï¼å APP ä¼ éçåæ°ï¼openType=launchApp æ¶ææ |
| | | * |
| | | * @event {Function} select ç¹å»ActionSheetå表项æ¶è§¦å |
| | | * @event {Function} close ç¹å»åæ¶æé®æ¶è§¦å |
| | | * @event {Function} getuserinfo ç¨æ·ç¹å»è¯¥æé®æ¶ï¼ä¼è¿åè·åå°çç¨æ·ä¿¡æ¯ï¼åè°ç detail æ°æ®ä¸ wx.getUserInfo è¿åçä¸è´ï¼openType="getUserInfo"æ¶ææ |
| | | * @event {Function} contact å®¢ææ¶æ¯åè°ï¼openType="contact"æ¶ææ |
| | | * @event {Function} getphonenumber è·åç¨æ·ææºå·åè°ï¼openType="getPhoneNumber"æ¶ææ |
| | | * @event {Function} error å½ä½¿ç¨å¼æ¾è½åæ¶ï¼åçé误çåè°ï¼openType="error"æ¶ææ |
| | | * @event {Function} launchapp æå¼ APP æåçåè°ï¼openType="launchApp"æ¶ææ |
| | | * @event {Function} opensetting 卿弿æè®¾ç½®é¡µååè°ï¼openType="openSetting"æ¶ææ |
| | | * @example <u-action-sheet :actions="list" :title="title" :show="show"></u-action-sheet> |
| | | */ |
| | | export default { |
| | | name: "u-action-sheet", |
| | | // ä¸äºpropsåæ°åmethodsæ¹æ³ï¼éè¿mixinæ··å
¥ï¼å 为å
¶ä»æä»¶ä¹ä¼ç¨å° |
| | | mixins: [openType, button, uni.$u.mixin, props], |
| | | data() { |
| | | return { |
| | | |
| | | } |
| | | }, |
| | | computed: { |
| | | // æä½é¡¹ç®çæ ·å¼ |
| | | itemStyle() { |
| | | return (index) => { |
| | | let style = {}; |
| | | if (this.actions[index].color) style.color = this.actions[index].color |
| | | if (this.actions[index].fontSize) style.fontSize = uni.$u.addUnit(this.actions[index].fontSize) |
| | | // é项被ç¦ç¨çæ ·å¼ |
| | | if (this.actions[index].disabled) style.color = '#c0c4cc' |
| | | return style; |
| | | } |
| | | }, |
| | | }, |
| | | methods: { |
| | | closeHandler() { |
| | | // å
许ç¹å»é®ç½©å
³éæ¶ï¼æååºcloseäºä»¶ |
| | | if(this.closeOnClickOverlay) { |
| | | this.$emit('close') |
| | | } |
| | | }, |
| | | // ç¹å»åæ¶æé® |
| | | cancel() { |
| | | this.$emit('close') |
| | | }, |
| | | selectHandler(index) { |
| | | const item = this.actions[index] |
| | | if (item && !item.disabled && !item.loading) { |
| | | this.$emit('select', item) |
| | | if (this.closeOnClickAction) { |
| | | this.$emit('close') |
| | | } |
| | | } |
| | | }, |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | $u-action-sheet-reset-button-width:100% !default; |
| | | $u-action-sheet-title-font-size: 16px !default; |
| | | $u-action-sheet-title-padding: 12px 30px !default; |
| | | $u-action-sheet-title-color: $u-main-color !default; |
| | | $u-action-sheet-header-icon-wrap-right:15px !default; |
| | | $u-action-sheet-header-icon-wrap-top:15px !default; |
| | | $u-action-sheet-description-font-size:13px !default; |
| | | $u-action-sheet-description-color:14px !default; |
| | | $u-action-sheet-description-margin: 18px 15px !default; |
| | | $u-action-sheet-item-wrap-item-padding:15px !default; |
| | | $u-action-sheet-item-wrap-name-font-size:16px !default; |
| | | $u-action-sheet-item-wrap-subname-font-size:13px !default; |
| | | $u-action-sheet-item-wrap-subname-color: #c0c4cc !default; |
| | | $u-action-sheet-item-wrap-subname-margin-top:10px !default; |
| | | $u-action-sheet-cancel-text-font-size:16px !default; |
| | | $u-action-sheet-cancel-text-color:$u-content-color !default; |
| | | $u-action-sheet-cancel-text-font-size:15px !default; |
| | | $u-action-sheet-cancel-text-hover-background-color:rgb(242, 243, 245) !default; |
| | | |
| | | .u-reset-button { |
| | | width: $u-action-sheet-reset-button-width; |
| | | } |
| | | |
| | | .u-action-sheet { |
| | | text-align: center; |
| | | &__header { |
| | | position: relative; |
| | | padding: $u-action-sheet-title-padding; |
| | | &__title { |
| | | font-size: $u-action-sheet-title-font-size; |
| | | color: $u-action-sheet-title-color; |
| | | font-weight: bold; |
| | | text-align: center; |
| | | } |
| | | |
| | | &__icon-wrap { |
| | | position: absolute; |
| | | right: $u-action-sheet-header-icon-wrap-right; |
| | | top: $u-action-sheet-header-icon-wrap-top; |
| | | } |
| | | } |
| | | |
| | | &__description { |
| | | font-size: $u-action-sheet-description-font-size; |
| | | color: $u-tips-color; |
| | | margin: $u-action-sheet-description-margin; |
| | | text-align: center; |
| | | } |
| | | |
| | | &__item-wrap { |
| | | |
| | | &__item { |
| | | padding: $u-action-sheet-item-wrap-item-padding; |
| | | @include flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | flex-direction: column; |
| | | |
| | | &__name { |
| | | font-size: $u-action-sheet-item-wrap-name-font-size; |
| | | color: $u-main-color; |
| | | text-align: center; |
| | | } |
| | | |
| | | &__subname { |
| | | font-size: $u-action-sheet-item-wrap-subname-font-size; |
| | | color: $u-action-sheet-item-wrap-subname-color; |
| | | margin-top: $u-action-sheet-item-wrap-subname-margin-top; |
| | | text-align: center; |
| | | } |
| | | } |
| | | } |
| | | |
| | | &__cancel-text { |
| | | font-size: $u-action-sheet-cancel-text-font-size; |
| | | color: $u-action-sheet-cancel-text-color; |
| | | text-align: center; |
| | | padding: $u-action-sheet-cancel-text-font-size; |
| | | } |
| | | |
| | | &--hover { |
| | | background-color: $u-action-sheet-cancel-text-hover-background-color; |
| | | } |
| | | } |
| | | </style> |