综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uv-action-sheet.vue 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <uv-popup
  3. ref="popup"
  4. mode="bottom"
  5. :safeAreaInsetBottom="safeAreaInsetBottom"
  6. :round="round"
  7. :close-on-click-overlay="closeOnClickOverlay"
  8. @change="popupChange"
  9. >
  10. <view class="uv-action-sheet">
  11. <view
  12. class="uv-action-sheet__header"
  13. v-if="title"
  14. >
  15. <text class="uv-action-sheet__header__title uv-line-1">{{title}}</text>
  16. <view
  17. class="uv-action-sheet__header__icon-wrap"
  18. @tap.stop="cancel"
  19. >
  20. <uv-icon
  21. name="close"
  22. size="17"
  23. color="#c8c9cc"
  24. bold
  25. ></uv-icon>
  26. </view>
  27. </view>
  28. <text
  29. class="uv-action-sheet__description"
  30. :style="[{
  31. marginTop: `${title && description ? 0 : '18px'}`
  32. }]"
  33. v-if="description"
  34. >{{description}}</text>
  35. <slot>
  36. <uv-line v-if="description"></uv-line>
  37. <view class="uv-action-sheet__item-wrap">
  38. <view v-for="(item, index) in actions" :key="index">
  39. <!-- #ifdef MP -->
  40. <button
  41. class="uv-reset-button"
  42. :openType="item.openType"
  43. @getuserinfo="onGetUserInfo"
  44. @contact="onContact"
  45. @getphonenumber="onGetPhoneNumber"
  46. @error="onError"
  47. @launchapp="onLaunchApp"
  48. @opensetting="onOpenSetting"
  49. :lang="lang"
  50. :session-from="sessionFrom"
  51. :send-message-title="sendMessageTitle"
  52. :send-message-path="sendMessagePath"
  53. :send-message-img="sendMessageImg"
  54. :show-message-card="showMessageCard"
  55. :app-parameter="appParameter"
  56. @tap="selectHandler(index)"
  57. :hover-class="!item.disabled && !item.loading ? 'uv-action-sheet--hover' : ''"
  58. >
  59. <!-- #endif -->
  60. <view
  61. class="uv-action-sheet__item-wrap__item"
  62. @tap.stop="selectHandler(index)"
  63. :hover-class="!item.disabled && !item.loading ? 'uv-action-sheet--hover' : ''"
  64. :hover-stay-time="150"
  65. >
  66. <template v-if="!item.loading">
  67. <text
  68. class="uv-action-sheet__item-wrap__item__name"
  69. :style="[itemStyle(index)]"
  70. >{{ item.name }}</text>
  71. <text
  72. v-if="item.subname"
  73. class="uv-action-sheet__item-wrap__item__subname"
  74. >{{ item.subname }}</text>
  75. </template>
  76. <uv-loading-icon
  77. v-else
  78. custom-class="van-action-sheet__loading"
  79. size="18"
  80. mode="circle"
  81. />
  82. </view>
  83. <!-- #ifdef MP -->
  84. </button>
  85. <!-- #endif -->
  86. <uv-line v-if="index !== actions.length - 1"></uv-line>
  87. </view>
  88. </view>
  89. </slot>
  90. <uv-gap
  91. bgColor="#eaeaec"
  92. height="6"
  93. v-if="cancelText"
  94. ></uv-gap>
  95. <view hover-class="uv-action-sheet--hover">
  96. <text
  97. @touchmove.stop.prevent
  98. :hover-stay-time="150"
  99. v-if="cancelText"
  100. class="uv-action-sheet__cancel-text"
  101. @tap="cancel"
  102. >{{cancelText}}</text>
  103. </view>
  104. </view>
  105. </uv-popup>
  106. </template>
  107. <script>
  108. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  109. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  110. import button from '@/uni_modules/uv-ui-tools/libs/mixin/button.js'
  111. import openType from '@/uni_modules/uv-ui-tools/libs/mixin/openType.js'
  112. import props from './props.js';
  113. /**
  114. * ActionSheet 操作菜单
  115. * @description 本组件用于从底部弹出一个操作菜单,供用户选择并返回结果。本组件功能类似于uni的uni.showActionSheetAPI,配置更加灵活,所有平台都表现一致。
  116. * @tutorial https://www.uvui.cn/components/actionSheet.html
  117. * @property {Boolean} show 操作菜单是否展示 (默认 false )
  118. * @property {String} title 操作菜单标题
  119. * @property {String} description 选项上方的描述信息
  120. * @property {Array<Object>} actions 按钮的文字数组,见官方文档示例
  121. * @property {String} cancelText 取消按钮的提示文字,不为空时显示按钮
  122. * @property {Boolean} closeOnClickAction 点击某个菜单项时是否关闭弹窗 (默认 true )
  123. * @property {Boolean} safeAreaInsetBottom 处理底部安全区 (默认 true )
  124. * @property {String} openType 小程序的打开方式 (contact | launchApp | getUserInfo | openSetting |getPhoneNumber |error )
  125. * @property {Boolean} closeOnClickOverlay 点击遮罩是否允许关闭 (默认 true )
  126. * @property {String} lang 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文
  127. * @property {String} sessionFrom 会话来源,openType="contact"时有效
  128. * @property {String} sendMessageTitle 会话内消息卡片标题,openType="contact"时有效
  129. * @property {String} sendMessagePath 会话内消息卡片点击跳转小程序路径,openType="contact"时有效
  130. * @property {String} sendMessageImg 会话内消息卡片图片,openType="contact"时有效
  131. * @property {Boolean} showMessageCard 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,openType="contact"时有效 (默认 false )
  132. * @property {String} appParameter 打开 APP 时,向 APP 传递的参数,openType=launchApp 时有效
  133. *
  134. * @event {Function} select 点击ActionSheet列表项时触发
  135. * @event {Function} close 点击取消按钮时触发
  136. * @event {Function} getuserinfo 用户点击该按钮时,会返回获取到的用户信息,回调的 detail 数据与 wx.getUserInfo 返回的一致,openType="getUserInfo"时有效
  137. * @event {Function} contact 客服消息回调,openType="contact"时有效
  138. * @event {Function} getphonenumber 获取用户手机号回调,openType="getPhoneNumber"时有效
  139. * @event {Function} error 当使用开放能力时,发生错误的回调,openType="error"时有效
  140. * @event {Function} launchapp 打开 APP 成功的回调,openType="launchApp"时有效
  141. * @event {Function} opensetting 在打开授权设置页后回调,openType="openSetting"时有效
  142. * @example <uv-action-sheet ref="actionSheet" :actions="list" :title="title" ></uv-action-sheet>
  143. */
  144. export default {
  145. name: "uv-action-sheet",
  146. mixins: [openType, button, mpMixin , mixin, props],
  147. emits: ['close', 'select'],
  148. computed: {
  149. // 操作项目的样式
  150. itemStyle() {
  151. return (index) => {
  152. let style = {};
  153. if (this.actions[index].color) style.color = this.actions[index].color
  154. if (this.actions[index].fontSize) style.fontSize = this.$uv.addUnit(this.actions[index].fontSize)
  155. // 选项被禁用的样式
  156. if (this.actions[index].disabled) style.color = '#c0c4cc'
  157. return style;
  158. }
  159. },
  160. },
  161. methods: {
  162. open() {
  163. this.$refs.popup.open();
  164. },
  165. close() {
  166. this.$refs.popup.close();
  167. },
  168. popupChange(e) {
  169. if(!e.show) this.$emit('close');
  170. },
  171. // 点击取消按钮
  172. cancel() {
  173. this.close();
  174. },
  175. selectHandler(index) {
  176. const item = this.actions[index]
  177. if (item && !item.disabled && !item.loading) {
  178. this.$emit('select', item)
  179. if (this.closeOnClickAction) {
  180. this.close();
  181. }
  182. }
  183. },
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. $show-lines: 1;
  189. $show-reset-button: 1;
  190. @import '@/uni_modules/uv-ui-tools/libs/css/variable.scss';
  191. @import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
  192. @import '@/uni_modules/uv-ui-tools/libs/css/color.scss';
  193. $uv-action-sheet-reset-button-width:100% !default;
  194. $uv-action-sheet-title-font-size: 16px !default;
  195. $uv-action-sheet-title-padding: 12px 30px !default;
  196. $uv-action-sheet-title-color: $uv-main-color !default;
  197. $uv-action-sheet-header-icon-wrap-right:15px !default;
  198. $uv-action-sheet-header-icon-wrap-top:15px !default;
  199. $uv-action-sheet-description-font-size:13px !default;
  200. $uv-action-sheet-description-color:14px !default;
  201. $uv-action-sheet-description-margin: 18px 15px !default;
  202. $uv-action-sheet-item-wrap-item-padding:15px !default;
  203. $uv-action-sheet-item-wrap-name-font-size:16px !default;
  204. $uv-action-sheet-item-wrap-subname-font-size:13px !default;
  205. $uv-action-sheet-item-wrap-subname-color: #c0c4cc !default;
  206. $uv-action-sheet-item-wrap-subname-margin-top:10px !default;
  207. $uv-action-sheet-cancel-text-font-size:16px !default;
  208. $uv-action-sheet-cancel-text-color:$uv-content-color !default;
  209. $uv-action-sheet-cancel-text-font-size:15px !default;
  210. $uv-action-sheet-cancel-text-hover-background-color:rgb(242, 243, 245) !default;
  211. .uv-reset-button {
  212. width: $uv-action-sheet-reset-button-width;
  213. }
  214. .uv-action-sheet {
  215. text-align: center;
  216. &__header {
  217. position: relative;
  218. padding: $uv-action-sheet-title-padding;
  219. &__title {
  220. font-size: $uv-action-sheet-title-font-size;
  221. color: $uv-action-sheet-title-color;
  222. font-weight: bold;
  223. text-align: center;
  224. }
  225. &__icon-wrap {
  226. position: absolute;
  227. right: $uv-action-sheet-header-icon-wrap-right;
  228. top: $uv-action-sheet-header-icon-wrap-top;
  229. }
  230. }
  231. &__description {
  232. font-size: $uv-action-sheet-description-font-size;
  233. color: $uv-tips-color;
  234. margin: $uv-action-sheet-description-margin;
  235. text-align: center;
  236. }
  237. &__item-wrap {
  238. &__item {
  239. padding: $uv-action-sheet-item-wrap-item-padding;
  240. @include flex;
  241. align-items: center;
  242. justify-content: center;
  243. flex-direction: column;
  244. &__name {
  245. font-size: $uv-action-sheet-item-wrap-name-font-size;
  246. color: $uv-main-color;
  247. text-align: center;
  248. }
  249. &__subname {
  250. font-size: $uv-action-sheet-item-wrap-subname-font-size;
  251. color: $uv-action-sheet-item-wrap-subname-color;
  252. margin-top: $uv-action-sheet-item-wrap-subname-margin-top;
  253. text-align: center;
  254. }
  255. }
  256. }
  257. &__cancel-text {
  258. font-size: $uv-action-sheet-cancel-text-font-size;
  259. color: $uv-action-sheet-cancel-text-color;
  260. text-align: center;
  261. padding: $uv-action-sheet-cancel-text-font-size;
  262. }
  263. &--hover {
  264. background-color: $uv-action-sheet-cancel-text-hover-background-color;
  265. }
  266. }
  267. </style>