wpTabbar.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <view>
  4. <scroll-view scroll-y="true" scroll-with-animation :style="{'height':height+'px'}">
  5. <home v-if="pagePath === '/pages/home/index'"></home>
  6. <integral v-if="pagePath === '/pages/integral/index'"></integral>
  7. <orderFood v-if="pagePath === '/pages/orderFood/index'"></orderFood>
  8. <app v-if="pagePath === '/pages/app/index'"></app>
  9. <user @setType="setType" v-if="pagePath === '/pages/user/index'"></user>
  10. </scroll-view>
  11. </view>
  12. <view id="MyDom" class="wpTabBar" style="background-color: #f6f6f6;">
  13. <view v-for="(item,index) in tabBarList" class="wp-tab-item" :key="index" @click="tabBarChange(item.url)"
  14. :style="{'width':tabWidth}">
  15. <view v-if="item.url === '/pages/app/index'" style="line-height: 0%;">
  16. <image style="width:90rpx;" v-if="item.url === pagePath" :src="item.selectIcon" mode="aspectFill">
  17. </image>
  18. <image style="width:90rpx;" v-else :src="item.icon" mode="aspectFill"></image>
  19. </view>
  20. <view v-else style="line-height: 0%;">
  21. <image v-if="item.url === pagePath" :src="item.selectIcon" mode="aspectFill"></image>
  22. <image v-else :src="item.icon" mode="aspectFill"></image>
  23. </view>
  24. <view class="wp-tab-title">{{item.name}}
  25. <view v-if="msgNums[index] > 0" class="hs-hzl-count count">
  26. {{msgNums[index]}}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. var begin;
  35. var stop;
  36. import home from '../../pages/home/index'
  37. import app from '../../pages/app/index'
  38. import orderFood from '../../pages/orderFood/index'
  39. import integral from '../../pages/integral/index'
  40. import user from '../../pages/user/index'
  41. export default {
  42. name: "wp-tabbar",
  43. components: {
  44. home,
  45. app,
  46. integral,
  47. orderFood,
  48. user
  49. },
  50. props: {
  51. i: {
  52. type: Array,
  53. default: [0, 0, 0, 0]
  54. }
  55. },
  56. data() {
  57. return {
  58. data: [],
  59. pagePath: '/pages/home/index',
  60. type: 0,
  61. msgNums: [0, 0, 0, 0],
  62. clearItem1: null,
  63. clearItem2: null,
  64. clearItem3: null,
  65. tabBarList: [],
  66. tabBarListDefault: [{
  67. name: "首页", // name
  68. icon: "../../static/img/tab-icon/home.png", // 图标
  69. selectIcon: "../../static/img/tab-icon/home-active.png", // 选中图标
  70. url: "/pages/home/index", // 页面路径
  71. }, {
  72. name: "预定",
  73. icon: "../../static/img/tab-icon/order-food.png",
  74. selectIcon: "../../static/img/tab-icon/order-food-active.png",
  75. url: "/pages/orderFood/index",
  76. }, {
  77. name: "积分",
  78. icon: "../../static/img/tab-icon/shop.png",
  79. selectIcon: "../../static/img/tab-icon/shop-active.png",
  80. url: "/pages/integral/index",
  81. }, {
  82. name: "我的",
  83. icon: "../../static/img/tab-icon/me.png",
  84. selectIcon: "../../static/img/tab-icon/me-active.png",
  85. url: "/pages/user/index",
  86. }],
  87. // tabbar 栏
  88. tabBarListML: [{
  89. name: "首页", // name
  90. icon: "../../static/img/tab-icon/home.png", // 图标
  91. selectIcon: "../../static/img/tab-icon/home-active.png", // 选中图标
  92. url: "/pages/home/index", // 页面路径
  93. }, {
  94. name: "预定",
  95. icon: "../../static/img/tab-icon/order-food.png",
  96. selectIcon: "../../static/img/tab-icon/order-food-active.png",
  97. url: "/pages/orderFood/index",
  98. }, {
  99. name: "应用",
  100. icon: "../../static/img/tab-icon/app.png",
  101. selectIcon: "../../static/img/tab-icon/app-active.png",
  102. url: "/pages/app/index",
  103. }, {
  104. name: "我的",
  105. icon: "../../static/img/tab-icon/me.png",
  106. selectIcon: "../../static/img/tab-icon/me-active.png",
  107. url: "/pages/user/index",
  108. }],
  109. tabBarListHSKJ: [{
  110. name: "首页", // name
  111. icon: "../../static/img/tab-icon/home.png", // 图标
  112. selectIcon: "../../static/img/tab-icon/home-active.png", // 选中图标
  113. url: "/pages/home/index", // 页面路径
  114. }, {
  115. name: "应用",
  116. icon: "../../static/img/tab-icon/app.png",
  117. selectIcon: "../../static/img/tab-icon/app-active.png",
  118. url: "/pages/app/index",
  119. }, {
  120. name: "我的",
  121. icon: "../../static/img/tab-icon/me.png",
  122. selectIcon: "../../static/img/tab-icon/me-active.png",
  123. url: "/pages/user/index",
  124. }],
  125. tabWidth: '25%',
  126. height: 0
  127. }
  128. },
  129. beforeDestroy() {
  130. // uni.setStorageSync('refreshStart', 1)
  131. clearInterval(this.clearItem1)
  132. clearInterval(this.clearItem3)
  133. },
  134. onLoad() {
  135. this.initView()
  136. uni.hideTabBar()
  137. clearInterval(this.clearItem1)
  138. clearInterval(this.clearItem3)
  139. let that = this
  140. this.data = this.tabBarList
  141. this.clearItem3 = setInterval(() => {
  142. that.setMark()
  143. }, 500);
  144. let mydomHeight
  145. uni.createSelectorQuery().in(this)
  146. .select('#MyDom')
  147. .boundingClientRect(data => {
  148. mydomHeight = data.height
  149. uni.setStorageSync('mydomHeight', mydomHeight)
  150. uni.getSystemInfo({
  151. success: res => {
  152. uni.setStorageSync('windowHeight', res.windowHeight)
  153. that.height = res.windowHeight - uni.getStorageSync('mydomHeight')
  154. }
  155. })
  156. })
  157. .exec();
  158. },
  159. onShow() {
  160. this.type = uni.getStorageSync("tabType")
  161. },
  162. onHide() {},
  163. methods: {
  164. initView() {
  165. let tabType = uni.getStorageSync('tabType')
  166. if (tabType == 2) {
  167. this.tabWidth = '25%'
  168. this.tabBarList = this.tabBarListDefault
  169. } else if (tabType == 3) {
  170. this.tabWidth = '25%'
  171. this.tabBarList = this.tabBarListML
  172. } else if (tabType == 4) {
  173. this.tabWidth = '33.33%'
  174. this.tabBarList = this.tabBarListHSKJ
  175. } else {
  176. this.tabWidth = '25%'
  177. this.tabBarList = this.tabBarListDefault
  178. }
  179. },
  180. setType(type) {
  181. this.type = type
  182. this.initView()
  183. this.$forceUpdate()
  184. },
  185. tabBarChange(path) {
  186. this.toSwitchTab(path)
  187. uni.hideTabBar()
  188. },
  189. async testSend() {
  190. const {
  191. data: res
  192. } = await this.$httpRequest({
  193. url: '/app/sendTestMsg',
  194. method: 'get',
  195. urlType: this.$getUrlType()
  196. })
  197. if (res.code == 200) {
  198. }
  199. },
  200. async msgs() {
  201. const {
  202. data: res
  203. } = await this.$httpRequest({
  204. url: '/app/msgs',
  205. method: 'get',
  206. urlType: this.$getUrlType()
  207. })
  208. if (res.code == 200) {
  209. uni.removeStorageSync("tabMark")
  210. uni.removeStorageSync("msgMarkSum")
  211. uni.setStorageSync("tabMark", res.data)
  212. uni.setStorageSync("msgMarkSum", res.data.sum)
  213. }
  214. },
  215. sendSocketMessage(msg) {
  216. uni.sendSocketMessage({
  217. data: msg
  218. });
  219. },
  220. setMark() {
  221. let data = uni.getStorageSync("msgData")
  222. if (!data) {
  223. this.msgNums = []
  224. return
  225. }
  226. data = JSON.parse(data)
  227. let appSum = data.m1 + data.m2 + data.m3 + data.m4 + data.m5 + data.m6 + data.m7 + data.m8 + data.m9
  228. // this.msgNums = []
  229. let mData = []
  230. mData.push(appSum)
  231. mData.push(0)
  232. if (this.$getUrlType() === 3) {
  233. mData.push(data.m1 + data.m3 + data.m4 + data.m5 + data.m7+ data.m8)
  234. } else {
  235. mData.push(0)
  236. }
  237. mData.push(0)
  238. this.msgNums = mData
  239. },
  240. async toSwitchTab(path) {
  241. this.pagePath = path
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .wpTabBar {
  248. width: 100%;
  249. height: 130rpx;
  250. display: flex;
  251. flex-wrap: wrap;
  252. position: fixed;
  253. left: 0;
  254. bottom: 0;
  255. padding-top: 20rpx;
  256. padding-bottom: 30rpx;
  257. .wp-tab-item {
  258. width: 33.3%;
  259. display: flex;
  260. flex-direction: column;
  261. align-items: center;
  262. .wp-tab-title {
  263. position: relative;
  264. color: #9d9d9d;
  265. }
  266. image {
  267. width: 50rpx;
  268. height: 50rpx;
  269. padding: 0 10rpx;
  270. }
  271. }
  272. }
  273. .count {
  274. bottom: 75rpx;
  275. left: 40rpx;
  276. font-size: 22rpx;
  277. padding: 0 0 3rpx 3rpx;
  278. }
  279. </style>