373 lines
15 KiB
JavaScript
373 lines
15 KiB
JavaScript
"use strict";
|
|
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([["common"],{
|
|
|
|
/***/ "./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 () {
|
|
toggleTheme();
|
|
// 触发全局事件,让其他已挂载页面也能感知
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
var Taro = (__webpack_require__(/*! @tarojs/taro */ "./node_modules/@tarojs/taro/index.js")["default"]);
|
|
Taro.eventCenter.trigger('theme:storageChanged');
|
|
}, [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_4__ = __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");
|
|
|
|
|
|
|
|
|
|
|
|
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_2__.getTheme)()),
|
|
_useState2 = (0,F_weixin_wordc_node_modules_babel_runtime_helpers_esm_slicedToArray_js__WEBPACK_IMPORTED_MODULE_4__["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);
|
|
set(t);
|
|
}, []);
|
|
var toggleTheme = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
|
var next = theme === 'light' ? 'dark' : 'light';
|
|
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, {
|
|
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.png'],
|
|
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.png', '/img/book_big/The2.png'],
|
|
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.png', '/img/penbox/The2.png', '/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 */ addDesign: function() { return /* binding */ addDesign; },
|
|
/* harmony export */ designToOrder: function() { return /* binding */ designToOrder; },
|
|
/* 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 */ setDesignList: function() { return /* binding */ setDesignList; },
|
|
/* harmony export */ setTheme: function() { return /* binding */ setTheme; },
|
|
/* harmony export */ setUserInfo: function() { return /* binding */ setUserInfo; },
|
|
/* harmony export */ updateDesign: function() { return /* binding */ updateDesign; }
|
|
/* harmony export */ });
|
|
/* unused harmony export setOrderList */
|
|
/* 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 DESIGN_KEY = 'smart_design_list';
|
|
var ORDER_KEY = 'smart_order_list';
|
|
var USER_KEY = 'smart_user_info';
|
|
var THEME_KEY = 'smart_theme';
|
|
|
|
/** 获取设计清单 */
|
|
var getDesignList = function getDesignList() {
|
|
try {
|
|
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(DESIGN_KEY) || [];
|
|
} catch (_unused) {
|
|
return [];
|
|
}
|
|
};
|
|
|
|
/** 保存设计清单 */
|
|
var setDesignList = function setDesignList(list) {
|
|
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(DESIGN_KEY, list);
|
|
};
|
|
|
|
/** 获取订单列表 */
|
|
var getOrderList = function getOrderList() {
|
|
try {
|
|
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(ORDER_KEY) || [];
|
|
} catch (_unused2) {
|
|
return [];
|
|
}
|
|
};
|
|
|
|
/** 保存订单列表 */
|
|
var setOrderList = function setOrderList(list) {
|
|
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(ORDER_KEY, list);
|
|
};
|
|
|
|
/** 添加设计清单条目 */
|
|
var addDesign = 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;
|
|
};
|
|
|
|
/** 更新设计清单条目 */
|
|
var updateDesign = 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);
|
|
};
|
|
|
|
/** 设计转订单 */
|
|
var designToOrder = 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)
|
|
};
|
|
|
|
// 更新 design 状态
|
|
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;
|
|
};
|
|
|
|
/** 用户数据 */
|
|
var getUserInfo = function getUserInfo() {
|
|
try {
|
|
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(USER_KEY);
|
|
} catch (_unused3) {
|
|
return null;
|
|
}
|
|
};
|
|
var setUserInfo = function setUserInfo(info) {
|
|
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(USER_KEY, info);
|
|
};
|
|
|
|
/** 主题 */
|
|
|
|
var getTheme = function getTheme() {
|
|
try {
|
|
return _tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().getStorageSync(THEME_KEY) || 'light';
|
|
} catch (_unused4) {
|
|
return 'light';
|
|
}
|
|
};
|
|
var setTheme = function setTheme(theme) {
|
|
_tarojs_taro__WEBPACK_IMPORTED_MODULE_0___default().setStorageSync(THEME_KEY, theme);
|
|
};
|
|
|
|
/***/ })
|
|
|
|
}]);
|
|
//# sourceMappingURL=common.js.map
|