tm-sliderNav.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="tm-sliderNav fulled-height">
  3. <scroll-view scroll-y :style="{
  4. height:activeHeight+'px',
  5. width:activeWidth+'px',
  6. }">
  7. <tm-listitem :disabled="item['disabled']==true?true:false" :black="black_tmeme"
  8. @click="change(index)"
  9. v-for="(item,index) in formaData" :key='index'
  10. :color="activeIndex==index?(text?' text ' + color_tmeme:'white'):bgColor"
  11. :show-right-icon="false"
  12. :margin="[0,0]"
  13. :padding="[10,32]"
  14. :fontSize="fontSize"
  15. :class-style="activeIndex==index?`border-${color_tmeme}-l-2`:`border-${bgColor}-l-2`"
  16. round="0" shadow="0"
  17. >
  18. <tm-badges color='red' :fllowTheme="false" :offset="[12,-10]" v-if="item.dot>0&&dot" :dot="false" :label="item.dot"></tm-badges>
  19. <view class="" >
  20. <text :class="[`text-${activeIndex==index?color_tmeme:fontColor}`,item['disabled']?'opacity-3':'']">{{item[rangKey]}}</text>
  21. </view>
  22. </tm-listitem>
  23. </scroll-view>
  24. </view>
  25. </template>
  26. <script>
  27. /**
  28. * 侧边导航
  29. * @property {Number|String} height = [] 默认0,单位upx,自动使用父组件的高度。
  30. * @property {Number|String} width = [] 默认190,单位upx,宽度
  31. * @property {Number} round = [] 默认4,单位upx,圆角
  32. * @property {Array} list = [] 默认[],数据结构对象,必须需要含有唯一标识符id即可。[{title:'苏州'}],,可以含有dot,显示角标。每一个类目和子类可以含有disabled值,用来禁用类目或者选项。
  33. * @property {String} rang-key = [] 默认'title',数据结构对象中,需要展示标签的key
  34. * @property {String} color = [] 默认 primary,主题色名
  35. * @property {String} bg-color = [] 默认 grey-lighten-5,主题色名未选择时的背景色。
  36. * @property {String} font-color = [] 默认 grey,未选中时的文字颜色
  37. * @property {String} font-size = [] 默认 28,项目文字大小单位rpx
  38. * @property {Boolean} black = [] 默认 false,是否暗黑模式。
  39. * @property {Boolean} dot = [] 默认 false,是否显示角标数字,当前选中的数量。
  40. * @property {Boolean} text = [] 默认 false,使用主题文本色为高亮色。
  41. * @property {Function} change 每次选择变化都会触发全局change,
  42. * @example <tm-sliderNav :text="true" :list="list"></tm-sliderNav>
  43. */
  44. import tmListitem from "@/tm-vuetify/components/tm-listitem/tm-listitem.vue"
  45. import tmGrouplist from "@/tm-vuetify/components/tm-grouplist/tm-grouplist.vue"
  46. import tmBadges from "@/tm-vuetify/components/tm-badges/tm-badges.vue"
  47. export default {
  48. components:{tmListitem,tmGrouplist,tmBadges},
  49. name:"tm-sliderNav",
  50. props:{
  51. // 高度,默认为0时,自动使用父组件的高度.单位upx
  52. height: {
  53. type: String | Number,
  54. default: 0
  55. },
  56. //单位upx
  57. width: {
  58. type: String | Number,
  59. default: 190
  60. },
  61. //单位upx
  62. round: {
  63. type: Number,
  64. default: 4
  65. },
  66. // 对象数组
  67. list:{
  68. type:Array,
  69. default:()=>{
  70. return [];
  71. }
  72. },
  73. // 显示标签的key.
  74. rangKey:{
  75. type:String,
  76. default:'title'
  77. },
  78. // 主题色名
  79. color:{
  80. type:String,
  81. default:'primary'
  82. },
  83. fontColor:{
  84. type:String,
  85. default:'grey-darken-1'
  86. },
  87. black:{
  88. type:Boolean|String,
  89. default:null
  90. },
  91. // 是否显示角标数字当前选中的数量。
  92. dot:{
  93. type:Boolean,
  94. default:true
  95. },
  96. // 使用主题文本色为高亮色。
  97. text:{
  98. type:Boolean,
  99. default:false
  100. },
  101. fontSize:{
  102. type:String|Number,
  103. default:'28'
  104. },
  105. // 未选择时的背景色。
  106. bgColor:{
  107. type:String,
  108. default:'grey-lighten-5'
  109. },
  110. // 跟随主题色的改变而改变。
  111. fllowTheme:{
  112. type:Boolean|String,
  113. default:true
  114. }
  115. },
  116. watch:{
  117. list:{
  118. deep:true,
  119. handler(){
  120. this.dataList = this.list;
  121. }
  122. }
  123. },
  124. data() {
  125. return {
  126. activeHeight:0,
  127. activeWidth:0,
  128. activeIndex:0,
  129. formaData:[]
  130. };
  131. },
  132. computed:{
  133. dataList:{
  134. get:function(){
  135. return this.formaData
  136. },
  137. set:function(val){
  138. let t = this;
  139. let p = [...val];
  140. for(let j=0;j<p.length;j++){
  141. if(!p[j].hasOwnProperty('dot')){
  142. p[j]['dot'] = 0;
  143. }
  144. }
  145. this.formaData = p;
  146. }
  147. },
  148. black_tmeme: function() {
  149. if (this.black !== null) return this.black;
  150. return this.$tm.vx.state().tmVuetify.black;
  151. },
  152. color_tmeme:function(){
  153. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  154. return this.$tm.vx.state().tmVuetify.color;
  155. }
  156. return this.color;
  157. },
  158. },
  159. mounted() {
  160. let t = this;
  161. this.$nextTick(async function() {
  162. this.activeHeight = uni.upx2px(this.height);
  163. if (!this.activeHeight) {
  164. let wsz = await this.$Querey(".tm-sliderNav",this).catch(e=>{})
  165. this.activeHeight = wsz[0].height||250;
  166. this.activeWidth =uni.upx2px(this.width)||100;
  167. }
  168. this.dataList = this.list;
  169. });
  170. },
  171. methods: {
  172. change(index) {
  173. this.activeIndex=index;
  174. this.$emit('change',index);
  175. }
  176. },
  177. }
  178. </script>
  179. <style lang="scss">
  180. </style>