From 6dbbe576f3891911af2abe66b8c51f6d54c291fb Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Mon, 8 Jan 2024 18:05:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=9C=B0=E5=9D=80=E6=94=B9=E4=B8=BAstore?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86=E5=8F=98=E9=87=8F=E7=9A=84?= =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D=E3=80=82=E6=B6=88=E6=81=AF=E9=A1=B5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=AF=E6=8C=81=E4=B8=8B=E6=8B=89=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/dev.ts | 1 + src/app.config.ts | 15 +- src/app.tsx | 2 - src/custom-tab-bar/index.tsx | 12 +- src/pages/activity/activity.tsx | 2 +- src/pages/detect/detect.tsx | 4 +- src/pages/entry/entry.tsx | 3 +- src/pages/index/index.tsx | 4 +- src/pages/initiate/initiate.tsx | 18 +- src/pages/login/login.tsx | 1 - src/pages/message/message.less | 7 + src/pages/message/message.tsx | 269 ++++++++++++++++++-- src/pages/privacyPolicy/privacyPolicy.less | 7 + src/pages/privacyPolicy/privacyPolicy.tsx | 7 +- src/pages/register/register.tsx | 2 +- src/pages/user/user.tsx | 6 +- src/pages/userInfo/userInfo.tsx | 2 +- src/pages/userInfoDetail/userInfoDetail.tsx | 2 +- src/store/features/global.js | 20 ++ src/store/features/userInfo.js | 2 - src/store/index.js | 2 + src/utils/Interface.js | 18 ++ src/utils/compressImage.js | 109 ++++++++ src/utils/request.js | 33 +-- 24 files changed, 461 insertions(+), 87 deletions(-) create mode 100644 src/store/features/global.js create mode 100644 src/utils/compressImage.js diff --git a/config/dev.ts b/config/dev.ts index 34742cc..d5e257e 100644 --- a/config/dev.ts +++ b/config/dev.ts @@ -5,6 +5,7 @@ module.exports = { defineConstants: { }, mini: { + debugReact: true, webpackChain: (chain, webpack) => { chain.merge({ plugin: { diff --git a/src/app.config.ts b/src/app.config.ts index bd31c05..8523904 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -27,6 +27,12 @@ export default defineAppConfig({ "backgroundColor": "#ffffff", "borderStyle": "black", "list": [ + { + pagePath: "pages/index/index", + text: "主页", + iconPath: "img/tabar/1.png", + selectedIconPath: "img/tabar/11.png", + }, { pagePath: "pages/activity/activity", text: "活动", @@ -39,12 +45,6 @@ export default defineAppConfig({ iconPath: "img/tabar/2.png", selectedIconPath: "img/tabar/22.png", }, - { - pagePath: "pages/index/index", - text: "主页", - iconPath: "img/tabar/1.png", - selectedIconPath: "img/tabar/11.png", - }, { pagePath: "pages/shop/shop", text: "商城", @@ -68,6 +68,7 @@ export default defineAppConfig({ navigationStyle: 'custom', navigationBarBackgroundColor: '#fff', navigationBarTitleText: 'WeChat', - navigationBarTextStyle: 'black' + navigationBarTextStyle: 'black', + // enablePullDownRefresh: true } }) diff --git a/src/app.tsx b/src/app.tsx index e30334b..36b8aa8 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -5,8 +5,6 @@ import "./app.less"; // // html5 // import "@tarojs/taro/html5.css"; -import Taro from "@tarojs/taro"; - import { Provider } from "react-redux"; import store from "./store"; diff --git a/src/custom-tab-bar/index.tsx b/src/custom-tab-bar/index.tsx index 3a11454..990c1b7 100644 --- a/src/custom-tab-bar/index.tsx +++ b/src/custom-tab-bar/index.tsx @@ -16,6 +16,12 @@ export default class Index extends Component { backgroundColor: "#ffffff", borderStyle: "black", list: [ + { + pagePath: "pages/index/index", + text: "主页", + iconPath: "/img/tabar/1.png", + selectedIconPath: "/img/tabar/11.png", + }, { pagePath: "pages/activity/activity", text: "活动", @@ -28,12 +34,6 @@ export default class Index extends Component { iconPath: "/img/tabar/2.png", selectedIconPath: "/img/tabar/22.png", }, - { - pagePath: "pages/index/index", - text: "主页", - iconPath: "/img/tabar/1.png", - selectedIconPath: "/img/tabar/11.png", - }, { pagePath: "pages/shop/shop", text: "商城", diff --git a/src/pages/activity/activity.tsx b/src/pages/activity/activity.tsx index 3306364..5cee0bd 100644 --- a/src/pages/activity/activity.tsx +++ b/src/pages/activity/activity.tsx @@ -33,7 +33,7 @@ export default class Activity extends Component { componentDidShow() { const tabbar = Taro.getTabBar(this.pageCtx); - tabbar?.setSelected(0); + tabbar?.setSelected(1); } componentDidHide() {} diff --git a/src/pages/detect/detect.tsx b/src/pages/detect/detect.tsx index f2b3f74..e0a04e7 100644 --- a/src/pages/detect/detect.tsx +++ b/src/pages/detect/detect.tsx @@ -14,8 +14,6 @@ import { import "taro-ui/dist/style/components/button.scss"; // 按需引入 import "./detect.less"; -const app = Taro.getApp(); - import type CustomTabBar from "../../custom-tab-bar"; export default class Detect extends Component { pageCtx = Taro.getCurrentInstance().page; @@ -33,7 +31,7 @@ export default class Detect extends Component { componentDidShow() { const tabbar = Taro.getTabBar(this.pageCtx); - tabbar?.setSelected(1); + tabbar?.setSelected(2); } componentDidHide() {} diff --git a/src/pages/entry/entry.tsx b/src/pages/entry/entry.tsx index 9a46c9a..40ad8b5 100644 --- a/src/pages/entry/entry.tsx +++ b/src/pages/entry/entry.tsx @@ -68,7 +68,7 @@ export default class Entry extends Component { let list = detail.filter((item: any) => item.fileSuffix === "images"); let welcomeList = list.map((item) => { return { - image: item.fileUrl, + image: item.filePath, title: item.title, desc: item.content, }; @@ -152,6 +152,7 @@ export default class Entry extends Component { style={{ top: menu.top + "px", height: "calc(" + (100 % -menu.height) + "px)", + display: current === index ? "block" : "none", }} > diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index a4f219c..0d2dffb 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -76,7 +76,7 @@ class Index extends Component { componentDidShow() { const tabbar = Taro.getTabBar(this.pageCtx); - tabbar?.setSelected(2); + tabbar?.setSelected(0); this.showInit(); } @@ -128,8 +128,8 @@ class Index extends Component { GetNoReadMessageNum = async () => { let res = await GetNoReadMessageNum(); if (res.data.code === 200) { - console.log("GetNoReadMessageNum", res); Taro.setStorageSync("messageCount", res.data.data); + this.setState({ messagecount: res.data.data }); } }; diff --git a/src/pages/initiate/initiate.tsx b/src/pages/initiate/initiate.tsx index afb7d01..59e25ab 100644 --- a/src/pages/initiate/initiate.tsx +++ b/src/pages/initiate/initiate.tsx @@ -12,8 +12,8 @@ import { SwiperItem, } from "@tarojs/components"; -import { Toast } from "@antmjs/vantui"; -const Toast_ = Toast.createOnlyToast(); +// import { Toast } from "@antmjs/vantui"; +// const Toast_ = Toast.createOnlyToast(); /*** redux ***/ import { connect } from "react-redux"; @@ -22,9 +22,7 @@ import { userRefresh } from "../../store/features/userInfo"; import "taro-ui/dist/style/components/button.scss"; // 按需引入 import "./initiate.less"; -import { go } from "../../utils/traoAPI"; - -import { getGlobalData, setGlobalData } from "../../utils/global"; +import { go, msg } from "../../utils/traoAPI"; class Initiate extends Component { constructor(props) { @@ -54,7 +52,7 @@ class Initiate extends Component { const menu = Taro.getMenuButtonBoundingClientRect(); this.setState({ menu }); - if (!getGlobalData("token")) { + if (!Taro.getStorageSync("token")) { await this.WCUserLogin(); Taro.setStorageSync("isWelcome", true); await this.initData(); @@ -89,9 +87,7 @@ class Initiate extends Component { this.setState({ url }); } } else { - Toast_.fail({ - message: "获取首页视频失败!", - }); + msg("获取首页视频失败!"); } } @@ -108,7 +104,6 @@ class Initiate extends Component { const { code } = await Taro.login(); const { data } = await WCUserLogin({ code }); if (data.code === 200) { - // setGlobalData("token", data.data.token); Taro.setStorageSync("token", data.data.token); Taro.setStorageSync("mobile", data.data.mobile); this.props.userRefresh(data.data); @@ -190,8 +185,6 @@ class Initiate extends Component { - - ); } @@ -199,6 +192,7 @@ class Initiate extends Component { const mapStateToProps = (state) => ({ mobile: state.userInfo.mobile, + token: state.global.token, }); const mapDispatchToProps = (dispatch) => ({ userRefresh(value) { diff --git a/src/pages/login/login.tsx b/src/pages/login/login.tsx index 0ca0ac1..8b1d16e 100644 --- a/src/pages/login/login.tsx +++ b/src/pages/login/login.tsx @@ -44,7 +44,6 @@ class Login extends Component { }; render() { - let { name } = this.state; return ( { constructor(props) { super(props); @@ -19,6 +30,13 @@ export default class Message extends Component { list: [], pageNum: 1, pageSize: 10, + scrollTop: 0, + // downText: "下拉刷新", + pullText: "上拉加载更多", + isBottom: false, // 是否触底 + start_p: {}, + scrollY: true, + dargState: 0, //刷新状态 0不作操做 1刷新 -1加载更多 }; } @@ -64,40 +82,241 @@ export default class Message extends Component { } }; + // onRefresh: IPullToRefreshProps["onRefresh"] = () => { + // return new Promise((resolve) => { + // setTimeout(() => { + // resolve(undefined); + // }, 1000); + // }); + // }; + + // _onscroll = (e) => this.setTop(e.detail.scrollTop); + + // setTop = (value) => { + // console.log("setTop", value); + // }; + + /*** 上拉加载 ***/ + reduction = () => { + //还原初始设置 + const time = 0.5; + this.setState({ + // dargState: 0, + scrollY: true, + }); + setTimeout(() => { + this.setState({ + pullText: "上拉加载更多", + // downText: "下拉刷新", + }); + }, time * 1000); + }; + touchStart = (e) => { + this.setState({ + start_p: e.touches[0], + }); + }; + touchmove = (e) => { + let move_p = e.touches[0], //移动时的位置 + deviationX = 0.3, //左右偏移量(超过这个偏移量不执行下拉操做) + deviationY = 70, //拉动长度(低于这个值的时候不执行) + maxY = 100; //拉动的最大高度 + + let start_x = this.state.start_p.clientX, + start_y = this.state.start_p.clientY, + move_x = move_p.clientX, + move_y = move_p.clientY; + + //获得偏移数值 + let dev = Math.abs(move_x - start_x) / Math.abs(move_y - start_y); + if (dev < deviationX) { + //当偏移数值大于设置的偏移数值时则不执行操做 + let pY = Math.abs(move_y - start_y) / 3.5; //拖动倍率(使拖动的时候有粘滞的感受--试了不少次 这个倍率恰好) + if (move_y - start_y > 0) { + //下拉操做 + if (pY >= deviationY) { + this.setState({ dargState: 1, downText: "释放刷新" }); + } else { + // this.setState({ dargState: 0, downText: "下拉刷新" }); + } + if (pY >= maxY) { + pY = maxY; + } + this.setState({ + scrollY: false, //拖动的时候禁用 + }); + } + if (start_y - (move_y + 100) > 0) { + //上拉操做 + // console.log("上拉操做"); + if (pY >= deviationY) { + this.setState({ dargState: -1, pullText: "释放加载更多" }); + } else { + // this.setState({ dargState: 0, pullText: "上拉加载更多" }); + } + } + } + }; + pull = () => { + //上拉 + console.log("上拉"); + + // this.props.onPull() + }; + down = () => { + //下拉 + console.log("下拉"); + // this.props.onDown() + }; + ScrollToUpper = () => { + //滚动到顶部事件 + console.log("滚动到顶部事件"); + // this.props.Upper() + }; + ScrollToLower = () => { + //滚动到底部事件 + console.log("滚动到底部事件"); + // this.props.Lower() + }; + touchEnd = (e) => { + if (this.state.dargState === 1) { + this.down(); + } else if (this.state.dargState === -1) { + this.pull(); + } + this.reduction(); + }; + /*** 上拉加载 ***/ + + // onPullDownRefresh = (e) => { + // console.log("onPullDownRefresh", e); + // }; + render() { - let { list } = this.state; + let { list, scrollTop, dargState, pullText } = this.state; return ( + {/* */} + {/* 0} onRefresh={this.onRefresh}> + + + {new Array(20).fill(1).map((_, index) => ( + + {index} + + ))} + + + + + + {dargState === 0 ? ( + "上拉加载更多" + ) : ( + 加载中... + )} + + */} + + + + + + {list.map((item: any) => { + return ( + + + + + + + 系统通知 + + {item.createTime} + + + + + [花至官方旗舰店]: {item.content ? item.content : ""} + + + + + ); + })} + + + + + + {dargState === 0 ? ( + "上拉加载更多" + ) : ( + 加载中... + )} + + + {/* - {list.map((item: any, key: number) => { + {list.map((item: any) => { return ( - - - - - - - - 系统通知 + + + + + - {item.createTime} + 系统通知 - - - - [花至官方旗舰店]: {item.content ? item.content : ""} - - + {item.createTime} + + + + + [花至官方旗舰店]: {item.content ? item.content : ""} + - + ); })} - + */} diff --git a/src/pages/privacyPolicy/privacyPolicy.less b/src/pages/privacyPolicy/privacyPolicy.less index 11a32e6..fc2954b 100644 --- a/src/pages/privacyPolicy/privacyPolicy.less +++ b/src/pages/privacyPolicy/privacyPolicy.less @@ -2,6 +2,13 @@ padding: 30rpx; word-break: break-all; box-sizing: border-box; + table { + border-collapse: collapse; /* 边框合并 */ + } + td { + text-align: center; /* 字体居中 */ + border: 1px solid #ccc; /* 边框样式 */ + } } pre { diff --git a/src/pages/privacyPolicy/privacyPolicy.tsx b/src/pages/privacyPolicy/privacyPolicy.tsx index 39736c5..9e9887a 100644 --- a/src/pages/privacyPolicy/privacyPolicy.tsx +++ b/src/pages/privacyPolicy/privacyPolicy.tsx @@ -44,9 +44,10 @@ export default class PrivacyPolicy extends Component { " + - nodes + - "" + nodes + // "
" +
+              // nodes +
+              // "
" } />
diff --git a/src/pages/register/register.tsx b/src/pages/register/register.tsx index 36fa7cc..9db0f61 100644 --- a/src/pages/register/register.tsx +++ b/src/pages/register/register.tsx @@ -63,7 +63,7 @@ export default class Register extends Component { // skipby: options.skipby // }) // } - // if (!app.globalData.token) { + // if (!Taro.getStorageSync("token")) { // await this.WCUserLogin(); // } diff --git a/src/pages/user/user.tsx b/src/pages/user/user.tsx index 9338689..9e0868a 100644 --- a/src/pages/user/user.tsx +++ b/src/pages/user/user.tsx @@ -5,8 +5,8 @@ import Taro from "@tarojs/taro"; // 引入 Swiper, SwiperItem 组件 import { View, Block, Textarea, Image } from "@tarojs/components"; -import { Toast } from "@antmjs/vantui"; -const Toast_ = Toast.createOnlyToast(); +// import { Toast } from "@antmjs/vantui"; +// const Toast_ = Toast.createOnlyToast(); import { go, loading, msg } from "../../utils/traoAPI"; @@ -343,7 +343,7 @@ class User extends Component { close={this.closeCustomerService} confirm={this.confirmCustomerService} /> - + {/* */}
); } diff --git a/src/pages/userInfo/userInfo.tsx b/src/pages/userInfo/userInfo.tsx index 159009f..000e312 100644 --- a/src/pages/userInfo/userInfo.tsx +++ b/src/pages/userInfo/userInfo.tsx @@ -97,7 +97,7 @@ class UserInfo extends Component { } async onLoad() { - if (!getGlobalData("token")) { + if (!Taro.getStorageSync("token")) { // await this.WCUserLogin(); } const menu = Taro.getMenuButtonBoundingClientRect(); diff --git a/src/pages/userInfoDetail/userInfoDetail.tsx b/src/pages/userInfoDetail/userInfoDetail.tsx index a404e98..d97bd11 100644 --- a/src/pages/userInfoDetail/userInfoDetail.tsx +++ b/src/pages/userInfoDetail/userInfoDetail.tsx @@ -89,7 +89,7 @@ class UserInfoDetail extends Component { } async onLoad() { - if (!getGlobalData("token")) { + if (!Taro.getStorageSync("token")) { // await this.WCUserLogin(); } const menu = Taro.getMenuButtonBoundingClientRect(); diff --git a/src/store/features/global.js b/src/store/features/global.js new file mode 100644 index 0000000..6c45171 --- /dev/null +++ b/src/store/features/global.js @@ -0,0 +1,20 @@ +import Taro from "@tarojs/taro"; +import { createSlice } from "@reduxjs/toolkit"; + +// 全局变量 +const globalReducer = createSlice({ + name: "global", // store的名字 + initialState: { + domain: "http://110.41.134.131:8080", // 请求地址 + token: "", + }, + reducers: { + setToken(state, { payload }) { + // Taro.setStorageSync.setItem("token", payload); + state.token = payload; + }, + }, +}); + +export const { setToken } = globalReducer.actions; +export default globalReducer.reducer; diff --git a/src/store/features/userInfo.js b/src/store/features/userInfo.js index 66803f0..1cb0d40 100644 --- a/src/store/features/userInfo.js +++ b/src/store/features/userInfo.js @@ -1,8 +1,6 @@ import Taro from "@tarojs/taro"; import { createSlice } from "@reduxjs/toolkit"; -import { RefreshWxUserInfo } from "../../utils/Interface"; - const userInfoReducer = createSlice({ name: "userInfo", // store的名字 initialState: { diff --git a/src/store/index.js b/src/store/index.js index 82793a6..0ef15c2 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,6 +3,7 @@ import { configureStore } from "@reduxjs/toolkit"; import counterReducer from "./features/counter"; import navigationReducer from "./features/navigation"; import userInfoReducer from "./features/userInfo"; +import globalReducer from "./features/global"; const store = configureStore({ reducer: { @@ -10,6 +11,7 @@ const store = configureStore({ counter: counterReducer, navigation: navigationReducer, userInfo: userInfoReducer, + global: globalReducer, }, }); diff --git a/src/utils/Interface.js b/src/utils/Interface.js index 14a76bd..36b4d75 100644 --- a/src/utils/Interface.js +++ b/src/utils/Interface.js @@ -173,6 +173,24 @@ export const GetIntegralRule = (data) => { method: "get", }); }; + +export const GetIsAttentionOfficialAccount = (data) => { + // 查询用户是否关注公众号 + return Ajax({ + url: "/hzwx/noRemind/isAttentionOfficialAccount", + data, + method: "get", + }); +}; + +export const GetOfficialAccount = (data) => { + // 查询用户是否关闭提醒关注公众号 + return Ajax({ + url: "/hzwx/noRemind/getOfficialAccount", + data, + method: "get", + }); +}; // /////////// diff --git a/src/utils/compressImage.js b/src/utils/compressImage.js new file mode 100644 index 0000000..e00bfe9 --- /dev/null +++ b/src/utils/compressImage.js @@ -0,0 +1,109 @@ +import Taro from "@tarojs/taro"; + +/* 获取图片信息 + * @param {string} tempFilePath 图片路径 + * @returns 图片信息 + */ +async function getImgInfo(tempFilePath) { + try { + let image = await new Promise((resolve, reject) => { + Taro.getImageInfo({ + src: tempFilePath, + success(res) { + let imgInfo = { + type: res.type, + height: res.height, + width: res.width, + path: res.path, + }; + resolve(imgInfo); + }, + fail(err) { + reject(err); + }, + }); + }); + return image; + } catch (err) { + console.log(err); + } +} + +/** + * 图片压缩 + * @param {object} file 图片信息:width、height、type、path + * @param {string} canvasId canvas的id名 + * @param {object} config 限制最大宽高 + * @returns 压缩完成后的图片path + */ +async function contraction( + file, + canvasId, + config = { maxWidth: 2048, maxHeight: 1536 } + // config = { maxWidth: 1024, maxHeight: 768 } +) { + try { + let ctxInfo = await new Promise((resolve, reject) => { + // 获取图片原始宽高 + let width = file.width; + let height = file.height; + + // 计算图片当前大小和目标大小的比例:目标大小 / 图片当前大小 + // 根据比例调整图片的尺寸: + // 新宽度 = 原始宽度 * √(目标大小 / 图片当前大小) + // 新高度 = 原始高度 * √(目标大小 / 图片当前大小) + // 宽高同比例调整 + // 宽度 > 最大限宽 -> 重置尺寸 + if (width > config.maxWidth) { + const ratio = config.maxWidth / width; + width = config.maxWidth; + height = height * ratio; + } + // 高度 > 最大限高度 -> 重置尺寸 + if (height > config.maxHeight) { + const ratio = config.maxHeight / height; + width = width * ratio; + height = config.maxHeight; + } + + // 获取canvas元素 + const query = this.createSelectorQuery(); + let dom = query.select(`#${canvasId}`); + dom.fields({ node: true, size: true }).exec((res) => { + // Canvas 对象 + const canvas = res[0].node; + // 渲染上下文 + const ctx = canvas.getContext("2d"); + + // 根据设备像素比处理尺寸 = 大小 * 设备像素 + const dpr = Taro.getSystemInfoSync().pixelRatio; + canvas.width = width * dpr; + canvas.height = height * dpr; + ctx.scale(dpr, dpr); + + //创建img对象 + let img = canvas.createImage(); + img.src = file.path; // 给图片添加路径 + //图片加载完毕 + img.onload = function () { + // 将图片绘制到 canvas + ctx.drawImage(img, 0, 0, width, height); + // 生成图片 + Taro.canvasToTempFilePath({ + canvas, + x: 0, + y: 0, + destWidth: width, + destHeight: height, + success(res) { + resolve(res); // 生成临时文件路径 + }, + }); + }; + }); + }); + return ctxInfo; + } catch (err) { + console.log(err); + } +} diff --git a/src/utils/request.js b/src/utils/request.js index 0d1f2da..8296538 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,21 +1,25 @@ import { back, showModal } from "./traoAPI"; import { WCUserLogin } from "./Interface"; -import { getGlobalData, setGlobalData } from "./global"; +// import { getGlobalData, setGlobalData } from "./global"; import Taro from "@tarojs/taro"; import formdata from "./wx-formdata/formData"; +import store from "../store"; +const global = store.getState().global; + +const global_requestUrlList = []; // 全局:正在请求的url地址,防止多次点击 + export const Ajax = (params) => { const app = Taro.getApp(); - // const domain = getGlobalData("domain") - const domain = getGlobalData("domain") || "http://192.168.10.147:80"; + const domain = global.domain; // console.log("Ajaxdomain", app, domain); // Taro.showLoading({ // title: '请求中...', // mask: true // }); // 防止多次点击 - const requestUrlList = getGlobalData("requestUrlList") || []; + const requestUrlList = global_requestUrlList; const whiteList = []; // 白名单 if ( requestUrlList.indexOf(params.url) > -1 && @@ -30,7 +34,6 @@ export const Ajax = (params) => { url: domain + params.url, method: params.method || "GET", header: { - // Authorization: "Bearer " + getGlobalData("token") || "", Authorization: "Bearer " + Taro.getStorageSync("token"), ...params.header, }, @@ -43,8 +46,7 @@ export const Ajax = (params) => { content: "登录已过期,请重新登录", showCancel: false, }).then((res) => { - setGlobalData("token", null); - + sessionStorage.setItem("token", null); Taro.clearStorage(); // 清空所有缓存 Taro.reLaunch({ // url: "/pages/login/login", @@ -80,7 +82,7 @@ export const Ajax = (params) => { }).then(() => { reject(res); if (res.data.code == 403 || res.data.msg === "登录状态已过期") { - setGlobalData("token", null); + sessionStorage.setItem("token", null); Taro.reLaunch({ // url: "/pages/login/login", url: "/pages/initiate/initiate", @@ -104,7 +106,7 @@ export const Ajax = (params) => { }, complete() { Taro.hideLoading(); - const requestUrlList = getGlobalData("requestUrlList"); + const requestUrlList = global_requestUrlList; const newRequestUrlList = requestUrlList.splice( requestUrlList.indexOf(params.url), 1 @@ -116,7 +118,7 @@ export const Ajax = (params) => { export const AjaxuploadFile = (params) => { const app = Taro.getApp(); - const domain = getGlobalData("domain"); + const domain = global.domain; // Taro.showLoading({ // title: "请求中...", // mask: true, @@ -168,10 +170,10 @@ export const AjaxuploadFile = (params) => { export const AjaxFormData = (params) => { const app = Taro.getApp(); - const domain = getGlobalData("domain"); + const domain = global.domain; // 防止多次点击 - const requestUrlList = getGlobalData("requestUrlList") || []; + const requestUrlList = global_requestUrlList; const whiteList = ["/Api/MessageList"]; if ( requestUrlList.indexOf(params.url) > -1 && @@ -186,7 +188,6 @@ export const AjaxFormData = (params) => { url: domain + params.url, method: params.method || "GET", header: { - // Authorization: "Bearer " + getGlobalData("token") || "", Authorization: "Bearer " + Taro.getStorageSync("token"), ...params.header, "content-type": params.data.contentType, @@ -200,7 +201,7 @@ export const AjaxFormData = (params) => { content: "登录已过期,请重新登录", showCancel: false, }).then((res) => { - setGlobalData("token", null); + sessionStorage.setItem("token", null); Taro.clearStorage(); // 清空所有缓存 Taro.reLaunch({ url: "/pages/initiate/initiate", @@ -230,7 +231,7 @@ export const AjaxFormData = (params) => { }).then(() => { reject(res); if (res.data.code == 403 || res.data.msg === "登录状态已过期") { - setGlobalData("token", null); + sessionStorage.setItem("token", null); Taro.reLaunch({ url: "/pages/initiate/initiate", }); @@ -253,7 +254,7 @@ export const AjaxFormData = (params) => { }, complete() { Taro.hideLoading(); - const requestUrlList = getGlobalData("requestUrlList"); + const requestUrlList = global_requestUrlList; const newRequestUrlList = requestUrlList.splice( requestUrlList.indexOf(params.url), 1