600 lines
25 KiB
JavaScript
600 lines
25 KiB
JavaScript
"use strict";
|
||
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([["common"],{
|
||
|
||
/***/ "./src/components/LoginGuard/index.tsx":
|
||
/*!*********************************************!*\
|
||
!*** ./src/components/LoginGuard/index.tsx ***!
|
||
\*********************************************/
|
||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
||
|
||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||
/* harmony export */ "default": function() { return /* binding */ LoginGuard; }
|
||
/* harmony export */ });
|
||
/* 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 _tarojs_components__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @tarojs/components */ "./node_modules/@tarojs/plugin-platform-weapp/dist/components-react.js");
|
||
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react/jsx-runtime */ "./node_modules/react/cjs/react-jsx-runtime.production.min.js");
|
||
|
||
|
||
|
||
function LoginGuard(props) {
|
||
var user = _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync('smart_user_info');
|
||
if (!(user !== null && user !== void 0 && user.openid)) {
|
||
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsxs)(_tarojs_components__WEBPACK_IMPORTED_MODULE_2__.View, {
|
||
className: "login-guard",
|
||
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_2__.Text, {
|
||
className: "login-guard-icon",
|
||
children: "\uD83D\uDD12"
|
||
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_2__.Text, {
|
||
className: "login-guard-title",
|
||
children: "\u8BF7\u5148\u767B\u5F55"
|
||
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_2__.Text, {
|
||
className: "login-guard-desc",
|
||
children: "\u767B\u5F55\u540E\u67E5\u770B\u60A8\u7684\u4E13\u5C5E\u5185\u5BB9"
|
||
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_2__.View, {
|
||
className: "btn-gradient login-guard-btn",
|
||
onClick: function onClick() {
|
||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().switchTab({
|
||
url: '/pages/profile/index'
|
||
});
|
||
},
|
||
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_2__.Text, {
|
||
children: "\u53BB\u767B\u5F55"
|
||
})
|
||
})]
|
||
});
|
||
}
|
||
return props.children;
|
||
}
|
||
|
||
/***/ }),
|
||
|
||
/***/ "./src/components/ThemeToggle/index.tsx":
|
||
/*!**********************************************!*\
|
||
!*** ./src/components/ThemeToggle/index.tsx ***!
|
||
\**********************************************/
|
||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
||
|
||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||
/* harmony export */ "default": function() { return /* binding */ ThemeToggle; }
|
||
/* harmony export */ });
|
||
/* 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_1__.useThemeContext)(),
|
||
theme = _useThemeContext.theme,
|
||
toggleTheme = _useThemeContext.toggleTheme;
|
||
var handleToggle = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
||
// ThemeProvider 在 App.tsx 全局挂载,toggleTheme() 直接修改全局 state,
|
||
// 不需要 eventCenter,所有页面会自动响应。
|
||
toggleTheme();
|
||
}, [toggleTheme]);
|
||
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_2__.jsx)(_tarojs_components__WEBPACK_IMPORTED_MODULE_3__.Text, {
|
||
className: "theme-icon",
|
||
children: theme === 'light' ? '🌙' : '☀️'
|
||
})
|
||
});
|
||
}
|
||
|
||
/***/ }),
|
||
|
||
/***/ "./src/context/ThemeContext.tsx":
|
||
/*!**************************************!*\
|
||
!*** ./src/context/ThemeContext.tsx ***!
|
||
\**************************************/
|
||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
||
|
||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||
/* harmony export */ ThemeProvider: function() { return /* binding */ ThemeProvider; },
|
||
/* 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_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 _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");
|
||
|
||
|
||
|
||
|
||
var ThemeContext = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.createContext)({
|
||
theme: 'light',
|
||
toggleTheme: function toggleTheme() {},
|
||
setTheme: function setTheme() {}
|
||
});
|
||
|
||
function ThemeProvider(_ref) {
|
||
var children = _ref.children;
|
||
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_1__.setTheme)(t);
|
||
set(t);
|
||
}, []);
|
||
var toggleTheme = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
||
var next = theme === 'light' ? 'dark' : 'light';
|
||
setTheme(next);
|
||
}, [theme, setTheme]);
|
||
|
||
// 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,
|
||
setTheme: setTheme
|
||
},
|
||
children: children
|
||
});
|
||
}
|
||
function useThemeContext() {
|
||
return (0,react__WEBPACK_IMPORTED_MODULE_0__.useContext)(ThemeContext);
|
||
}
|
||
|
||
/***/ }),
|
||
|
||
/***/ "./src/utils/productConfig.ts":
|
||
/*!************************************!*\
|
||
!*** ./src/utils/productConfig.ts ***!
|
||
\************************************/
|
||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
||
|
||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||
/* harmony export */ CATEGORIES: function() { return /* binding */ CATEGORIES; },
|
||
/* harmony export */ getProductById: function() { return /* binding */ getProductById; }
|
||
/* harmony export */ });
|
||
/* unused harmony export PRODUCTS */
|
||
/**
|
||
* 产品品类配置文件
|
||
*
|
||
* ⚠️ 重要:当实际产品尺寸确定后,请修改本文件中的 mask 参数
|
||
* 修改后页面会自动生效,无需改动其他代码
|
||
*/
|
||
|
||
var PRODUCTS = [{
|
||
id: 'notebook-small',
|
||
name: '微雕笔记本(小)',
|
||
desc: '便携随行,记录点滴',
|
||
icon: '📓',
|
||
price: 12,
|
||
leadTime: '3-5个工作日',
|
||
description: '精选优质纸张,封面采用高档PU材质,手感细腻。内页可定制横线、方格或空白三种版式。激光微雕工艺将名字或图案精准刻印在封面,永不褪色。小巧轻便,适合随身携带,无论是课堂笔记还是日常备忘,都是你的专属伴侣。',
|
||
images: ['/img/book_small/The1.jpg'],
|
||
mask: {
|
||
shape: 'rect',
|
||
width: 300,
|
||
height: 420,
|
||
borderRadius: 8
|
||
}
|
||
}, {
|
||
id: 'notebook-large',
|
||
name: '微雕笔记本(大)',
|
||
desc: '大开本,更多创作空间',
|
||
icon: '📔',
|
||
price: 45,
|
||
leadTime: '3-5个工作日',
|
||
description: 'A4尺寸大开本,180°平摊设计,书写更自由。封面可选真皮、仿布纹或磨砂材质,激光微雕区域更大,适合呈现全班名字、团队口号或公司Logo等大篇幅内容。是毕业纪念、企业年会礼品的首选。',
|
||
images: ['/img/book_big/The1.jpg', '/img/book_big/The2.jpg'],
|
||
mask: {
|
||
shape: 'rect',
|
||
width: 340,
|
||
height: 480,
|
||
borderRadius: 8
|
||
}
|
||
}, {
|
||
id: 'coaster',
|
||
name: '铜质杯垫',
|
||
desc: '金属质感,桌面艺术',
|
||
icon: '☕',
|
||
price: 25,
|
||
leadTime: '5-7个工作日',
|
||
description: '采用优质黄铜材质,表面经拉丝工艺处理,呈现哑光金属质感。背面配有防滑软木垫,保护桌面同时防止滑动。激光微雕可在表面刻印名字、日期或祝福语,是乔迁新居、新婚贺礼的精致之选。',
|
||
images: ['/img/cup/The1.jpg'],
|
||
mask: {
|
||
shape: 'circle',
|
||
width: 280,
|
||
height: 280
|
||
}
|
||
}, {
|
||
id: 'penbox',
|
||
name: '竹制笔盒',
|
||
desc: '自然竹纹,文房雅器',
|
||
icon: '✏️',
|
||
price: 75,
|
||
leadTime: '7-10个工作日',
|
||
description: '精选天然楠竹,经多道工序打磨抛光,保留天然竹纹肌理。盒盖采用磁吸开合,内部设有分层隔板。激光微雕在竹面上呈现深浅不一的雕刻效果,融入墨香气质。适合书房案头、书法爱好者的文房伴侣。',
|
||
images: ['/img/penbox/The1.jpg', '/img/penbox/The2.jpg', '/img/penbox/The3.jpg'],
|
||
mask: {
|
||
shape: 'rect',
|
||
width: 320,
|
||
height: 160,
|
||
borderRadius: 12
|
||
}
|
||
}, {
|
||
id: 'booklamp',
|
||
name: '书本型灯',
|
||
desc: '温暖光影,点亮心意',
|
||
icon: '💡',
|
||
price: 45,
|
||
leadTime: '5-7个工作日',
|
||
description: '开合式设计,打开即亮,合拢即灭,如魔法书般充满惊喜。采用LED暖光灯源,光线柔和不刺眼,可持续点亮6-8小时。封面激光微雕可定制文字、图案或照片,让温暖的灯光承载专属记忆。是情侣礼物、毕业礼物的创意之选。',
|
||
images: ['/img/booklight/The1.jpg', '/img/booklight/The2.jpg'],
|
||
mask: {
|
||
shape: 'rect',
|
||
width: 320,
|
||
height: 240,
|
||
borderRadius: 4
|
||
}
|
||
}];
|
||
|
||
/** CATEGORIES 为 PRODUCTS 的别名,供页面引用 */
|
||
var CATEGORIES = PRODUCTS;
|
||
|
||
/**
|
||
* 根据产品ID查找品类配置
|
||
*/
|
||
var getProductById = function getProductById(id) {
|
||
return PRODUCTS.find(function (p) {
|
||
return p.id === id;
|
||
});
|
||
};
|
||
|
||
/***/ }),
|
||
|
||
/***/ "./src/utils/store.ts":
|
||
/*!****************************!*\
|
||
!*** ./src/utils/store.ts ***!
|
||
\****************************/
|
||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
||
|
||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||
/* 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 */ verifyAdminPassword: function() { return /* binding */ verifyAdminPassword; }
|
||
/* harmony export */ });
|
||
/* 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");
|
||
/* harmony import */ var _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tarojs_taro__WEBPACK_IMPORTED_MODULE_0__);
|
||
|
||
|
||
|
||
var THEME_KEY = 'smart_theme';
|
||
var USER_KEY = 'smart_user_info';
|
||
var ACTIVE_USER_KEY = 'smart_active_openid';
|
||
|
||
// ---------- 当前用户 openid 管理 ----------
|
||
|
||
function getActiveOpenid() {
|
||
var user = getUserInfoRaw();
|
||
var openid = (user === null || user === void 0 ? void 0 : user.openid) || _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(ACTIVE_USER_KEY) || '_guest_';
|
||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(ACTIVE_USER_KEY, openid);
|
||
return openid;
|
||
}
|
||
function key(scope) {
|
||
var prefix = getActiveOpenid();
|
||
return "".concat(scope, "_").concat(prefix);
|
||
}
|
||
|
||
// ---------- 用户数据 ----------
|
||
|
||
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 (_unused2) {
|
||
return null;
|
||
}
|
||
}
|
||
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);
|
||
}
|
||
function setUserInfo(info) {
|
||
setUserInfoRaw(info);
|
||
}
|
||
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 (_unused6) {
|
||
return [];
|
||
}
|
||
}
|
||
function setDesignList(list) {
|
||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(key('design_list'), list);
|
||
}
|
||
function addDesign(product, count) {
|
||
var list = getDesignList();
|
||
var item = {
|
||
id: 'DSG' + Date.now(),
|
||
productId: product.id,
|
||
productName: product.name,
|
||
productIcon: product.icon,
|
||
unitPrice: product.price,
|
||
count: count,
|
||
status: 'undesigned',
|
||
createdAt: new Date().toISOString().slice(0, 10)
|
||
};
|
||
setDesignList([].concat((0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_toConsumableArray_js__WEBPACK_IMPORTED_MODULE_1__["default"])(list), [item]));
|
||
return item;
|
||
}
|
||
function updateDesign(id, patch) {
|
||
var list = getDesignList();
|
||
var idx = list.findIndex(function (d) {
|
||
return d.id === id;
|
||
});
|
||
if (idx === -1) return;
|
||
list[idx] = (0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__["default"])((0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__["default"])({}, list[idx]), patch);
|
||
setDesignList(list);
|
||
}
|
||
|
||
// ---------- 订单 ----------
|
||
|
||
function getOrderList() {
|
||
try {
|
||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(key('order_list')) || [];
|
||
} catch (_unused7) {
|
||
return [];
|
||
}
|
||
}
|
||
function setOrderList(list) {
|
||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(key('order_list'), list);
|
||
}
|
||
function designToOrder(designId) {
|
||
var dList = getDesignList();
|
||
var oList = getOrderList();
|
||
var design = dList.find(function (d) {
|
||
return d.id === designId;
|
||
});
|
||
if (!design) return null;
|
||
var order = {
|
||
id: 'ORD' + Date.now().toString().slice(-9),
|
||
productName: design.productName,
|
||
productIcon: design.productIcon,
|
||
statusCode: 'pending',
|
||
date: new Date().toLocaleString('zh-CN', {
|
||
month: '2-digit',
|
||
day: '2-digit',
|
||
hour: '2-digit',
|
||
minute: '2-digit'
|
||
}).replace(/\//g, '-'),
|
||
price: '¥' + (design.unitPrice * design.count).toFixed(2),
|
||
count: design.count,
|
||
sku: "".concat(design.productName, " \xD7 ").concat(design.count)
|
||
};
|
||
var dIdx = dList.findIndex(function (d) {
|
||
return d.id === designId;
|
||
});
|
||
if (dIdx !== -1) {
|
||
dList[dIdx].status = 'ordered';
|
||
dList[dIdx].orderId = order.id;
|
||
}
|
||
setDesignList(dList);
|
||
setOrderList([order].concat((0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_toConsumableArray_js__WEBPACK_IMPORTED_MODULE_1__["default"])(oList)));
|
||
return order;
|
||
}
|
||
|
||
// ---------- 主题 ----------
|
||
|
||
function getTheme() {
|
||
try {
|
||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(THEME_KEY) || 'light';
|
||
} catch (_unused8) {
|
||
return 'light';
|
||
}
|
||
}
|
||
function setTheme(theme) {
|
||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(THEME_KEY, theme);
|
||
}
|
||
|
||
// ---------- 收货地址 ----------
|
||
|
||
function getAddressList() {
|
||
try {
|
||
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(key('address_list')) || [];
|
||
} catch (_unused9) {
|
||
return [];
|
||
}
|
||
}
|
||
function setAddressList(list) {
|
||
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(key('address_list'), list);
|
||
}
|
||
function addAddress(addr) {
|
||
var list = getAddressList();
|
||
var item = (0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__["default"])((0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__["default"])({}, addr), {}, {
|
||
id: 'ADR' + Date.now()
|
||
});
|
||
// 若设为默认,取消其他默认
|
||
if (item.isDefault) {
|
||
list.forEach(function (a) {
|
||
a.isDefault = false;
|
||
});
|
||
}
|
||
setAddressList([item].concat((0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_toConsumableArray_js__WEBPACK_IMPORTED_MODULE_1__["default"])(list)));
|
||
return item;
|
||
}
|
||
function updateAddress(id, patch) {
|
||
var list = getAddressList();
|
||
var idx = list.findIndex(function (a) {
|
||
return a.id === id;
|
||
});
|
||
if (idx === -1) return;
|
||
if (patch.isDefault) list.forEach(function (a) {
|
||
a.isDefault = false;
|
||
});
|
||
list[idx] = (0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__["default"])((0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_2__["default"])({}, list[idx]), patch);
|
||
setAddressList(list);
|
||
}
|
||
function deleteAddress(id) {
|
||
var list = getAddressList().filter(function (a) {
|
||
return a.id !== id;
|
||
});
|
||
setAddressList(list);
|
||
}
|
||
function getDefaultAddress() {
|
||
return getAddressList().find(function (a) {
|
||
return a.isDefault;
|
||
});
|
||
}
|
||
|
||
/***/ })
|
||
|
||
}]);
|
||
//# sourceMappingURL=common.js.map
|