tm-actionSheet.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="tm-actionSheet ">
  3. <tm-poup @change="toogle" ref="pop" v-model="showpop" height="auto" :black="black_tmeme" :bg-color="black_tmeme ? 'grey-darken-6' : 'grey-lighten-4'">
  4. <view class="tm-actionSheet-title pa-32 pb-32 relative " :class="[black_tmeme ? 'grey-darken-5' : 'white']">
  5. <view class="text-size-n text-align-center">{{ title }}</view>
  6. <view class="tm-actionSheet-close rounded flex-center absolute" :class="black_tmeme ? 'grey-darken-4' : 'grey-lighten-3'">
  7. <tm-icons @click="close" name="icon-times" size="24" :color="black_tmeme ? 'white' : 'grey'"></tm-icons>
  8. </view>
  9. </view>
  10. <view>
  11. <slot>
  12. <tm-grouplist shadow="5" round="4">
  13. <tm-listitem
  14. :black="black_tmeme"
  15. @click="onclick(index, item)"
  16. v-for="(item, index) in actions"
  17. :key="index"
  18. :title="item[rangKey]"
  19. :label="item['label'] ? item['label'] : ''"
  20. :right-icon="item['rightIcon'] ? item['rightIcon'] : 'icon-angle-right'"
  21. ></tm-listitem>
  22. </tm-grouplist>
  23. </slot>
  24. </view>
  25. <view style="height: 50upx"></view>
  26. </tm-poup>
  27. </view>
  28. </template>
  29. <script>
  30. /**
  31. * 动作面板
  32. * @description 动作面板,从底部弹出的操作菜单。
  33. * @property {Boolean} black = [true|false] 默认:false,暗黑模式
  34. * @property {Boolean} value = [true|false] 默认:false,显示菜单,推荐使用v-model,使用value.sync达到双向绑定。
  35. * @property {String} title = [] 默认:'请操作',弹出层的标题。
  36. * @property {Array} actions = [] 默认:[],格式见文档,操作数组。
  37. * @property {String} rang-key = [title] 默认:title,actions对象数组时,自定义标题键。
  38. * @property {Boolean} click-close = [true|false] 默认:true,点击项目时,是否自动关闭弹层。
  39. * @property {Function} change 点击项目时触发,返回:{index:项目索引,data:actions的对象数据}
  40. * @property {Function} input 弹层显示和隐藏时,将会触发。
  41. * @example <tm-actionSheet @change="test" v-model="show" :actions="[{title:'说明文档',label:'这是说明文件的资料信息'},{title:'新建文件夹'}]"></tm-actionSheet>
  42. */
  43. import tmGrouplist from '@/tm-vuetify/components/tm-grouplist/tm-grouplist.vue';
  44. import tmListitem from '@/tm-vuetify/components/tm-listitem/tm-listitem.vue';
  45. import tmIcons from '@/tm-vuetify/components/tm-icons/tm-icons.vue';
  46. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  47. export default {
  48. components: { tmGrouplist, tmListitem, tmIcons, tmPoup },
  49. name: 'tm-actionSheet',
  50. model: {
  51. prop: 'value',
  52. event: 'input'
  53. },
  54. props: {
  55. value: {
  56. type: Boolean,
  57. default: false
  58. },
  59. black: {
  60. type: Boolean,
  61. default: null
  62. },
  63. title: {
  64. type: String,
  65. default: '操作栏'
  66. },
  67. // 数组格式。
  68. /*
  69. {
  70. title:"标题",
  71. label:"项目说明文字",
  72. rightIcon:"",//右边图标。
  73. }
  74. */
  75. actions: {
  76. type: Array,
  77. default: () => {
  78. return [];
  79. }
  80. },
  81. // 自定义标题键key.
  82. rangKey: {
  83. type: String,
  84. default: 'title'
  85. },
  86. // 点击项目时,是否关闭弹层
  87. clickClose: {
  88. type: Boolean,
  89. default: true
  90. }
  91. },
  92. data() {
  93. return {
  94. showpop: false
  95. };
  96. },
  97. mounted() {
  98. this.showpop = this.value;
  99. },
  100. watch: {
  101. value: function(val) {
  102. this.showpop = val;
  103. }
  104. },
  105. computed: {
  106. black_tmeme: function() {
  107. if (this.black !== null) return this.black;
  108. return this.$tm.vx.state().tmVuetify.black;
  109. }
  110. },
  111. methods: {
  112. close() {
  113. this.$refs.pop.close();
  114. },
  115. toogle(e) {
  116. let t = this;
  117. if (e) {
  118. this.$nextTick(function() {
  119. if (this.showpop != this.value) {
  120. this.showpop = this.value;
  121. }
  122. });
  123. }
  124. this.$emit('input', e);
  125. this.$emit('update:value', e);
  126. },
  127. onclick(index, item) {
  128. if (this.clickClose === true) {
  129. this.$refs.pop.close();
  130. this.$emit('change', {
  131. index: index,
  132. data: item
  133. });
  134. }
  135. }
  136. }
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. .tm-actionSheet-title {
  141. .tm-actionSheet-close {
  142. top: 32upx;
  143. right: 32upx;
  144. width: 50upx;
  145. height: 50upx;
  146. }
  147. }
  148. </style>