tm-sliderNav.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // activeIndex
  74. activeIndex: {
  75. type: Number |String,
  76. default: 0 // set a default value for the prop
  77. },
  78. // 显示标签的key.
  79. rangKey:{
  80. type:String,
  81. default:'title'
  82. },
  83. // 主题色名
  84. color:{
  85. type:String,
  86. default:'primary'
  87. },
  88. fontColor:{
  89. type:String,
  90. default:'grey-darken-1'
  91. },
  92. black:{
  93. type:Boolean|String,
  94. default:null
  95. },
  96. // 是否显示角标数字当前选中的数量。
  97. dot:{
  98. type:Boolean,
  99. default:true
  100. },
  101. // 使用主题文本色为高亮色。
  102. text:{
  103. type:Boolean,
  104. default:false
  105. },
  106. fontSize:{
  107. type:String|Number,
  108. default:'28'
  109. },
  110. // 未选择时的背景色。
  111. bgColor:{
  112. type:String,
  113. default:'grey-lighten-5'
  114. },
  115. // 跟随主题色的改变而改变。
  116. fllowTheme:{
  117. type:Boolean|String,
  118. default:true
  119. }
  120. },
  121. watch:{
  122. list:{
  123. deep:true,
  124. handler(){
  125. this.dataList = this.list;
  126. }
  127. }
  128. },
  129. data() {
  130. return {
  131. activeHeight:0,
  132. activeWidth:0,
  133. formaData:[],
  134. };
  135. },
  136. computed:{
  137. dataList:{
  138. get:function(){
  139. return this.formaData
  140. },
  141. set:function(val){
  142. let t = this;
  143. let p = [...val];
  144. for(let j=0;j<p.length;j++){
  145. if(!p[j].hasOwnProperty('dot')){
  146. p[j]['dot'] = 0;
  147. }
  148. }
  149. this.formaData = p;
  150. }
  151. },
  152. black_tmeme: function() {
  153. if (this.black !== null) return this.black;
  154. return this.$tm.vx.state().tmVuetify.black;
  155. },
  156. color_tmeme:function(){
  157. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  158. return this.$tm.vx.state().tmVuetify.color;
  159. }
  160. return this.color;
  161. },
  162. },
  163. mounted() {
  164. let t = this;
  165. this.$nextTick(async function() {
  166. this.activeHeight = uni.upx2px(this.height);
  167. if (!this.activeHeight) {
  168. let wsz = await this.$Querey(".tm-sliderNav",this).catch(e=>{})
  169. this.activeHeight = wsz[0].height||250;
  170. this.activeWidth =uni.upx2px(this.width)||100;
  171. }
  172. this.dataList = this.list;
  173. });
  174. },
  175. methods: {
  176. change(index) {
  177. // this.activeIndex=index;
  178. this.$emit('change',index);
  179. }
  180. },
  181. }
  182. </script>
  183. <style lang="scss">
  184. </style>