修改了主题切换的问题,但登录故障问题还有残留
This commit is contained in:
Vendored
+150
-43
@@ -58,31 +58,28 @@ function LoginGuard(props) {
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": function() { return /* binding */ ThemeToggle; }
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _tarojs_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @tarojs/components */ "./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js");
|
||||
/* harmony import */ var _tarojs_taro__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tarojs/taro */ "./node_modules/@tarojs/taro/index.js");
|
||||
/* harmony import */ var _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tarojs_taro__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react */ "./node_modules/react/cjs/react.production.min.js");
|
||||
/* harmony import */ var _context_ThemeContext__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../context/ThemeContext */ "./src/context/ThemeContext.tsx");
|
||||
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react/jsx-runtime */ "./node_modules/react/cjs/react-jsx-runtime.production.min.js");
|
||||
|
||||
/* harmony import */ var _tarojs_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @tarojs/components */ "./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js");
|
||||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "./node_modules/react/cjs/react.production.min.js");
|
||||
/* harmony import */ var _context_ThemeContext__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../context/ThemeContext */ "./src/context/ThemeContext.tsx");
|
||||
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react/jsx-runtime */ "./node_modules/react/cjs/react-jsx-runtime.production.min.js");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function ThemeToggle() {
|
||||
var _useThemeContext = (0,_context_ThemeContext__WEBPACK_IMPORTED_MODULE_2__.useThemeContext)(),
|
||||
var _useThemeContext = (0,_context_ThemeContext__WEBPACK_IMPORTED_MODULE_1__.useThemeContext)(),
|
||||
theme = _useThemeContext.theme,
|
||||
toggleTheme = _useThemeContext.toggleTheme;
|
||||
var handleToggle = (0,react__WEBPACK_IMPORTED_MODULE_1__.useCallback)(function () {
|
||||
var handleToggle = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
||||
// ThemeProvider 在 App.tsx 全局挂载,toggleTheme() 直接修改全局 state,
|
||||
// 不需要 eventCenter,所有页面会自动响应。
|
||||
toggleTheme();
|
||||
// 触发全局事件,让其他页面也能感知(切换tab后回来的页面会重新读取storage)
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().eventCenter.trigger('theme:change');
|
||||
}, [toggleTheme]);
|
||||
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_4__.View, {
|
||||
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_3__.View, {
|
||||
className: "theme-toggle",
|
||||
onClick: handleToggle,
|
||||
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_4__.Text, {
|
||||
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_3__.Text, {
|
||||
className: "theme-icon",
|
||||
children: theme === 'light' ? '🌙' : '☀️'
|
||||
})
|
||||
@@ -102,13 +99,10 @@ function ThemeToggle() {
|
||||
/* harmony export */ useThemeContext: function() { return /* binding */ useThemeContext; }
|
||||
/* harmony export */ });
|
||||
/* unused harmony export ThemeContext */
|
||||
/* harmony import */ var F_weixin_wordc_node_modules_babel_runtime_helpers_esm_slicedToArray_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js */ "./node_modules/@babel/runtime/helpers/esm/slicedToArray.js");
|
||||
/* harmony import */ var F_weixin_wordc_node_modules_babel_runtime_helpers_esm_slicedToArray_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js */ "./node_modules/@babel/runtime/helpers/esm/slicedToArray.js");
|
||||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "./node_modules/react/cjs/react.production.min.js");
|
||||
/* harmony import */ var _tarojs_taro__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tarojs/taro */ "./node_modules/@tarojs/taro/index.js");
|
||||
/* harmony import */ var _tarojs_taro__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_tarojs_taro__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _utils_store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/store */ "./src/utils/store.ts");
|
||||
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react/jsx-runtime */ "./node_modules/react/cjs/react-jsx-runtime.production.min.js");
|
||||
|
||||
/* harmony import */ var _utils_store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/store */ "./src/utils/store.ts");
|
||||
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react/jsx-runtime */ "./node_modules/react/cjs/react-jsx-runtime.production.min.js");
|
||||
|
||||
|
||||
|
||||
@@ -121,12 +115,12 @@ var ThemeContext = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.createCont
|
||||
|
||||
function ThemeProvider(_ref) {
|
||||
var children = _ref.children;
|
||||
var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)((0,_utils_store__WEBPACK_IMPORTED_MODULE_2__.getTheme)()),
|
||||
_useState2 = (0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_slicedToArray_js__WEBPACK_IMPORTED_MODULE_4__["default"])(_useState, 2),
|
||||
var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)((0,_utils_store__WEBPACK_IMPORTED_MODULE_1__.getTheme)()),
|
||||
_useState2 = (0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_slicedToArray_js__WEBPACK_IMPORTED_MODULE_3__["default"])(_useState, 2),
|
||||
theme = _useState2[0],
|
||||
set = _useState2[1];
|
||||
var setTheme = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function (t) {
|
||||
(0,_utils_store__WEBPACK_IMPORTED_MODULE_2__.setTheme)(t);
|
||||
(0,_utils_store__WEBPACK_IMPORTED_MODULE_1__.setTheme)(t);
|
||||
set(t);
|
||||
}, []);
|
||||
var toggleTheme = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
||||
@@ -134,17 +128,11 @@ function ThemeProvider(_ref) {
|
||||
setTheme(next);
|
||||
}, [theme, setTheme]);
|
||||
|
||||
// 监听全局主题变化事件(用于已挂载但未重新渲染的页面)
|
||||
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
|
||||
var listener = function listener(next) {
|
||||
return set(next);
|
||||
};
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_1___default().eventCenter.on('theme:change', listener);
|
||||
return function () {
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_1___default().eventCenter.off('theme:change', listener);
|
||||
};
|
||||
}, []);
|
||||
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(ThemeContext.Provider, {
|
||||
// eventCenter 监听已移除:ThemeContext 本身就在 App.tsx 全局挂载,
|
||||
// 所有页面共用一个 state,无需再靠事件广播。
|
||||
// 旧代码曾在此处监听 'theme:change' 并直接 set(参数),但 trigger 未传参数导致 theme 变成 undefined。
|
||||
|
||||
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(ThemeContext.Provider, {
|
||||
value: {
|
||||
theme: theme,
|
||||
toggleTheme: toggleTheme,
|
||||
@@ -185,7 +173,7 @@ var PRODUCTS = [{
|
||||
price: 12,
|
||||
leadTime: '3-5个工作日',
|
||||
description: '精选优质纸张,封面采用高档PU材质,手感细腻。内页可定制横线、方格或空白三种版式。激光微雕工艺将名字或图案精准刻印在封面,永不褪色。小巧轻便,适合随身携带,无论是课堂笔记还是日常备忘,都是你的专属伴侣。',
|
||||
images: ['/img/book_small/The1.png'],
|
||||
images: ['/img/book_small/The1.jpg'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 300,
|
||||
@@ -200,7 +188,7 @@ var PRODUCTS = [{
|
||||
price: 45,
|
||||
leadTime: '3-5个工作日',
|
||||
description: 'A4尺寸大开本,180°平摊设计,书写更自由。封面可选真皮、仿布纹或磨砂材质,激光微雕区域更大,适合呈现全班名字、团队口号或公司Logo等大篇幅内容。是毕业纪念、企业年会礼品的首选。',
|
||||
images: ['/img/book_big/The1.png', '/img/book_big/The2.png'],
|
||||
images: ['/img/book_big/The1.jpg', '/img/book_big/The2.jpg'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 340,
|
||||
@@ -229,7 +217,7 @@ var PRODUCTS = [{
|
||||
price: 75,
|
||||
leadTime: '7-10个工作日',
|
||||
description: '精选天然楠竹,经多道工序打磨抛光,保留天然竹纹肌理。盒盖采用磁吸开合,内部设有分层隔板。激光微雕在竹面上呈现深浅不一的雕刻效果,融入墨香气质。适合书房案头、书法爱好者的文房伴侣。',
|
||||
images: ['/img/penbox/The1.png', '/img/penbox/The2.png', '/img/penbox/The3.jpg'],
|
||||
images: ['/img/penbox/The1.jpg', '/img/penbox/The2.jpg', '/img/penbox/The3.jpg'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 320,
|
||||
@@ -277,20 +265,25 @@ var getProductById = function getProductById(id) {
|
||||
/* harmony export */ addAddress: function() { return /* binding */ addAddress; },
|
||||
/* harmony export */ addDesign: function() { return /* binding */ addDesign; },
|
||||
/* harmony export */ clearUserInfo: function() { return /* binding */ clearUserInfo; },
|
||||
/* harmony export */ createUser: function() { return /* binding */ createUser; },
|
||||
/* harmony export */ deleteAddress: function() { return /* binding */ deleteAddress; },
|
||||
/* harmony export */ deleteUser: function() { return /* binding */ deleteUser; },
|
||||
/* harmony export */ designToOrder: function() { return /* binding */ designToOrder; },
|
||||
/* harmony export */ getAddressList: function() { return /* binding */ getAddressList; },
|
||||
/* harmony export */ getDesignList: function() { return /* binding */ getDesignList; },
|
||||
/* harmony export */ getOrderList: function() { return /* binding */ getOrderList; },
|
||||
/* harmony export */ getTheme: function() { return /* binding */ getTheme; },
|
||||
/* harmony export */ getUserInfo: function() { return /* binding */ getUserInfo; },
|
||||
/* harmony export */ listAllUsers: function() { return /* binding */ listAllUsers; },
|
||||
/* harmony export */ setDesignList: function() { return /* binding */ setDesignList; },
|
||||
/* harmony export */ setTheme: function() { return /* binding */ setTheme; },
|
||||
/* harmony export */ setUserInfo: function() { return /* binding */ setUserInfo; },
|
||||
/* harmony export */ switchUser: function() { return /* binding */ switchUser; },
|
||||
/* harmony export */ updateAddress: function() { return /* binding */ updateAddress; },
|
||||
/* harmony export */ updateDesign: function() { return /* binding */ updateDesign; }
|
||||
/* harmony export */ updateDesign: function() { return /* binding */ updateDesign; },
|
||||
/* harmony export */ verifyAdminPassword: function() { return /* binding */ verifyAdminPassword; }
|
||||
/* harmony export */ });
|
||||
/* unused harmony exports getUserInfoRaw, setUserInfoRaw, setOrderList, setAddressList, getDefaultAddress */
|
||||
/* unused harmony exports getUserInfoRaw, setUserInfoRaw, getUserInfoByOpenid, setOrderList, setAddressList, getDefaultAddress */
|
||||
/* harmony import */ var F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js */ "./node_modules/@babel/runtime/helpers/esm/objectSpread2.js");
|
||||
/* harmony import */ var F_weixin_wordc_node_modules_babel_runtime_helpers_esm_toConsumableArray_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js */ "./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js");
|
||||
/* harmony import */ var _tarojs_taro__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tarojs/taro */ "./node_modules/@tarojs/taro/index.js");
|
||||
@@ -317,10 +310,38 @@ function key(scope) {
|
||||
|
||||
// ---------- 用户数据 ----------
|
||||
|
||||
var USER_REGISTRY_KEY = 'smart_user_registry';
|
||||
var ADMIN_PASSWORD = 'zhihui2024';
|
||||
|
||||
// ---------- 用户注册表 ----------
|
||||
|
||||
function getUserRegistry() {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(USER_REGISTRY_KEY) || [];
|
||||
} catch (_unused) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
function saveToRegistry(openid) {
|
||||
var list = getUserRegistry();
|
||||
if (!list.includes(openid)) {
|
||||
list.push(openid);
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(USER_REGISTRY_KEY, list);
|
||||
}
|
||||
}
|
||||
function removeFromRegistry(openid) {
|
||||
var list = getUserRegistry().filter(function (id) {
|
||||
return id !== openid;
|
||||
});
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(USER_REGISTRY_KEY, list);
|
||||
}
|
||||
|
||||
// ---------- 用户数据 ----------
|
||||
|
||||
function getUserInfoRaw() {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(USER_KEY);
|
||||
} catch (_unused) {
|
||||
} catch (_unused2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -328,9 +349,22 @@ function setUserInfoRaw(info) {
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(USER_KEY, info);
|
||||
if (info !== null && info !== void 0 && info.openid) {
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(ACTIVE_USER_KEY, info.openid);
|
||||
// 为每个用户备份独立副本,方便切换账号时读取
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync("user_info_".concat(info.openid), info);
|
||||
saveToRegistry(info.openid);
|
||||
}
|
||||
}
|
||||
function getUserInfoByOpenid(openid) {
|
||||
try {
|
||||
var backup = _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync("user_info_".concat(openid));
|
||||
if (backup) return backup;
|
||||
} catch (_unused3) {}
|
||||
var current = getUserInfoRaw();
|
||||
if ((current === null || current === void 0 ? void 0 : current.openid) === openid) return current;
|
||||
return null;
|
||||
}
|
||||
function clearUserInfo() {
|
||||
// 仅退出登录,不删除用户数据
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().removeStorageSync(USER_KEY);
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().removeStorageSync(ACTIVE_USER_KEY);
|
||||
}
|
||||
@@ -341,12 +375,85 @@ function getUserInfo() {
|
||||
return getUserInfoRaw();
|
||||
}
|
||||
|
||||
// ---------- 用户数据库管理 ----------
|
||||
|
||||
function listAllUsers() {
|
||||
var registry = getUserRegistry();
|
||||
return registry.map(function (openid) {
|
||||
var info = getUserInfoByOpenid(openid);
|
||||
var dList = getDesignListFor(openid);
|
||||
var oList = getOrderListFor(openid);
|
||||
return {
|
||||
openid: openid,
|
||||
nickName: (info === null || info === void 0 ? void 0 : info.nickName) || '未知用户',
|
||||
avatarUrl: (info === null || info === void 0 ? void 0 : info.avatarUrl) || '',
|
||||
loginAt: (info === null || info === void 0 ? void 0 : info.loginAt) || 0,
|
||||
designCount: dList.length,
|
||||
orderCount: oList.length
|
||||
};
|
||||
});
|
||||
}
|
||||
function createUser(nickName, avatarUrl) {
|
||||
var openid = 'mock_' + Date.now().toString(36) + '_' + Math.random().toString(36).slice(2, 6);
|
||||
var info = {
|
||||
openid: openid,
|
||||
nickName: nickName || '微信用户',
|
||||
avatarUrl: avatarUrl || '',
|
||||
loginAt: Date.now()
|
||||
};
|
||||
setUserInfoRaw(info);
|
||||
return info;
|
||||
}
|
||||
function switchUser(openid) {
|
||||
var info = getUserInfoByOpenid(openid);
|
||||
if (!info) return false;
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(USER_KEY, info);
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(ACTIVE_USER_KEY, openid);
|
||||
return true;
|
||||
}
|
||||
function deleteUser(openid) {
|
||||
// 删除该用户的所有数据
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().removeStorageSync("user_info_".concat(openid));
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().removeStorageSync("design_list_".concat(openid));
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().removeStorageSync("order_list_".concat(openid));
|
||||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().removeStorageSync("address_list_".concat(openid));
|
||||
removeFromRegistry(openid);
|
||||
// 如果删的是当前登录用户,清掉登录态
|
||||
var current = getUserInfoRaw();
|
||||
if ((current === null || current === void 0 ? void 0 : current.openid) === openid) {
|
||||
clearUserInfo();
|
||||
}
|
||||
}
|
||||
function verifyAdminPassword(password) {
|
||||
return password === ADMIN_PASSWORD;
|
||||
}
|
||||
|
||||
// ---------- 跨用户读取辅助函数 ----------
|
||||
|
||||
function keyFor(scope, openid) {
|
||||
return "".concat(scope, "_").concat(openid);
|
||||
}
|
||||
function getDesignListFor(openid) {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(keyFor('design_list', openid)) || [];
|
||||
} catch (_unused4) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
function getOrderListFor(openid) {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(keyFor('order_list', openid)) || [];
|
||||
} catch (_unused5) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 设计清单 ----------
|
||||
|
||||
function getDesignList() {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(key('design_list')) || [];
|
||||
} catch (_unused2) {
|
||||
} catch (_unused6) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -383,7 +490,7 @@ function updateDesign(id, patch) {
|
||||
function getOrderList() {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(key('order_list')) || [];
|
||||
} catch (_unused3) {
|
||||
} catch (_unused7) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -429,7 +536,7 @@ function designToOrder(designId) {
|
||||
function getTheme() {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(THEME_KEY) || 'light';
|
||||
} catch (_unused4) {
|
||||
} catch (_unused8) {
|
||||
return 'light';
|
||||
}
|
||||
}
|
||||
@@ -442,7 +549,7 @@ function setTheme(theme) {
|
||||
function getAddressList() {
|
||||
try {
|
||||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(key('address_list')) || [];
|
||||
} catch (_unused5) {
|
||||
} catch (_unused9) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user