From 6d62e111b5879d0f1fa44a430280192f49ec3c69 Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Mon, 9 Dec 2024 14:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api.js | 52 +- api/http.js | 5 +- api/model/login.js | 39 ++ components/base/navbar.vue | 30 +- components/base/tabbar.vue | 2 +- components/config/configPopup.vue | 3 + components/config/customerServicePopup.vue | 28 +- main.js | 4 + mixins/configList.js | 43 ++ pages/index/category.vue | 12 +- pages/index/center.vue | 4 +- pages_order/auth/wxLogin.vue | 12 +- pages_order/auth/wxUserInfo.vue | 2 +- pages_order/components/address/addressList.vue | 1 - pages_order/mine/help.vue | 79 ++- pages_order/order/refundsOrExchange.vue | 696 ++++++++++++------------- store/store.js | 24 +- uni.scss | 20 + utils/index.js | 19 +- utils/oss-upload/oss/index.js | 12 +- utils/oss-upload/oss/web.js | 2 +- utils/position.js | 4 +- utils/utils.js | 22 +- 23 files changed, 670 insertions(+), 445 deletions(-) create mode 100644 api/model/login.js create mode 100644 mixins/configList.js diff --git a/api/api.js b/api/api.js index 871475a..9301696 100644 --- a/api/api.js +++ b/api/api.js @@ -1,9 +1,12 @@ import http from './http.js' +import utils from '../utils/utils.js' let limit = {} let debounce = {} +const models = [] + const config = { // 示例 // wxLogin : {url : '/api/wxLogin', method : 'POST', @@ -12,42 +15,14 @@ const config = { // }, getConfig : {url : '/api/getConfig', method : 'GET', limit : 500}, - - - // 微信登录接口 - wxLogin: { - url: '/login/login', - method: 'POST', - limit : 500, - showLoading : true, - }, - // 修改个人信息接口 - updateInfo: { - url: '/info/updateInfo', - method: 'POST', - auth: true, - limit : 500, - showLoading : true, - }, - //隐私政策 - getPrivacyPolicy: { - url: '/login/getPrivacyPolicy', - method: 'GET', - }, - //用户协议 - getUserAgreement: { - url: '/login/getUserAgreement', - method: 'GET', - }, } - export function api(key, data, callback, loadingTitle) { let req = config[key] if (!req) { - console.error('无效key' + key); + console.error('无效key--------' + key); return } @@ -73,9 +48,7 @@ export function api(key, data, callback, loadingTitle) { //必须登录 if (req.auth) { if (!uni.getStorageSync('token')) { - uni.navigateTo({ - url: '/pages_order/auth/wxLogin' - }) + utils.toLogin() console.error('需要登录') return } @@ -110,4 +83,19 @@ export function api(key, data, callback, loadingTitle) { +function addApiModel(model, key){ + for(let k in model){ + if(config[`${k}`]){ + console.error(`重名api------model=${key},key=${k}`); + continue + } + config[`${k}`] = model[k] + // config[`${key}_${k}`] = model[k] + } +} + +models.forEach(key => { + addApiModel(require(`./model/${key}.js`).default, key) +}) + export default api \ No newline at end of file diff --git a/api/http.js b/api/http.js index 8f7078e..3c18457 100644 --- a/api/http.js +++ b/api/http.js @@ -1,5 +1,6 @@ import Vue from 'vue' +import utils from '../utils/utils.js' function http(uri, data, callback, method = 'GET', showLoading, title) { @@ -29,9 +30,7 @@ function http(uri, data, callback, method = 'GET', showLoading, title) { res.data.message == '操作失败,用户不存在!'){ uni.removeStorageSync('token') console.error('登录过期'); - uni.navigateTo({ - url: '/pages_order/auth/wxLogin' - }) + utils.toLogin() } if(res.statusCode == 200 && res.data.code != 200){ diff --git a/api/model/login.js b/api/model/login.js new file mode 100644 index 0000000..cb3cbc8 --- /dev/null +++ b/api/model/login.js @@ -0,0 +1,39 @@ + + +// 登录相关接口 + +const api = { + // 微信登录接口 + wxLogin: { + url: '/login_common/appletLogin', + method: 'GET', + limit : 500, + showLoading : true, + }, + // 修改个人信息接口 + updateInfo: { + url: '/info_common/updateInfo', + method: 'POST', + auth: true, + limit : 500, + showLoading : true, + }, + // 获取个人信息 + getInfo: { + url: '/info_common/getInfo', + method: 'GET', + auth: true, + }, + //隐私政策 + getPrivacyPolicy: { + url: '/login/getPrivacyPolicy', + method: 'GET', + }, + //用户协议 + getUserAgreement: { + url: '/login/getUserAgreement', + method: 'GET', + }, +} + +export default api \ No newline at end of file diff --git a/components/base/navbar.vue b/components/base/navbar.vue index 909f33c..49636c4 100644 --- a/components/base/navbar.vue +++ b/components/base/navbar.vue @@ -2,27 +2,33 @@ + :style="{backgroundColor : bgColor,color}"> + + + + :color="color" size="46rpx"> {{ title }} + :color="color" size="58rpx"> - - @@ -64,6 +70,9 @@ }, bgColor : { default : '#fff' + }, + color : { + default : '#333' } }, created() { @@ -72,9 +81,18 @@ }, data() { return { + length : getCurrentPages().length }; }, methods : { + toHome(){ + if(this.length != 1){ + return + } + uni.reLaunch({ + url: '/pages/index/index' + }) + } } } diff --git a/components/base/tabbar.vue b/components/base/tabbar.vue index 732e9ef..ad879c9 100644 --- a/components/base/tabbar.vue +++ b/components/base/tabbar.vue @@ -72,7 +72,7 @@ if(index == this.select){ return } - uni.redirectTo({ + uni.reLaunch({ url: item.pagePath }) }, diff --git a/components/config/configPopup.vue b/components/config/configPopup.vue index 4f70dd3..ef2d21c 100644 --- a/components/config/configPopup.vue +++ b/components/config/configPopup.vue @@ -40,6 +40,9 @@ .configPopup { .content{ padding: 30rpx 20rpx; + overflow: scroll; + height: 100%; + box-sizing: border-box; } } \ No newline at end of file diff --git a/components/config/customerServicePopup.vue b/components/config/customerServicePopup.vue index d2d73a6..4937467 100644 --- a/components/config/customerServicePopup.vue +++ b/components/config/customerServicePopup.vue @@ -1,10 +1,12 @@ \ No newline at end of file diff --git a/store/store.js b/store/store.js index 7c3e47c..f9b701f 100644 --- a/store/store.js +++ b/store/store.js @@ -8,7 +8,7 @@ import api from '@/api/api.js' //Vuex.Store 构造器选项 const store = new Vuex.Store({ state: { - configList: [], //配置列表 + configList: {}, //配置列表 shop : false, userInfo : {}, //用户信息 }, @@ -24,6 +24,10 @@ const store = new Vuex.Store({ // api('getConfig', res => { // if(res.code == 200){ // state.configList = res.result + + // res.result.forEach(n => { + // state.configList[n.keyName] = n.keyContent + // }) // } // }) @@ -71,12 +75,28 @@ const store = new Vuex.Store({ }) }, getUserInfo(state){ - api('infoGetInfo', res => { + api('getInfo', res => { if(res.code == 200){ state.userInfo = res.result } }) }, + // 退出登录 + logout(state){ + uni.showModal({ + title: '确认退出登录吗', + success(r) { + if(r.confirm){ + state.userInfo = {} + state.role = false + uni.removeStorageSync('token') + uni.reLaunch({ + url: '/pages/index/index' + }) + } + } + }) + }, }, actions: {}, }) diff --git a/uni.scss b/uni.scss index 6e2d4c6..5dcc31f 100644 --- a/uni.scss +++ b/uni.scss @@ -74,3 +74,23 @@ $uni-color-subtitle: #555555; // 二级标题颜色 $uni-font-size-subtitle:26px; $uni-color-paragraph: #3F536E; // 文章段落颜色 $uni-font-size-paragraph:15px; + + +.uni-color-btn{ + border-radius: 40rpx; + padding: 20rpx; + margin: 40rpx; + background: $uni-color; + color: #fff; + text-align: center; + font-size: 28rpx; +} +.uni-uncolor-btn{ + border-radius: 40rpx; + padding: 20rpx; + margin: 40rpx; + border: 1px solid $uni-color; + color: $uni-color; + text-align: center; + font-size: 28rpx; +} \ No newline at end of file diff --git a/utils/index.js b/utils/index.js index b40f098..d98758d 100644 --- a/utils/index.js +++ b/utils/index.js @@ -27,4 +27,21 @@ Vue.prototype.$dayjs = dayjs Vue.prototype.$timeUtils = time Vue.prototype.$utils = util -Vue.prototype.$md5 = md5 \ No newline at end of file +Vue.prototype.$md5 = md5 + + +Vue.prototype.previewImage = (urls, current) => { + uni.previewImage({ + urls, + current, + }) +} +Vue.prototype.openLocation = (latitude, longitude) => { + if(!latitude || !longitude){ + return + } + uni.openLocation({ + latitude : Number(latitude), + longitude : Number(longitude), + }) +} \ No newline at end of file diff --git a/utils/oss-upload/oss/index.js b/utils/oss-upload/oss/index.js index 024eb80..e20f400 100644 --- a/utils/oss-upload/oss/index.js +++ b/utils/oss-upload/oss/index.js @@ -93,9 +93,9 @@ export function ossUploadImage({ count: 1, sizeType, success(res) { - // #ifdef H5 - return uploadFileToOSS(res.tempFiles[0]).then(success).catch(fail) - // #endif + // // #ifdef H5 + // return uploadFileToOSS(res.tempFiles[0]).then(success).catch(fail) + // // #endif ossUpload(res.tempFilePaths[0], key, folder).then(success).catch(fail) }, fail @@ -123,9 +123,9 @@ export function ossUploadVideo({ maxDuration, camera, success(res) { - // #ifdef H5 - return uploadFileToOSS(res.tempFile).then(success).catch(fail) - // #endif + // // #ifdef H5 + // return uploadFileToOSS(res.tempFile).then(success).catch(fail) + // // #endif ossUpload(res.tempFilePath, key, folder).then(success).catch(fail) }, fail diff --git a/utils/oss-upload/oss/web.js b/utils/oss-upload/oss/web.js index dfaab6e..9b419ae 100644 --- a/utils/oss-upload/oss/web.js +++ b/utils/oss-upload/oss/web.js @@ -1,5 +1,5 @@ // 此方法适用于web -import OSS from "ali-oss" +// import OSS from "ali-oss" import config from '@/config.js' /** diff --git a/utils/position.js b/utils/position.js index 09513cd..26210b6 100644 --- a/utils/position.js +++ b/utils/position.js @@ -144,8 +144,8 @@ function getUserAddressByIp(key) { //根据IP获取当前用户位置 //打开地图让用户选择位置 function selectAddress(longitude, latitude, successCallback) { uni.chooseLocation({ - longitude, //经度 - latitude, //纬度 + // longitude, //经度 + // latitude, //纬度 success: function(res) { successCallback && successCallback(res) } diff --git a/utils/utils.js b/utils/utils.js index dabe1e0..2b07dde 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -144,6 +144,12 @@ export function copyText(content) { }) } +// 将字符串中的文本格式化html +export function stringFormatHtml(str){ + return str && str.replace(/\n/gi, '
') + .replace(/ /gi, ' ') +} + function params(url){ if(typeof url == 'object'){ return url @@ -172,6 +178,18 @@ export function navigateBack(num = -1){ export function redirectTo(...args){ uni.redirectTo(params(...args)) } +export const toLogin = function(){ + let time = 0 + return () => { + if(new Date().getTime() - time < 1000){ + return + } + time = new Date().getTime() + uni.navigateTo({ + url: '/pages_order/auth/wxLogin' + }) + } +}() export default { toArray, @@ -185,5 +203,7 @@ export default { navigateTo, navigateBack, redirectTo, - copyText + copyText, + stringFormatHtml, + toLogin } \ No newline at end of file