add:UI设计稿修复,以及确定后续使用的taro图表库为@visactor/taro-vchart

master
blak-kong 2 years ago
parent bf179ffb7c
commit db13090485

62108
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -54,6 +54,8 @@
"@tarojs/runtime": "3.6.19", "@tarojs/runtime": "3.6.19",
"@tarojs/shared": "3.6.19", "@tarojs/shared": "3.6.19",
"@tarojs/taro": "3.6.19", "@tarojs/taro": "3.6.19",
"@visactor/taro-vchart": "^1.9.0",
"dayjs": "^1.11.10",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"react": "^18.0.0", "react": "^18.0.0",
"react-dom": "^18.0.0", "react-dom": "^18.0.0",

@ -164,7 +164,7 @@
} }
// 折叠高度 // 折叠高度
.main__body.main__body--isFolding { .main__body.main__body--isFolding {
height: 90px; height: 80px;
} }
} }
/* 样式定制 */ /* 样式定制 */

@ -25,8 +25,9 @@
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
background: #fff; background: #fff;
// padding-bottom: 10rpx; border: 0;
z-index: 99; z-index: 99;
padding-bottom: 2rpx;
.logo { .logo {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;

@ -1,9 +1,12 @@
.common-box { .drawer-box {
padding: 38rpx 0 0; padding: 38rpx 0 0;
// padding-bottom: 40rpx;
box-sizing: border-box; box-sizing: border-box;
z-index: 100005; z-index: 100005;
.drawer-popup-title {
margin-bottom: 60rpx;
}
} }
.common-popup-content-box { .common-popup-content-box {
margin-top: 42rpx; margin-top: 42rpx;
} }

@ -79,10 +79,18 @@ export default class PopupDrawer extends Component<any, any> {
></View> ></View>
)} )}
<View <View
className={classnames("common-box", "common-big-large")} className={classnames(
"common-box",
"drawer-box",
"common-big-large"
)}
style="margin: auto;" style="margin: auto;"
> >
<View className="common-popup-title">{title}</View> <View
className={classnames("common-popup-title", "drawer-popup-title")}
>
{title}
</View>
<View className="common-popup-content-box"> <View className="common-popup-content-box">
<View <View
className={classnames("common-popup-content", { className={classnames("common-popup-content", {

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -120,6 +120,8 @@ page {
height: 474rpx; height: 474rpx;
background: linear-gradient(0deg, #f8f8f8 0%, #efefef 100%); background: linear-gradient(0deg, #f8f8f8 0%, #efefef 100%);
border-radius: 50rpx; border-radius: 50rpx;
padding-bottom: env(safe-area-inset-bottom);
box-sizing: border-box;
.text { .text {
font-size: 48rpx; font-size: 48rpx;
font-family: PingFang SC; font-family: PingFang SC;
@ -132,7 +134,7 @@ page {
font-size: 26rpx; font-size: 26rpx;
font-weight: 400; font-weight: 400;
color: #666; color: #666;
margin-top: 48rpx; margin-top: 40rpx;
} }
.indicator { .indicator {
display: inline-flex; display: inline-flex;
@ -140,7 +142,7 @@ page {
width: 360rpx; width: 360rpx;
height: 2rpx; height: 2rpx;
background: transparent; background: transparent;
margin-top: 229rpx; margin-top: 200rpx;
.dot { .dot {
display: inline-flex; display: inline-flex;
flex: 1; flex: 1;

@ -215,7 +215,7 @@ class Entry extends Component<any, any> {
<View <View
key={"indicator_" + index} key={"indicator_" + index}
className={classnames("dot", { className={classnames("dot", {
"bg-show": current >= index, "bg-show": current === index,
})} })}
></View> ></View>
); );

@ -2,6 +2,11 @@ page {
background: #f3f3f3; background: #f3f3f3;
} }
// .index-main {
// height: max-content;
// background: #f3f3f3;
// }
/* 隐藏横向滚动条 */ /* 隐藏横向滚动条 */
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 0; width: 0;
@ -1002,6 +1007,7 @@ page {
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
height: 40rpx; height: 40rpx;
z-index: 99;
.text { .text {
color: #666; color: #666;
font-size: 26rpx; font-size: 26rpx;

@ -13,7 +13,7 @@ import {
/*** redux ***/ /*** redux ***/
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userRefresh } from "../../store/features/userInfo"; import { userRefresh, tokenRefresh } from "../../store/features/userInfo";
import { setIndexFlag } from "../../store/features/globalStore"; import { setIndexFlag } from "../../store/features/globalStore";
/*** redux end ***/ /*** redux end ***/
@ -356,14 +356,9 @@ class Index extends Component<any, any> {
const { code } = await Taro.login(); const { code } = await Taro.login();
const { data } = await WCUserLogin({ code }); const { data } = await WCUserLogin({ code });
if (data.code === 200) { if (data.code === 200) {
setStorageSync("isWelcome", "true"); Taro.setStorageSync("isWelcome", true);
setStorageSync(
"token",
data.data.token,
dayjs().add(12, "h").format("YYYY/MM/DD hh:mm:ss")
);
Taro.setStorageSync("mobile", data.data.mobile); Taro.setStorageSync("mobile", data.data.mobile);
this.props.userRefresh(data.data); this.props.tokenRefresh(data.data);
Taro.hideLoading(); Taro.hideLoading();
this.initPageData(); this.initPageData();
@ -384,8 +379,6 @@ class Index extends Component<any, any> {
if (url) { if (url) {
let urlObj = new URL(url); let urlObj = new URL(url);
let params = new URLSearchParams(url); let params = new URLSearchParams(url);
console.log("urlObj", urlObj);
console.log("params", params);
let { data } = await InstrumentInfo.getInstrumentInfoBySerial(); let { data } = await InstrumentInfo.getInstrumentInfoBySerial();
console.log("Data", data); console.log("Data", data);
} }
@ -412,7 +405,6 @@ class Index extends Component<any, any> {
typeBinding, typeBinding,
} = this.state; } = this.state;
console.log("bannerList", bannerList);
return ( return (
<Block> <Block>
<PopupAlert <PopupAlert
@ -610,6 +602,9 @@ const mapDispatchToProps = (dispatch) => ({
userRefresh(data) { userRefresh(data) {
dispatch(userRefresh(data)); dispatch(userRefresh(data));
}, },
tokenRefresh(data) {
dispatch(tokenRefresh(data));
},
setIndexFlag(data) { setIndexFlag(data) {
dispatch(setIndexFlag(data)); dispatch(setIndexFlag(data));
}, },

@ -32,7 +32,7 @@
align-items: center; align-items: center;
// justify-content: center; // justify-content: center;
// left: 50%; // left: 50%;
bottom: calc(env(safe-area-inset-bottom) + 142rpx); bottom: 142rpx;
// transform: translateX(-50%); // transform: translateX(-50%);
} }

@ -1,3 +1,4 @@
import dayjs from "dayjs";
import { MpSplashDetail, WCUserLogin } from "../../utils/Interface"; import { MpSplashDetail, WCUserLogin } from "../../utils/Interface";
import { Component, PropsWithChildren, useEffect, useState } from "react"; import { Component, PropsWithChildren, useEffect, useState } from "react";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
@ -16,12 +17,12 @@ import Navbar from "../../components/navbar/navbar";
/*** redux ***/ /*** redux ***/
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userRefresh } from "../../store/features/userInfo"; import { userRefresh, tokenRefresh } from "../../store/features/userInfo";
/*** redux end ***/ /*** redux end ***/
import "taro-ui/dist/style/components/button.scss"; // 按需引入 import "taro-ui/dist/style/components/button.scss"; // 按需引入
import "./initiate.less"; import "./initiate.less";
import { go, msg } from "../../utils/traoAPI"; import { go, msg, setStorageSync, getStorageSync } from "../../utils/traoAPI";
class Initiate extends Component<any, any> { class Initiate extends Component<any, any> {
constructor(props) { constructor(props) {
@ -49,7 +50,7 @@ class Initiate extends Component<any, any> {
const menu = Taro.getMenuButtonBoundingClientRect(); const menu = Taro.getMenuButtonBoundingClientRect();
this.setState({ menu }); this.setState({ menu });
if (!Taro.getStorageSync("token")) { if (!getStorageSync("token")) {
await this.WCUserLogin(); await this.WCUserLogin();
} else { } else {
go("/pages/entry/entry"); go("/pages/entry/entry");
@ -117,12 +118,13 @@ class Initiate extends Component<any, any> {
const { data } = await WCUserLogin({ code }); const { data } = await WCUserLogin({ code });
if (data.code === 200) { if (data.code === 200) {
Taro.setStorageSync("isWelcome", true); Taro.setStorageSync("isWelcome", true);
Taro.setStorageSync("token", data.data.token);
Taro.setStorageSync("mobile", data.data.mobile); Taro.setStorageSync("mobile", data.data.mobile);
this.props.userRefresh(data.data); this.props.tokenRefresh(data.data);
Taro.hideLoading(); Taro.hideLoading();
this.initData(); setTimeout(() => {
this.initData();
}, 300);
} else { } else {
msg("请求失败,尝试重新请求"); msg("请求失败,尝试重新请求");
this.WCUserLogin(); this.WCUserLogin();
@ -142,7 +144,7 @@ class Initiate extends Component<any, any> {
this.onEnded(); this.onEnded();
} }
onEnded = () => { onEnded = () => {
let token = Taro.getStorageSync("token"); let token = getStorageSync("token");
if (token) { if (token) {
let data = Taro.getStorageSync("MpSplashDetail_type1") || undefined; let data = Taro.getStorageSync("MpSplashDetail_type1") || undefined;
if (data) { if (data) {
@ -222,5 +224,8 @@ const mapDispatchToProps = (dispatch) => ({
userRefresh(value) { userRefresh(value) {
dispatch(userRefresh(value)); dispatch(userRefresh(value));
}, },
tokenRefresh(value) {
dispatch(tokenRefresh(value));
},
}); });
export default connect(mapStateToProps, mapDispatchToProps)(Initiate); export default connect(mapStateToProps, mapDispatchToProps)(Initiate);

@ -100,7 +100,7 @@ page {
.list_block { .list_block {
width: 100%; width: 100%;
border-bottom: 2rpx solid #dddddd; border-bottom: 2rpx solid #dddddd;
padding: 32rpx 0 30rpx 0; padding: 32rpx 30rpx 30rpx 30rpx;
box-sizing: border-box; box-sizing: border-box;
} }
.left { .left {

@ -447,7 +447,7 @@ class IntegralList extends Component<any, any> {
scrollY={this.state.scrollY} scrollY={this.state.scrollY}
scrollWithAnimation scrollWithAnimation
> >
<View style={{ padding: "0 12px" }}> <View>
<View> <View>
{list.length === 0 && ( {list.length === 0 && (
<View className="nodata"> <View className="nodata">

@ -5,7 +5,7 @@ page {
background: #fff; background: #fff;
border-radius: 30rpx; border-radius: 30rpx;
margin: 20rpx 30rpx 0; margin: 20rpx 30rpx 0;
padding: 20rpx 34rpx 48rpx; padding: 20rpx 35rpx 48rpx 35rpx;
box-sizing: border-box; box-sizing: border-box;
.info1 { .info1 {
.left { .left {

@ -2,6 +2,10 @@
padding-bottom: 160rpx; padding-bottom: 160rpx;
}*/ }*/
page {
background-color: #f8f8f8;
}
.tabs { .tabs {
display: flex; display: flex;
align-items: center; align-items: center;

@ -70,7 +70,7 @@ export default class Recording extends Component<any, any> {
<View className="nodata"> <View className="nodata">
<Image <Image
className="nodata_img" className="nodata_img"
src={require("../../img/empty.png")} src={require("../../img/nodata.png")}
></Image> ></Image>
<View className="nodata_text"></View> <View className="nodata_text"></View>
</View> </View>
@ -81,9 +81,9 @@ export default class Recording extends Component<any, any> {
<View className="nodata"> <View className="nodata">
<Image <Image
className="nodata_img" className="nodata_img"
src={require("../../img/empty.png")} src={require("../../img/nodata.png")}
></Image> ></Image>
<View className="empty_text"></View> <View className="nodata_text"></View>
</View> </View>
</View> </View>
)} )}

@ -28,10 +28,10 @@ page {
.footer { .footer {
position: relative; position: relative;
margin-top: -62rpx; margin-top: -72rpx;
z-index: 1; z-index: 1;
width: 100%; width: 100%;
height: 570rpx; height: 580rpx;
background: #fff; background: #fff;
// background: #000; // background: #000;
border-radius: 50rpx 50rpx 0rpx 0rpx; border-radius: 50rpx 50rpx 0rpx 0rpx;
@ -71,7 +71,7 @@ page {
line-height: 90rpx; line-height: 90rpx;
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
margin: 118rpx auto 42rpx; margin: 110rpx auto 36rpx;
text-align: center; text-align: center;
} }

@ -22,7 +22,7 @@ page {
.infobox1 { .infobox1 {
border-radius: 20rpx; border-radius: 20rpx;
margin-top: 168rpx; margin-top: 130rpx;
/*height: 490rpx;*/ /*height: 490rpx;*/
} }
.infobox1 .info1 { .infobox1 .info1 {
@ -264,3 +264,7 @@ page {
border-radius: 50%; border-radius: 50%;
} }
} }
.common-box {
padding: 50rpx 35rpx 44rpx 35rpx;
}

@ -14,7 +14,7 @@ import { userRefresh } from "../../store/features/userInfo";
import { RefreshWxUserInfo, GetNoReadMessageNum } from "../../utils/Interface"; import { RefreshWxUserInfo, GetNoReadMessageNum } from "../../utils/Interface";
import "taro-ui/dist/style/components/button.scss"; // 按需引入 // import "taro-ui/dist/style/components/button.scss"; // 按需引入
import "./user.less"; import "./user.less";
import type CustomTabBar from "../../custom-tab-bar"; import type CustomTabBar from "../../custom-tab-bar";
@ -204,6 +204,7 @@ class User extends Component<any, any> {
/> />
<PopupAlert <PopupAlert
isShow={isNotRegister} isShow={isNotRegister}
isClose={true}
title="提示" title="提示"
content="暂未授权注册,请点击注册" content="暂未授权注册,请点击注册"
confirmButtonText="确定" confirmButtonText="确定"

@ -41,7 +41,6 @@ class UserInfo extends Component<any, any> {
style: "font-size: 26rpx; font-weight: 400; color: #ccc", style: "font-size: 26rpx; font-weight: 400; color: #ccc",
userInfo: { userInfo: {
...this.props.userInfo, ...this.props.userInfo,
birthday: "",
}, },
isShowIntegralText: false, isShowIntegralText: false,
cityShow: false, cityShow: false,
@ -80,7 +79,9 @@ class UserInfo extends Component<any, any> {
// maxDate: new Date().getTime(), // maxDate: new Date().getTime(),
// minDate: new Date("1949-10-01").getTime(), // minDate: new Date("1949-10-01").getTime(),
minDate: new Date("1949-10-01").getTime(), minDate: new Date("1949-10-01").getTime(),
birthday: dayjs(this.props.userInfo.birthday).valueOf(), birthday: this.props.userInfo.birthday
? dayjs(this.props.userInfo.birthday).valueOf()
: dayjs().valueOf(),
isSubmit: false, // 是否允许提交 isSubmit: false, // 是否允许提交
}; };
} }

@ -83,6 +83,9 @@ class UserInfoDetail extends Component<any, any> {
// maxDate: new Date().getTime(), // maxDate: new Date().getTime(),
// minDate: new Date("1949-10-01").getTime(), // minDate: new Date("1949-10-01").getTime(),
currentDate: new Date().getTime(), currentDate: new Date().getTime(),
birthday: this.props.userInfo.birthday
? dayjs(this.props.userInfo.birthday).valueOf()
: dayjs().valueOf(),
minDate: new Date("1949-10-01").getTime(), minDate: new Date("1949-10-01").getTime(),
}; };
} }
@ -400,6 +403,7 @@ class UserInfoDetail extends Component<any, any> {
minDate, minDate,
isShowIntegralText, isShowIntegralText,
isSubmit, isSubmit,
birthday,
} = this.state; } = this.state;
const formatter = (type, value) => { const formatter = (type, value) => {
@ -491,7 +495,7 @@ class UserInfoDetail extends Component<any, any> {
<View className="value"> <View className="value">
{/* <picker className="picker" mode="date" bindchange="bindbirthdayPickerChange" end="{{dateend}}" value="{{ageindex}}" range="{{age}}">picker</picker> */} {/* <picker className="picker" mode="date" bindchange="bindbirthdayPickerChange" end="{{dateend}}" value="{{ageindex}}" range="{{age}}">picker</picker> */}
<View>{userInfo.birthday || dayjs().format("YYYY-MM-DD")}</View> <View>{userInfo.birthday}</View>
<View className="righticon"> <View className="righticon">
<Image <Image
src={require("../../img/user/right.png")} src={require("../../img/user/right.png")}
@ -529,7 +533,7 @@ class UserInfoDetail extends Component<any, any> {
<DatetimePicker <DatetimePicker
type="date" type="date"
formatter={formatter} formatter={formatter}
value={dayjs(userInfo.birthday).valueOf()} value={dayjs(birthday).valueOf()}
minDate={minDate} minDate={minDate}
maxDate={Date.now()} maxDate={Date.now()}
onCancel={this.onTimePickerCancel} onCancel={this.onTimePickerCancel}

@ -2,6 +2,8 @@ import Taro from "@tarojs/taro";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { createSlice } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
import { setStorageSync, getStorageSync } from "../../utils/traoAPI";
const userInfoReducer = createSlice({ const userInfoReducer = createSlice({
name: "userInfo", // store的名字 name: "userInfo", // store的名字
initialState: { initialState: {
@ -37,7 +39,7 @@ const userInfoReducer = createSlice({
state.mobile = payload.mobile || ""; state.mobile = payload.mobile || "";
state.nickname = payload.nickname || ""; state.nickname = payload.nickname || "";
state.headimg = payload.headimg || ""; state.headimg = payload.headimg || "";
state.birthday = payload.birthday || dayjs().format("YYYY-MM-DD"); state.birthday = payload.birthday || "";
state.province = payload.province || ""; state.province = payload.province || "";
state.provinceId = payload.provinceId || ""; state.provinceId = payload.provinceId || "";
state.city = payload.city || ""; state.city = payload.city || "";
@ -57,7 +59,7 @@ const userInfoReducer = createSlice({
state.mobile = payload.mobile || ""; state.mobile = payload.mobile || "";
state.nickname = payload.nickname || ""; state.nickname = payload.nickname || "";
state.headimg = payload.headimg || ""; state.headimg = payload.headimg || "";
state.birthday = payload.birthday || dayjs().format("YYYY-MM-DD"); state.birthday = payload.birthday || "";
state.province = payload.province || ""; state.province = payload.province || "";
state.provinceId = payload.provinceId || ""; state.provinceId = payload.provinceId || "";
state.city = payload.city || ""; state.city = payload.city || "";
@ -70,11 +72,13 @@ const userInfoReducer = createSlice({
state.integralText = payload.integralText || ""; state.integralText = payload.integralText || "";
Taro.setStorageSync("mobile", state.mobile); Taro.setStorageSync("mobile", state.mobile);
Taro.setStorageSync("token", state.token);
let expires = new Date().getTime() + 43200000;
setStorageSync("token", state.token, expires);
}, },
}, },
}); });
export const { setMobile, setNickname, setHeadimg, userRefresh } = export const { setMobile, setNickname, setHeadimg, userRefresh, tokenRefresh } =
userInfoReducer.actions; userInfoReducer.actions;
export default userInfoReducer.reducer; export default userInfoReducer.reducer;

@ -1,7 +1,6 @@
import { back, showModal } from "./traoAPI"; import { back, showModal, setStorageSync, getStorageSync } from "./traoAPI";
import { WCUserLogin } from "./Interface"; import { WCUserLogin } from "./Interface";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import formdata from "./wxFormdata/formData"; import formdata from "./wxFormdata/formData";
import store from "../store"; import store from "../store";
@ -29,11 +28,12 @@ export const Ajax = (params) => {
requestUrlList.push(params.url); requestUrlList.push(params.url);
} }
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
let token = getStorageSync("token");
Taro.request({ Taro.request({
url: domain + params.url, url: domain + params.url,
method: params.method || "GET", method: params.method || "GET",
header: { header: {
Authorization: "Bearer " + Taro.getStorageSync("token"), Authorization: "Bearer " + token,
...params.header, ...params.header,
}, },
data: params.data, data: params.data,
@ -45,7 +45,7 @@ export const Ajax = (params) => {
content: "登录已过期,请重新登录", content: "登录已过期,请重新登录",
showCancel: false, showCancel: false,
}).then((res) => { }).then((res) => {
Taro.setStorageSync("token", null); setStorageSync("token", null);
Taro.clearStorage(); // 清空所有缓存 Taro.clearStorage(); // 清空所有缓存
Taro.reLaunch({ Taro.reLaunch({
url: "/pages/initiate/initiate", url: "/pages/initiate/initiate",
@ -82,7 +82,7 @@ export const Ajax = (params) => {
}).then(() => { }).then(() => {
reject(res); reject(res);
if (res.data.code == 401 || res.data.msg === "登录状态已过期") { if (res.data.code == 401 || res.data.msg === "登录状态已过期") {
Taro.setStorageSync("token", null); setStorageSync("token", null);
Taro.reLaunch({ Taro.reLaunch({
url: "/pages/initiate/initiate", url: "/pages/initiate/initiate",
}); });
@ -127,6 +127,7 @@ export const AjaxUploadFile = (params, formData) => {
mask: true, mask: true,
}); });
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
let token = getStorageSync("token");
Taro.uploadFile({ Taro.uploadFile({
filePath: params.filePath, filePath: params.filePath,
name: "file", name: "file",
@ -135,9 +136,8 @@ export const AjaxUploadFile = (params, formData) => {
...formData, ...formData,
}, },
header: { header: {
Authorization: "Bearer " + Taro.getStorageSync("token"), Authorization: "Bearer " + token,
...params.header, ...params.header,
// token: Taro.getStorageSync("token"),
}, },
success(res) { success(res) {
let o = JSON.parse(res.data); let o = JSON.parse(res.data);
@ -191,11 +191,12 @@ export const AjaxFormData = (params) => {
requestUrlList.push(params.url); requestUrlList.push(params.url);
} }
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
let token = getStorageSync("token");
Taro.request({ Taro.request({
url: domain + params.url, url: domain + params.url,
method: params.method || "GET", method: params.method || "GET",
header: { header: {
Authorization: "Bearer " + Taro.getStorageSync("token"), Authorization: "Bearer " + token,
...params.header, ...params.header,
"content-type": params.data.contentType, "content-type": params.data.contentType,
}, },
@ -208,7 +209,7 @@ export const AjaxFormData = (params) => {
content: "登录已过期,请重新登录", content: "登录已过期,请重新登录",
showCancel: false, showCancel: false,
}).then((res) => { }).then((res) => {
Taro.setStorageSync("token", null); setStorageSync("token", null);
Taro.clearStorage(); // 清空所有缓存 Taro.clearStorage(); // 清空所有缓存
Taro.reLaunch({ Taro.reLaunch({
url: "/pages/initiate/initiate", url: "/pages/initiate/initiate",
@ -240,7 +241,7 @@ export const AjaxFormData = (params) => {
}).then(() => { }).then(() => {
reject(res); reject(res);
if (res.data.code == 401 || res.data.msg === "登录状态已过期") { if (res.data.code == 401 || res.data.msg === "登录状态已过期") {
Taro.setStorageSync("token", null); setStorageSync("token", null);
Taro.reLaunch({ Taro.reLaunch({
url: "/pages/initiate/initiate", url: "/pages/initiate/initiate",
}); });

@ -1,4 +1,5 @@
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import dayjs from "dayjs";
export const goOpenSetting = () => { export const goOpenSetting = () => {
//去设置页的弹框 //去设置页的弹框
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
@ -286,27 +287,11 @@ export const setStorageSync = function (key, data, expires) {
// 如果没有传第三个有效期参数,就还是用原来的方法 // 如果没有传第三个有效期参数,就还是用原来的方法
if (!expires) return originSetStorageSync(key, data); if (!expires) return originSetStorageSync(key, data);
const reg = /\d{4}\/\d{1,12}\/\d{1,31}/; // 用来验证绝对时间格式`yyyy/MM/dd`或者`yyyy/MM/dd hh:mm:ss` if (typeof expires !== "number") {
if (reg.test(expires)) { console.error("expires is not a number");
// 绝对日期 return originSetStorageSync(key, data);
const timestamp = new Date(expires + "").getTime();
if (isNaN(timestamp)) {
console.error(
expires +
" error 请传入正确的日期格式yyyy/MM/dd 或者 yyyy/MM/dd hh:mm:ss"
);
return originSetStorageSync(key, data);
}
originSetStorageSync(key, { data, expires: timestamp });
} else {
// 相对日期
if (typeof expires !== "number") {
console.error("expires is not a number");
return originSetStorageSync(key, data);
}
originSetStorageSync(key, { data, expires: +new Date() + expires });
} }
originSetStorageSync(key, { data, expires: expires });
}; };
// 取 // 取
@ -314,10 +299,21 @@ const originGetStorageSymc = Taro.getStorageSync;
export const getStorageSync = function (key) { export const getStorageSync = function (key) {
const data = originGetStorageSymc(key); const data = originGetStorageSymc(key);
// 如果data不是个对象就说明是没加有效期的直接返回 // 如果data不是个对象就说明是没加有效期的直接返回
if (typeof data !== "object" || (typeof data === "object" && !data.expires)) if (typeof data !== "object" || (typeof data === "object" && !data.expires)) {
return data; return data;
}
const now = new Date().getTime();
// console.log(key, data);
//
// console.log("now", now, dayjs(now).format("YYYY-MM-DD hh:mm:ss"));
// console.log(
// "expires",
// data.expires,
// dayjs(data.expires).format("YYYY-MM-DD hh:mm:ss")
// );
// console.log("now < data.expires", now < data.expires);
const now = +new Date();
if (now < data.expires) { if (now < data.expires) {
//用当前时间和存储的时间对比 //用当前时间和存储的时间对比
return data.data; // 未过期返回data return data.data; // 未过期返回data

16861
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save