tm-actionSheetMenu.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="tm-actionSheetMenu">
  3. <tm-poup @change="toogle" ref="pop" :black="false" v-model="showpop" height="auto" bg-color="none">
  4. <view class="ma-32">
  5. <view class=" round-8 overflow ">
  6. <tm-button
  7. :fllowTheme="false"
  8. :black="black_tmeme"
  9. font-size="22"
  10. font-color="grey"
  11. :theme="black_tmeme ? 'grey-darken-4' : 'white'"
  12. block
  13. flat
  14. >
  15. {{ title }}
  16. </tm-button>
  17. <slot>
  18. <tm-button
  19. :fllowTheme="false"
  20. :black="black_tmeme"
  21. @click="onclick(index, item)"
  22. v-for="(item, index) in actions"
  23. :key="index"
  24. :item-class="'text-' + color_tmeme"
  25. :theme="black_tmeme ? 'grey-darken-4' : 'white'"
  26. block
  27. flat
  28. >
  29. {{ item[rangKey] ? item[rangKey] : item }}
  30. </tm-button>
  31. </slot>
  32. </view>
  33. <view style="height: 96upx " class="pb-24 pt-16">
  34. <tm-button :round="8" :fllowTheme="false" :item-class="' text-weight-b'" :black="black_tmeme" @click="close" :theme="black ? 'grey-darken-4' : 'white'" block>
  35. 取消
  36. </tm-button>
  37. </view>
  38. <!-- #ifdef H5 -->
  39. <view style="height: var(--window-bottom);"></view>
  40. <!-- #endif -->
  41. </view>
  42. </tm-poup>
  43. </view>
  44. </template>
  45. <script>
  46. /**
  47. * 动作面板
  48. * @description 动作面板,从底部弹出的操作菜单。
  49. * @property {Boolean} black = [true|false] 默认:null,暗黑模式
  50. * @property {Boolean} value = [true|false] 默认:false,显示菜单,推荐使用v-model,使用value.sync达到双向绑定。
  51. * @property {String} title = [] 默认:'请操作',弹出层的标题。
  52. * @property {Array} actions = [] 默认:[],可以是对象数组,也可是字符串数组。
  53. * @property {String} rang-key = [title] 默认:title,actions对象数组时,需要提供自定义标题键。
  54. * @property {Boolean} click-close = [true|false] 默认:true,点击项目时,是否自动关闭弹层。
  55. * @property {Boolean} font-color = [] 默认:primary,文字颜色。可以是主题颜色,也可以是颜色格式rgb,rgba,#ff0000格式
  56. * @property {Function} change 点击项目时触发,返回:{index:项目索引,data:actions的对象数据}
  57. * @property {Function} input 弹层显示和隐藏时,将会触发。
  58. * @example <tm-actionSheetMenu :value="true" :actions="['说明文档','说明文档']"></tm-actionSheetMenu>
  59. */
  60. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  61. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  62. export default {
  63. components: { tmButton, tmPoup },
  64. name: 'tm-actionSheetMenu',
  65. model: {
  66. prop: 'value',
  67. event: 'input'
  68. },
  69. props: {
  70. value: {
  71. type: Boolean,
  72. default: false
  73. },
  74. black: {
  75. type: Boolean,
  76. default: null
  77. },
  78. title: {
  79. type: String,
  80. default: '请操作'
  81. },
  82. fontColor: {
  83. type: String,
  84. default: 'black'
  85. },
  86. actions: {
  87. type: Array,
  88. default: () => {
  89. return [];
  90. }
  91. },
  92. // 自定义标题键key.
  93. rangKey: {
  94. type: String,
  95. default: 'title'
  96. },
  97. // 点击项目时,是否关闭弹层
  98. clickClose: {
  99. type: Boolean,
  100. default: true
  101. },
  102. // 跟随主题色的改变而改变。
  103. fllowTheme: {
  104. type: Boolean | String,
  105. default: true
  106. }
  107. },
  108. data() {
  109. return {
  110. showpop: false
  111. };
  112. },
  113. mounted() {
  114. this.showpop = this.value;
  115. },
  116. computed: {
  117. color_tmeme: function() {
  118. if (this.$tm.vx.state().tmVuetify.color !== null && this.$tm.vx.state().tmVuetify.color && this.fllowTheme) {
  119. return this.$tm.vx.state().tmVuetify.color;
  120. }
  121. return this.fontColor;
  122. },
  123. black_tmeme: function() {
  124. if (this.black !== null) return this.black;
  125. return this.$tm.vx.state().tmVuetify.black;
  126. }
  127. },
  128. watch: {
  129. value: function(val) {
  130. this.showpop = val;
  131. }
  132. },
  133. methods: {
  134. close() {
  135. this.$refs.pop.close();
  136. },
  137. toogle(e) {
  138. let t = this;
  139. if (e) {
  140. this.$nextTick(function() {
  141. if (this.dataValue != this.defaultValue) {
  142. this.dataValue = this.defaultValue;
  143. }
  144. });
  145. }
  146. this.$emit('input', e);
  147. this.$emit('update:value', e);
  148. },
  149. onclick(index, item) {
  150. this.$emit('change', { index: index, data: item });
  151. if (this.clickClose === true) {
  152. this.$refs.pop.close();
  153. }
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. .tm-actionSheetMenu-title {
  160. .tm-actionSheetMenu-close {
  161. top: 32upx;
  162. right: 32upx;
  163. width: 50upx;
  164. height: 50upx;
  165. }
  166. }
  167. </style>