From 9a0f240c9b79fd32a5f104bdddc2d2c45e170af6 Mon Sep 17 00:00:00 2001 From: yanyan Date: Mon, 22 Jan 2024 10:21:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8F=8A=E6=88=91=E7=9A=84=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/my-login/my-login.vue | 106 +++++++++++++ components/my-search/my-search.vue | 74 +++++++++ components/my-userinfo/my-userinfo.vue | 183 +++++++++++++++++++++++ main.js | 5 +- mixins/tabbar-badge.js | 23 +++ pages.json | 19 ++- pages/index/index.vue | 31 ++-- pages/my/my.vue | 198 ++++++++++++++++++++++++- pages/scan/scan.vue | 17 +++ store/store.js | 15 ++ store/user.js | 56 +++++++ subpkg/list/list.vue | 126 ++++++++++++++++ 12 files changed, 835 insertions(+), 18 deletions(-) create mode 100755 components/my-login/my-login.vue create mode 100755 components/my-search/my-search.vue create mode 100755 components/my-userinfo/my-userinfo.vue create mode 100755 mixins/tabbar-badge.js create mode 100644 store/store.js create mode 100755 store/user.js create mode 100644 subpkg/list/list.vue diff --git a/components/my-login/my-login.vue b/components/my-login/my-login.vue new file mode 100755 index 0000000..90e7bdc --- /dev/null +++ b/components/my-login/my-login.vue @@ -0,0 +1,106 @@ + + + + + diff --git a/components/my-search/my-search.vue b/components/my-search/my-search.vue new file mode 100755 index 0000000..45d1870 --- /dev/null +++ b/components/my-search/my-search.vue @@ -0,0 +1,74 @@ + + + + + diff --git a/components/my-userinfo/my-userinfo.vue b/components/my-userinfo/my-userinfo.vue new file mode 100755 index 0000000..7c273a4 --- /dev/null +++ b/components/my-userinfo/my-userinfo.vue @@ -0,0 +1,183 @@ + + + + + diff --git a/main.js b/main.js index 31b1016..5bb89f4 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ // #ifndef VUE3 import Vue from 'vue' import App from './App' +import store from '@/store/store.js' //导入网络请求的包 import {$http} from '@escook/request-miniprogram' @@ -16,6 +17,7 @@ $http.beforeRequest = function(options) { }) } + $http.afterRequest = function(options) { uni.hideLoading() } @@ -33,7 +35,8 @@ Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ - ...App + ...App, + store }) app.$mount() // #endif diff --git a/mixins/tabbar-badge.js b/mixins/tabbar-badge.js new file mode 100755 index 0000000..d89dcad --- /dev/null +++ b/mixins/tabbar-badge.js @@ -0,0 +1,23 @@ +import { mapGetters } from 'vuex' + +export default { + computed: { + ...mapGetters('m_cart', ['total']) + }, + watch: { + total() { + this.setBadge() + } + }, + onShow() { + this.setBadge() + }, + methods: { + setBadge() { + uni.setTabBarBadge({ + index: 2, + text: this.total + '' + }) + } + } +} diff --git a/pages.json b/pages.json index e10c702..07da6f8 100644 --- a/pages.json +++ b/pages.json @@ -20,7 +20,8 @@ "style" : { "navigationBarTitleText" : "全民演练", - "enablePullDownRefresh" : false + "enablePullDownRefresh" : false, + "navigationStyle": "custom" } }, { @@ -31,6 +32,22 @@ "enablePullDownRefresh" : false } }], + "subPackages": [ + { + "root": "subpkg", + "pages": [ + { + "path": "list/list", + "style" : + { + "navigationBarTitleText" : "场景演练", + "navigationBarTextStyle": "black", + "enablePullDownRefresh" : false + } + } + ] + } + ], "globalStyle": { "navigationBarTextStyle": "white", "navigationBarTitleText": "全民演练", diff --git a/pages/index/index.vue b/pages/index/index.vue index f252c4f..96cfad6 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -6,16 +6,13 @@ - - + @@ -28,6 +25,8 @@ return { //顶部图片 topImg: "", + leftImg: "", + rightImg: "", //轮播图数据列表 swiperList: [], //场景入口 @@ -43,22 +42,30 @@ const { data: res - } = await uni.$http.post('/small/customImage/listAll') + } = await uni.$http.post('/small/customImage/listAll',{page:'home'}) if (!res.success) return uni.$showMsg() res.data.forEach(item=>{ - item.uploadPath = 'http://localhost:85' +item.uploadPath + item.uploadPath = uni.$http.baseUrl +item.uploadPath if (item.position === "top"){ this.topImg = item.uploadPath - } else if(item.position === "middle"){ + } else if(item.position.indexOf("banner") !=-1){ this.swiperList.push(item.uploadPath) - } else if(item.position === "bottom"){ - this.sceneList.push(item.uploadPath) + } else if(item.position.indexOf("bottom-left") !=-1){ + this.leftImg = item.uploadPath + } else if(item.position.indexOf("bottom-right") !=-1){ + this.rightImg = item.uploadPath } }) - + this.sceneList.push(this.leftImg) + this.sceneList.push(this.rightImg) uni.$showMsg('数据请求成功!') }, + navClickHandler(item) { + uni.navigateTo({ + url: '/subpkg/list/list' + }) + }, } } @@ -66,13 +73,13 @@ + diff --git a/pages/scan/scan.vue b/pages/scan/scan.vue index 6cc1cbf..3740b45 100644 --- a/pages/scan/scan.vue +++ b/pages/scan/scan.vue @@ -6,10 +6,27 @@ diff --git a/store/store.js b/store/store.js new file mode 100644 index 0000000..f212b44 --- /dev/null +++ b/store/store.js @@ -0,0 +1,15 @@ +import Vue from 'vue' +import Vuex from 'vuex' +import moduleUser from '@/store/user.js' + +Vue.use(Vuex) + +const store = new Vuex.Store({ + modules: { + // 挂载用户的 vuex 模块,模块内成员的访问路径被调整为 m_user,例如: + // 用户模块中 user 数组的访问路径是 m_user/user + 'm_user': moduleUser + } +}) + +export default store diff --git a/store/user.js b/store/user.js new file mode 100755 index 0000000..f82e50e --- /dev/null +++ b/store/user.js @@ -0,0 +1,56 @@ +export default { + // 开启命名空间 + namespaced: true, + + // 数据 + state: () => ({ + address: JSON.parse(uni.getStorageSync('address') || '{}'), + token: uni.getStorageSync('token') || '', + // 用户的信息对象 + userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'), + // 重定向的 Object 对象 + redirectInfo: null + }), + + // 方法 + mutations: { + // 更新收货地址 + updateAddress(state, address) { + state.address = address + + this.commit('m_user/saveAddressToStorage') + }, + // 持久化存储 address + saveAddressToStorage(state) { + uni.setStorageSync('address', JSON.stringify(state.address)) + }, + updateUserInfo(state, userinfo) { + state.userinfo = userinfo + + this.commit('m_user/saveUserInfoToStorage') + }, + saveUserInfoToStorage(state) { + uni.setStorageSync('userinfo', JSON.stringify(state.userinfo)) + }, + updateToken(state, token) { + state.token = token + this.commit('m_user/saveTokenToStorage') + }, + saveTokenToStorage(state) { + uni.setStorageSync('token', state.token) + }, + updateRedirectInfo(state, info) { + state.redirectInfo = info + console.log(state.redirectInfo) + } + }, + + getters: { + // 收货地址 + addstr(state) { + if (!state.address.provinceName) return '' + + return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo + } + } +} diff --git a/subpkg/list/list.vue b/subpkg/list/list.vue new file mode 100644 index 0000000..2fc01d0 --- /dev/null +++ b/subpkg/list/list.vue @@ -0,0 +1,126 @@ + + + + +