@kaiyinchem/ky-uniui 1.1.12 → 1.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,10 @@
10
10
  card: type === 'card',
11
11
  'white-bg': !noBg
12
12
  }"
13
+ :id="`ky-tab-wrap-${id}`"
13
14
  class="ky-tab-wrap"
14
15
  >
15
- <view id="ky-tab-parent" class="ky-tab-components">
16
+ <view class="ky-tab-components">
16
17
  <view class="ky-tab-box">
17
18
  <view
18
19
  v-for="(tab, i) in menu"
@@ -21,14 +22,14 @@
21
22
  :class="{ active: i === tabIndex, icon: tab.icon }"
22
23
  :id="'ky_tab_'+i"
23
24
  class="ky-tab-item"
24
- @click="onTabClick(tab, i)"
25
+ @click="onTabClick(i)"
25
26
  >
26
27
  <text v-if="tab.icon" class="ky-tab-icon iconfont">{{ tab.icon }}</text>
27
28
  <text class="ky-tab-text">{{ tab[label] }}</text>
28
29
  </view>
29
30
  </view>
30
31
  <view
31
- v-if="tabItemWidth > 0 && !hasIcon"
32
+ v-if="tabItemWidth > 0"
32
33
  :style="{
33
34
  left: tabItemOffsetLeft + 'px',
34
35
  width: tabItemWidth + 'px',
@@ -47,6 +48,10 @@
47
48
  emits: ['update:value', 'change'],
48
49
  props: {
49
50
  // 显示字体图标传入icon: '\'
51
+ id: {
52
+ type: [String, Number],
53
+ default: 1
54
+ },
50
55
  menu: {
51
56
  type: Array,
52
57
  default: () => [],
@@ -104,55 +109,48 @@
104
109
  tabItemOffsetLeft: 0,
105
110
  tabItemWidth: 0,
106
111
  tabItemHeight: 2,
107
- tabIndex: 0,
112
+ tabIndex: -1,
108
113
  }
109
114
  },
110
115
  watch: {
111
116
  value(v) {
112
- this.tabIndex = v
117
+ this.onTabClick(v)
113
118
  }
114
119
  },
115
120
  computed: {
116
- hasIcon() {
117
- return this.menu.find(e => e.icon)
118
- },
119
121
  $safeBottom() {
120
122
  return uni.getSystemInfoSync().safeAreaInsets.bottom
121
123
  }
122
124
  },
123
125
  mounted() {
124
- if (!this.hasIcon) {
125
- this.onTabClick(this.menu[this.index], this.index)
126
- } else {
127
- this.tabIndex = typeof this.value !== 'undefined' ? this.value : this.index
128
- }
126
+ this.onTabClick(typeof this.value !== 'undefined' ? this.value : this.index)
129
127
  },
130
128
  methods: {
131
- onTabClick(item, index) {
129
+ onTabClick(index) {
130
+ console.log('当前索引:', index)
132
131
  if (this.disabled) {
133
132
  return
134
133
  }
135
- if (this.hasIcon) {
136
- this.tabIndex = index
137
- this.$emit('change', index)
138
- this.$emit('update:value', index)
139
- return
140
- }
141
- const query = uni.createSelectorQuery().in(this)
142
- const parent = query.select(`#ky_tab_${index}`)
143
- parent.boundingClientRect(data => {
144
- this.tabItemWidth = data.width
145
- this.tabItemOffsetLeft = data.left
146
- if (this.type === 'card') {
147
- this.tabItemHeight = data.height
148
- }
149
- if (this.tabIndex === index) {
150
- return
151
- }
152
- this.tabIndex = index
153
- this.$emit('change', index)
154
- this.$emit('update:value', index)
155
- }).exec()
134
+ if (this.tabIndex === index) {
135
+ return
136
+ }
137
+ this.$nextTick(() => {
138
+ const query = uni.createSelectorQuery().in(this)
139
+ query.select(`#ky-tab-wrap-${this.id}`).boundingClientRect()
140
+ query.select(`#ky_tab_${index}`).boundingClientRect()
141
+ query.exec(data => {
142
+ const parent = data[0]
143
+ const tab = data[1]
144
+ this.tabItemWidth = tab.width
145
+ this.tabItemOffsetLeft = tab.left - parent.left
146
+ if (this.type === 'card') {
147
+ this.tabItemHeight = tab.height
148
+ }
149
+ })
150
+ })
151
+ this.tabIndex = index
152
+ this.$emit('change', index)
153
+ this.$emit('update:value', index)
156
154
  }
157
155
  }
158
156
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "locale"
10
10
  ],
11
11
  "description": "an uniapp ui",
12
- "version": "1.1.12",
12
+ "version": "1.1.14",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/yezipi/ky-uniui.git"