index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view>
  3. <view :style="{height:footHeight+'px'}"></view>
  4. <view v-if="newData.bgColor">
  5. <view class="page-footer" id="target" :style="{'background-color':newData.bgColor.color[0].item}">
  6. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index" @click="goRouter(item)">
  7. <block v-if="item.link == activeRouter">
  8. <image :src="item.imgList[0]"></image>
  9. <view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{item.name}}</view>
  10. </block>
  11. <block v-else>
  12. <image :src="item.imgList[1]"></image>
  13. <view class="txt" :style="{color:newData.txtColor.color[0].item}">{{item.name}}</view>
  14. </block>
  15. <div class="count-num"
  16. v-if="item.link === '/pages/order_addcart/order_addcart' && $store.state.indexData.cartNum && $store.state.indexData.cartNum>0">
  17. {{$store.state.indexData.cartNum}}
  18. </div>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. mapState,
  27. mapGetters
  28. } from "vuex"
  29. import {
  30. getNavigation
  31. } from '@/api/public.js'
  32. import {
  33. getCartCounts,
  34. } from '@/api/order.js';
  35. export default {
  36. name: 'pageFooter',
  37. props: {
  38. noTop: {
  39. type: Boolean,
  40. default: true
  41. },
  42. status: {
  43. type: Number | String,
  44. default: 1
  45. },
  46. countNum: {
  47. type: Number | String,
  48. default: 0
  49. },
  50. },
  51. computed: {
  52. ...mapState({
  53. configData: state => state.app.pageFooter
  54. })
  55. },
  56. computed: mapGetters(['isLogin', 'cartNum']),
  57. watch: {
  58. configData: {
  59. handler(nVal, oVal) {
  60. let self = this
  61. const query = uni.createSelectorQuery().in(this);
  62. this.newData = nVal
  63. this.$nextTick(() => {
  64. query.select('#target').boundingClientRect(data => {
  65. uni.$emit('footHeight', data.height)
  66. if (data) {
  67. self.footHeight = data.height + 50
  68. }
  69. }).exec();
  70. })
  71. },
  72. deep: true
  73. },
  74. cartNum(a, b) {
  75. this.$store.commit('indexData/setCartNum', a + '')
  76. if (a > 0) {
  77. uni.setTabBarBadge({
  78. index: Number(uni.getStorageSync('FOOTER_ADDCART')),
  79. text: a + ''
  80. })
  81. } else {
  82. wx.hideTabBarRedDot({
  83. index: Number(uni.getStorageSync('FOOTER_ADDCART'))
  84. })
  85. }
  86. }
  87. },
  88. created() {
  89. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  90. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  91. this.activeRouter = '/' + curRoute
  92. },
  93. onShow() {
  94. let res = {
  95. "name": "pageFoot",
  96. "setUp": {
  97. "tabVal": 0
  98. },
  99. "status": {
  100. "title": "是否自定义",
  101. "name": "status",
  102. "status": true
  103. },
  104. "txtColor": {
  105. "title": "文字颜色",
  106. "name": "txtColor",
  107. "default": [
  108. {
  109. "item": "#282828"
  110. }
  111. ],
  112. "color": [
  113. {
  114. "item": "rgba(51,51,51,1)"
  115. }
  116. ]
  117. },
  118. "activeTxtColor": {
  119. "title": "选中文字颜色",
  120. "name": "txtColor",
  121. "default": [
  122. {
  123. "item": "#F62C2C"
  124. }
  125. ],
  126. "color": [
  127. {
  128. "item": "rgba(29,176,252,1)"
  129. }
  130. ]
  131. },
  132. "bgColor": {
  133. "title": "背景颜色",
  134. "name": "bgColor",
  135. "default": [
  136. {
  137. "item": "#fff"
  138. }
  139. ],
  140. "color": [
  141. {
  142. "item": "#fff"
  143. }
  144. ]
  145. },
  146. "menuList": [
  147. {
  148. "imgList": [
  149. "https://qiniu.crmeb.net/attach/2021/11/bdf25202111181452426458.png",
  150. "https://qiniu.crmeb.net/attach/2021/11/aaf1b202111181452576658.png"
  151. ],
  152. "name": "首页",
  153. "link": "/pages/index/index"
  154. },
  155. {
  156. "imgList": [
  157. "https://demo26.crmeb.net/uploads/attach/2022/09/20220923/14367a2fecd502f51978ed6ea09afe19.png",
  158. "https://qiniu.crmeb.net/attach/2021/11/59d4a202111181453208678.png"
  159. ],
  160. "name": "分类",
  161. "link": "/pages/goods_cate/goods_cate"
  162. },
  163. {
  164. "imgList": [
  165. "https://qiniu.crmeb.net/attach/2021/11/076ac202111181453294517.png",
  166. "https://qiniu.crmeb.net/attach/2021/11/201c9202111181453378599.png"
  167. ],
  168. "name": "购物车",
  169. "link": "/pages/order_addcart/order_addcart"
  170. },
  171. {
  172. "imgList": [
  173. "https://qiniu.crmeb.net/attach/2021/11/f04cf20211118145343755.png",
  174. "https://qiniu.crmeb.net/attach/2021/11/3a141202111181453495771.png"
  175. ],
  176. "name": "我的",
  177. "link": "/pages/user/index"
  178. }
  179. ],
  180. "id": "idundefined"
  181. }
  182. // getNavigation().then(res => {
  183. this.newData = res
  184. uni.setStorageSync('pageFoot', newData)
  185. this.$store.commit('FOOT_UPLOAD', newData)
  186. if (this.newData.status && this.newData.status.status) {
  187. uni.hideTabBar()
  188. } else {
  189. uni.showTabBar()
  190. }
  191. // })
  192. // getNavigation().then(res => {
  193. // uni.setStorageSync('pageFoot', res.data)
  194. // this.$store.commit('FOOT_UPLOAD', res.data)
  195. // this.newData = res.data
  196. // if (this.newData.status && this.newData.status.status) {
  197. // uni.hideTabBar()
  198. // } else {
  199. // uni.showTabBar()
  200. // }
  201. // })
  202. },
  203. mounted() {
  204. let that = this
  205. this.newData = this.$store.state.app.pageFooter
  206. if (this.newData.status && this.newData.status.status) {
  207. uni.hideTabBar()
  208. } else {
  209. uni.showTabBar()
  210. }
  211. console.log(this.newData)
  212. if (this.isLogin) {
  213. this.getCartNum()
  214. }
  215. },
  216. data() {
  217. return {
  218. newData: {},
  219. activeRouter: '/',
  220. footHeight: 0
  221. }
  222. },
  223. methods: {
  224. goRouter(item) {
  225. var pages = getCurrentPages();
  226. if (pages.length) {
  227. var page = (pages[pages.length - 1]).$page.fullPath;
  228. } else {
  229. page = ''
  230. }
  231. if (item.link == page) return
  232. uni.switchTab({
  233. url: item.link,
  234. fail(err) {
  235. uni.redirectTo({
  236. url: item.link
  237. })
  238. }
  239. })
  240. },
  241. getCartNum: function() {
  242. let that = this;
  243. getCartCounts().then(res => {
  244. that.cartCount = res.data.count;
  245. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '...' : res.data.count)
  246. });
  247. },
  248. }
  249. }
  250. </script>
  251. <style lang="scss" scoped>
  252. .page-footer {
  253. position: fixed;
  254. bottom: 0;
  255. z-index: 30;
  256. display: flex;
  257. align-items: center;
  258. justify-content: space-around;
  259. width: 100%;
  260. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  261. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  262. box-sizing: border-box;
  263. border-top: solid 1rpx #F3F3F3;
  264. background-color: #fff;
  265. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  266. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  267. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  268. .foot-item {
  269. display: flex;
  270. width: max-content;
  271. align-items: center;
  272. justify-content: center;
  273. flex-direction: column;
  274. position: relative;
  275. .count-num {
  276. position: absolute;
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. width: 40rpx;
  281. height: 40rpx;
  282. top: 0rpx;
  283. right: -15rpx;
  284. color: #fff;
  285. font-size: 20rpx;
  286. background-color: #FD502F;
  287. border-radius: 50%;
  288. padding: 4rpx;
  289. }
  290. }
  291. .foot-item image {
  292. height: 50rpx;
  293. width: 50rpx;
  294. text-align: center;
  295. margin: 0 auto;
  296. }
  297. .foot-item .txt {
  298. font-size: 24rpx;
  299. &.active {}
  300. }
  301. }
  302. </style>