diff --git a/backend/src/routes/qrcodeRoutes.js b/backend/src/routes/qrcodeRoutes.js index 06495f9..b849a0b 100644 --- a/backend/src/routes/qrcodeRoutes.js +++ b/backend/src/routes/qrcodeRoutes.js @@ -1,13 +1,55 @@ const express = require('express'); const router = express.Router(); +const axios = require('axios'); const { authenticateUser } = require('../middleware/auth'); const User = require('../models/User'); +const env = require('../config/env'); + +// 缓存 access_token +let accessTokenCache = { + token: null, + expiresAt: 0 +}; + +/** + * 获取微信 access_token + */ +async function getAccessToken() { + const now = Date.now(); + + // 如果缓存有效,直接返回 + if (accessTokenCache.token && accessTokenCache.expiresAt > now) { + return accessTokenCache.token; + } + + // 调用微信API获取 access_token + const url = 'https://api.weixin.qq.com/cgi-bin/token'; + const response = await axios.get(url, { + params: { + grant_type: 'client_credential', + appid: env.wechat.appId, + secret: env.wechat.appSecret + } + }); + + if (response.data.errcode) { + throw new Error(`获取access_token失败: ${response.data.errmsg}`); + } + + // 缓存 token,提前5分钟过期 + accessTokenCache = { + token: response.data.access_token, + expiresAt: now + (response.data.expires_in - 300) * 1000 + }; + + return accessTokenCache.token; +} /** * @swagger * /api/v1/qrcode/miniprogram: * post: - * summary: 获取小程序码信息 + * summary: 获取小程序码 * tags: [QRCode] * security: * - bearerAuth: [] @@ -17,18 +59,17 @@ const User = require('../models/User'); * schema: * type: object * properties: - * path: - * type: string * width: * type: number + * description: 二维码宽度,默认430 * responses: * 200: - * description: 成功 + * description: 成功返回小程序码图片的base64 */ router.post('/miniprogram', authenticateUser, async (req, res) => { try { const userId = req.user.id; - const { path, width } = req.body; + const { width = 430 } = req.body; // 获取用户邀请码 const user = await User.findByPk(userId, { @@ -37,8 +78,9 @@ router.post('/miniprogram', authenticateUser, async (req, res) => { if (!user) { return res.status(404).json({ - success: false, - error: { code: 'USER_NOT_FOUND', message: 'User not found' } + code: 404, + message: 'User not found', + data: null }); } @@ -49,20 +91,52 @@ router.post('/miniprogram', authenticateUser, async (req, res) => { await user.update({ invitationCode }); } - // 目前返回邀请码信息,前端可以用 canvas 绘制 + // 获取 access_token + const accessToken = await getAccessToken(); + + // 调用微信API生成小程序码(使用 getUnlimited 接口,无数量限制) + const wxUrl = `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${accessToken}`; + const wxResponse = await axios.post(wxUrl, { + scene: `inviteCode=${invitationCode}`, // scene 参数,最长32字符 + page: 'pages/index/index', // 必须是已发布的小程序页面 + width: width, + auto_color: false, + line_color: { r: 0, g: 0, b: 0 }, + is_hyaline: false + }, { + responseType: 'arraybuffer' // 返回的是图片二进制数据 + }); + + // 检查是否返回错误(错误时返回JSON) + const contentType = wxResponse.headers['content-type']; + if (contentType && contentType.includes('application/json')) { + const errorData = JSON.parse(wxResponse.data.toString()); + console.error('微信小程序码生成失败:', errorData); + return res.status(200).json({ + code: 500, + message: errorData.errmsg || '生成小程序码失败', + data: null + }); + } + + // 转换为 base64 + const base64Image = Buffer.from(wxResponse.data).toString('base64'); + const dataUrl = `data:image/png;base64,${base64Image}`; + return res.status(200).json({ - success: true, + code: 0, + message: 'success', data: { invitationCode, - path: path || `pages/index/index?inviteCode=${invitationCode}`, - message: '请使用邀请码分享给好友' + qrcodeUrl: dataUrl // base64格式的小程序码图片 } }); } catch (error) { console.error('Get miniprogram qrcode error:', error); - return res.status(500).json({ - success: false, - error: { code: 'QRCODE_ERROR', message: error.message } + return res.status(200).json({ + code: 500, + message: error.message || '生成小程序码失败', + data: null }); } }); diff --git a/miniprogram/dist/dev/mp-weixin/app.js b/miniprogram/dist/dev/mp-weixin/app.js index b594bed..430d85f 100644 --- a/miniprogram/dist/dev/mp-weixin/app.js +++ b/miniprogram/dist/dev/mp-weixin/app.js @@ -44,8 +44,10 @@ const _sfc_main = { user: null, shouldRefresh: false, loginTime: 0, - config: null + config: null, // 应用配置(从后端获取) + inviteCode: "" + // 邀请码(从分享链接获取) }, onLaunch: function() { console.log("App Launch"); diff --git a/miniprogram/dist/dev/mp-weixin/common/vendor.js b/miniprogram/dist/dev/mp-weixin/common/vendor.js index 648e418..3a35e39 100644 --- a/miniprogram/dist/dev/mp-weixin/common/vendor.js +++ b/miniprogram/dist/dev/mp-weixin/common/vendor.js @@ -689,20 +689,20 @@ function queue$2(hooks, data, params2) { } }; } -function wrapperOptions(interceptors2, options2 = {}) { +function wrapperOptions(interceptors2, options = {}) { [HOOK_SUCCESS, HOOK_FAIL, HOOK_COMPLETE].forEach((name) => { const hooks = interceptors2[name]; if (!isArray$2(hooks)) { return; } - const oldCallback = options2[name]; - options2[name] = function callbackInterceptor(res) { - queue$2(hooks, res, options2).then((res2) => { + const oldCallback = options[name]; + options[name] = function callbackInterceptor(res) { + queue$2(hooks, res, options).then((res2) => { return isFunction$1(oldCallback) && oldCallback(res2) || res2; }); }; }); - return options2; + return options; } function wrapperReturnValue(method, returnValue) { const returnValueHooks = []; @@ -735,19 +735,19 @@ function getApiInterceptorHooks(method) { } return interceptor; } -function invokeApi(method, api, options2, params2) { +function invokeApi(method, api, options, params2) { const interceptor = getApiInterceptorHooks(method); if (interceptor && Object.keys(interceptor).length) { if (isArray$2(interceptor.invoke)) { - const res = queue$2(interceptor.invoke, options2); - return res.then((options3) => { - return api(wrapperOptions(getApiInterceptorHooks(method), options3), ...params2); + const res = queue$2(interceptor.invoke, options); + return res.then((options2) => { + return api(wrapperOptions(getApiInterceptorHooks(method), options2), ...params2); }); } else { - return api(wrapperOptions(interceptor, options2), ...params2); + return api(wrapperOptions(interceptor, options), ...params2); } } - return api(options2, ...params2); + return api(options, ...params2); } function hasCallback(args) { if (isPlainObject$2(args) && [API_SUCCESS, API_FAIL, API_COMPLETE].find((cb) => isFunction$1(args[cb]))) { @@ -768,12 +768,12 @@ function promisify$1(name, fn) { }))); }; } -function formatApiArgs(args, options2) { +function formatApiArgs(args, options) { const params2 = args[0]; - if (!options2 || !isPlainObject$2(options2.formatArgs) && isPlainObject$2(params2)) { + if (!options || !isPlainObject$2(options.formatArgs) && isPlainObject$2(params2)) { return; } - const formatArgs = options2.formatArgs; + const formatArgs = options.formatArgs; const keys = Object.keys(formatArgs); for (let i = 0; i < keys.length; i++) { const name = keys[i]; @@ -802,17 +802,17 @@ function invokeFail(id, name, errMsg, errRes = {}) { let res = extend({ errMsg: apiErrMsg }, errRes); return invokeCallback(id, res); } -function beforeInvokeApi(name, args, protocol, options2) { +function beforeInvokeApi(name, args, protocol, options) { { validateProtocols(name, args, protocol); } - if (options2 && options2.beforeInvoke) { - const errMsg2 = options2.beforeInvoke(args); + if (options && options.beforeInvoke) { + const errMsg2 = options.beforeInvoke(args); if (isString$1(errMsg2)) { return errMsg2; } } - const errMsg = formatApiArgs(args, options2); + const errMsg = formatApiArgs(args, options); if (errMsg) { return errMsg; } @@ -827,10 +827,10 @@ function normalizeErrMsg(errMsg) { } return errMsg; } -function wrapperTaskApi(name, fn, protocol, options2) { +function wrapperTaskApi(name, fn, protocol, options) { return (args) => { - const id = createAsyncApiCallback(name, args, options2); - const errMsg = beforeInvokeApi(name, [args], protocol, options2); + const id = createAsyncApiCallback(name, args, options); + const errMsg = beforeInvokeApi(name, [args], protocol, options); if (errMsg) { return invokeFail(id, name, errMsg); } @@ -840,23 +840,23 @@ function wrapperTaskApi(name, fn, protocol, options2) { }); }; } -function wrapperSyncApi(name, fn, protocol, options2) { +function wrapperSyncApi(name, fn, protocol, options) { return (...args) => { - const errMsg = beforeInvokeApi(name, args, protocol, options2); + const errMsg = beforeInvokeApi(name, args, protocol, options); if (errMsg) { throw new Error(errMsg); } return fn.apply(null, args); }; } -function wrapperAsyncApi(name, fn, protocol, options2) { - return wrapperTaskApi(name, fn, protocol, options2); +function wrapperAsyncApi(name, fn, protocol, options) { + return wrapperTaskApi(name, fn, protocol, options); } -function defineSyncApi(name, fn, protocol, options2) { - return wrapperSyncApi(name, fn, protocol, options2); +function defineSyncApi(name, fn, protocol, options) { + return wrapperSyncApi(name, fn, protocol, options); } -function defineAsyncApi(name, fn, protocol, options2) { - return promisify$1(name, wrapperAsyncApi(name, fn, protocol, options2)); +function defineAsyncApi(name, fn, protocol, options) { + return promisify$1(name, wrapperAsyncApi(name, fn, protocol, options)); } const API_UPX2PX = "upx2px"; const Upx2pxProtocol = [ @@ -1132,12 +1132,12 @@ function promisify(name, api) { if (!isFunction$1(api)) { return api; } - return function promiseApi(options2 = {}, ...rest) { - if (isFunction$1(options2.success) || isFunction$1(options2.fail) || isFunction$1(options2.complete)) { - return wrapperReturnValue(name, invokeApi(name, api, options2, rest)); + return function promiseApi(options = {}, ...rest) { + if (isFunction$1(options.success) || isFunction$1(options.fail) || isFunction$1(options.complete)) { + return wrapperReturnValue(name, invokeApi(name, api, options, rest)); } return wrapperReturnValue(name, handlePromise(new Promise((resolve2, reject) => { - invokeApi(name, api, extend({}, options2, { + invokeApi(name, api, extend({}, options, { success: resolve2, fail: reject }), rest); @@ -1204,18 +1204,18 @@ function initWrapper(protocols2) { }; } return function(arg1, arg2) { - let options2 = protocol; + let options = protocol; if (isFunction$1(protocol)) { - options2 = protocol(arg1); + options = protocol(arg1); } - arg1 = processArgs(methodName, arg1, options2.args, options2.returnValue); + arg1 = processArgs(methodName, arg1, options.args, options.returnValue); const args = [arg1]; if (typeof arg2 !== "undefined") { args.push(arg2); } - const returnValue = wx[options2.name || methodName].apply(wx, args); + const returnValue = wx[options.name || methodName].apply(wx, args); if (isSyncApi(methodName)) { - return processReturnValue(methodName, returnValue, options2.returnValue, isContextApi(methodName)); + return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName)); } return returnValue; }; @@ -1294,7 +1294,7 @@ function populateParameters(fromRes, toRes) { const hostLanguage = language.replace(/_/g, "-"); const parameters = { appId: "__UNI__C6C43F9", - appName: "appointment_system", + appName: "一起飞Go Mundo", appVersion: "1.0.0", appVersionCode: "100", appLanguage: getAppLanguage(hostLanguage), @@ -1438,7 +1438,7 @@ const getAppBaseInfo = { hostSDKVersion: SDKVersion, hostTheme: theme, appId: "__UNI__C6C43F9", - appName: "appointment_system", + appName: "一起飞Go Mundo", appVersion: "1.0.0", appVersionCode: "100", appLanguage: getAppLanguage(hostLanguage) @@ -3777,12 +3777,12 @@ function normalizeEmitsOptions(comp, appContext, asMixin = false) { } return normalized; } -function isEmitListener(options2, key) { - if (!options2 || !isOn(key)) { +function isEmitListener(options, key) { + if (!options || !isOn(key)) { return false; } key = key.slice(2).replace(/Once$/, ""); - return hasOwn$2(options2, key[0].toLowerCase() + key.slice(1)) || hasOwn$2(options2, hyphenate(key)) || hasOwn$2(options2, key); + return hasOwn$2(options, key[0].toLowerCase() + key.slice(1)) || hasOwn$2(options, hyphenate(key)) || hasOwn$2(options, key); } let currentRenderingInstance = null; function setCurrentRenderingInstance(instance) { @@ -3833,13 +3833,13 @@ function resolve(registry, name) { return registry && (registry[name] || registry[camelize(name)] || registry[capitalize(camelize(name))]); } const INITIAL_WATCHER_VALUE = {}; -function watch(source, cb, options2) { +function watch(source, cb, options) { if (!isFunction$1(cb)) { warn$1( `\`watch(fn, options?)\` signature has been moved to a separate API. Use \`watchEffect(fn, options?)\` instead. \`watch\` now only supports \`watch(source, cb, options?) signature.` ); } - return doWatch(source, cb, options2); + return doWatch(source, cb, options); } function doWatch(source, cb, { immediate, @@ -4007,7 +4007,7 @@ function doWatch(source, cb, { } return unwatch; } -function instanceWatch(source, value, options2) { +function instanceWatch(source, value, options) { const publicThis = this.proxy; const getter = isString$1(source) ? source.includes(".") ? createPathGetter(publicThis, source) : () => publicThis[source] : source.bind(publicThis, publicThis); let cb; @@ -4015,10 +4015,10 @@ function instanceWatch(source, value, options2) { cb = value; } else { cb = value.handler; - options2 = value; + options = value; } const reset = setCurrentInstance(this); - const res = doWatch(getter, cb.bind(publicThis), options2); + const res = doWatch(getter, cb.bind(publicThis), options); reset(); return res; } @@ -4120,15 +4120,15 @@ function createAppAPI(render, hydrate) { ); } }, - use(plugin2, ...options2) { + use(plugin2, ...options) { if (installedPlugins.has(plugin2)) { warn$1(`Plugin has already been applied to target app.`); } else if (plugin2 && isFunction$1(plugin2.install)) { installedPlugins.add(plugin2); - plugin2.install(app, ...options2); + plugin2.install(app, ...options); } else if (isFunction$1(plugin2)) { installedPlugins.add(plugin2); - plugin2(app, ...options2); + plugin2(app, ...options); } else { warn$1( `A plugin must either be a function or an object with an "install" function.` @@ -4572,12 +4572,12 @@ function createDuplicateChecker() { } let shouldCacheAccess = true; function applyOptions$1(instance) { - const options2 = resolveMergedOptions(instance); + const options = resolveMergedOptions(instance); const publicThis = instance.proxy; const ctx = instance.ctx; shouldCacheAccess = false; - if (options2.beforeCreate) { - callHook$1(options2.beforeCreate, instance, "bc"); + if (options.beforeCreate) { + callHook$1(options.beforeCreate, instance, "bc"); } const { // state @@ -4611,7 +4611,7 @@ function applyOptions$1(instance) { components, directives, filters - } = options2; + } = options; const checkDuplicateProperties = createDuplicateChecker(); { const [propsOptions] = instance.propsOptions; @@ -4766,7 +4766,7 @@ function applyOptions$1(instance) { if (directives) instance.directives = directives; if (instance.ctx.$onApplyOptions) { - instance.ctx.$onApplyOptions(options2, instance, publicThis); + instance.ctx.$onApplyOptions(options, instance, publicThis); } } function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP) { @@ -5016,7 +5016,7 @@ function updateProps(instance, rawProps, rawPrevProps, optimized) { vnode: { patchFlag } } = instance; const rawCurrentProps = toRaw(props2); - const [options2] = instance.propsOptions; + const [options] = instance.propsOptions; let hasAttrsChanged = false; if ( // always force full diff in dev @@ -5032,7 +5032,7 @@ function updateProps(instance, rawProps, rawPrevProps, optimized) { continue; } const value = rawProps[key]; - if (options2) { + if (options) { if (hasOwn$2(attrs, key)) { if (value !== attrs[key]) { attrs[key] = value; @@ -5041,7 +5041,7 @@ function updateProps(instance, rawProps, rawPrevProps, optimized) { } else { const camelizedKey = camelize(key); props2[camelizedKey] = resolvePropValue( - options2, + options, rawCurrentProps, camelizedKey, value, @@ -5067,12 +5067,12 @@ function updateProps(instance, rawProps, rawPrevProps, optimized) { !hasOwn$2(rawProps, key) && // it's possible the original props was passed in as kebab-case // and converted to camelCase (#955) ((kebabKey = hyphenate(key)) === key || !hasOwn$2(rawProps, kebabKey))) { - if (options2) { + if (options) { if (rawPrevProps && // for camelCase (rawPrevProps[key] !== void 0 || // for kebab-case rawPrevProps[kebabKey] !== void 0)) { props2[key] = resolvePropValue( - options2, + options, rawCurrentProps, key, void 0, @@ -5102,7 +5102,7 @@ function updateProps(instance, rawProps, rawPrevProps, optimized) { } } function setFullProps(instance, rawProps, props2, attrs) { - const [options2, needCastKeys] = instance.propsOptions; + const [options, needCastKeys] = instance.propsOptions; let hasAttrsChanged = false; let rawCastValues; if (rawProps) { @@ -5112,7 +5112,7 @@ function setFullProps(instance, rawProps, props2, attrs) { } const value = rawProps[key]; let camelKey; - if (options2 && hasOwn$2(options2, camelKey = camelize(key))) { + if (options && hasOwn$2(options, camelKey = camelize(key))) { if (!needCastKeys || !needCastKeys.includes(camelKey)) { props2[camelKey] = value; } else { @@ -5132,7 +5132,7 @@ function setFullProps(instance, rawProps, props2, attrs) { for (let i = 0; i < needCastKeys.length; i++) { const key = needCastKeys[i]; props2[key] = resolvePropValue( - options2, + options, rawCurrentProps, key, castValues[key], @@ -5143,8 +5143,8 @@ function setFullProps(instance, rawProps, props2, attrs) { } return hasAttrsChanged; } -function resolvePropValue(options2, props2, key, value, instance, isAbsent) { - const opt = options2[key]; +function resolvePropValue(options, props2, key, value, instance, isAbsent) { + const opt = options[key]; if (opt != null) { const hasDefault = hasOwn$2(opt, "default"); if (hasDefault && value === void 0) { @@ -5291,9 +5291,9 @@ function getTypeIndex(type, expectedTypes) { } function validateProps(rawProps, props2, instance) { const resolvedValues = toRaw(props2); - const options2 = instance.propsOptions[0]; - for (const key in options2) { - let opt = options2[key]; + const options = instance.propsOptions[0]; + for (const key in options) { + let opt = options[key]; if (opt == null) continue; validateProp( @@ -6045,13 +6045,13 @@ function initAppConfig(appConfig) { return nextTick(this.$, fn); }; } -function onApplyOptions(options2, instance, publicThis) { +function onApplyOptions(options, instance, publicThis) { instance.appContext.config.globalProperties.$applyOptions( - options2, + options, instance, publicThis ); - const computedOptions = options2.computed; + const computedOptions = options.computed; if (computedOptions) { const keys = Object.keys(computedOptions); if (keys.length) { @@ -6172,17 +6172,17 @@ function warnRef(ref2) { warn$3("Invalid template ref type:", ref2, `(${typeof ref2})`); } const queuePostRenderEffect = queuePostFlushCb; -function mountComponent(initialVNode, options2) { - const instance = initialVNode.component = createComponentInstance(initialVNode, options2.parentComponent, null); +function mountComponent(initialVNode, options) { + const instance = initialVNode.component = createComponentInstance(initialVNode, options.parentComponent, null); { instance.ctx.$onApplyOptions = onApplyOptions; instance.ctx.$children = []; } - if (options2.mpType === "app") { + if (options.mpType === "app") { instance.render = NOOP; } - if (options2.onBeforeSetup) { - options2.onBeforeSetup(instance, options2); + if (options.onBeforeSetup) { + options.onBeforeSetup(instance, options); } { pushWarningContext(initialVNode); @@ -6196,8 +6196,8 @@ function mountComponent(initialVNode, options2) { endMeasure(instance, `init`); } { - if (options2.parentComponent && instance.proxy) { - options2.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy); + if (options.parentComponent && instance.proxy) { + options.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy); } } setupRenderEffect(instance); @@ -6456,8 +6456,8 @@ function createVueApp(rootComponent, rootProps = null) { initialVNode.shapeFlag = 6; return initialVNode; }; - const createComponent2 = function createComponent22(initialVNode, options2) { - return mountComponent(createVNode2(initialVNode), options2); + const createComponent2 = function createComponent22(initialVNode, options) { + return mountComponent(createVNode2(initialVNode), options); }; const destroyComponent = function destroyComponent2(component) { return component && unmountComponent(component.$); @@ -6496,14 +6496,14 @@ function injectLifecycleHook(name, hook, publicThis, instance) { injectHook(name, hook.bind(publicThis), instance); } } -function initHooks$1(options2, instance, publicThis) { - const mpType = options2.mpType || publicThis.$mpType; +function initHooks$1(options, instance, publicThis) { + const mpType = options.mpType || publicThis.$mpType; if (!mpType || mpType === "component") { return; } - Object.keys(options2).forEach((name) => { - if (isUniLifecycleHook(name, options2[name], false)) { - const hooks = options2[name]; + Object.keys(options).forEach((name) => { + if (isUniLifecycleHook(name, options[name], false)) { + const hooks = options[name]; if (isArray$2(hooks)) { hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance)); } else { @@ -6512,8 +6512,8 @@ function initHooks$1(options2, instance, publicThis) { } }); } -function applyOptions$2(options2, instance, publicThis) { - initHooks$1(options2, instance, publicThis); +function applyOptions$2(options, instance, publicThis) { + initHooks$1(options, instance, publicThis); } function set(target, key, val) { return target[key] = val; @@ -6880,19 +6880,19 @@ function createEmitFn(oldEmit, ctx) { return oldEmit.apply(this, [event, ...args]); }; } -function initBaseInstance(instance, options2) { +function initBaseInstance(instance, options) { const ctx = instance.ctx; - ctx.mpType = options2.mpType; - ctx.$mpType = options2.mpType; + ctx.mpType = options.mpType; + ctx.$mpType = options.mpType; ctx.$mpPlatform = "mp-weixin"; - ctx.$scope = options2.mpInstance; + ctx.$scope = options.mpInstance; ctx.$mp = {}; { ctx._self = {}; } instance.slots = {}; - if (isArray$2(options2.slots) && options2.slots.length) { - options2.slots.forEach((name) => { + if (isArray$2(options.slots) && options.slots.length) { + options.slots.forEach((name) => { instance.slots[name] = true; }); if (instance.slots[SLOT_DEFAULT_NAME]) { @@ -6901,15 +6901,15 @@ function initBaseInstance(instance, options2) { } ctx.getOpenerEventChannel = function() { { - return options2.mpInstance.getOpenerEventChannel(); + return options.mpInstance.getOpenerEventChannel(); } }; ctx.$hasHook = hasHook; ctx.$callHook = callHook; instance.emit = createEmitFn(instance.emit, ctx); } -function initComponentInstance(instance, options2) { - initBaseInstance(instance, options2); +function initComponentInstance(instance, options) { + initBaseInstance(instance, options); const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function(...args) { @@ -7038,7 +7038,7 @@ function parseApp(instance, parseAppOptions) { globalData: instance.$options && instance.$options.globalData || {}, $vm: instance, // mp-alipay 组件 data 初始化比 onLaunch 早,提前挂载 - onLaunch(options2) { + onLaunch(options) { this.$vm = instance; const ctx = internalInstance.ctx; if (this.$vm && ctx.$scope) { @@ -7050,7 +7050,7 @@ function parseApp(instance, parseAppOptions) { slots: [] }); ctx.globalData = this.globalData; - instance.$callHook(ON_LAUNCH, options2); + instance.$callHook(ON_LAUNCH, options); } }; const { onError } = internalInstance; @@ -7233,7 +7233,7 @@ const builtInProps = [ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots "uS" ]; -function initDefaultProps(options2, isBehavior = false) { +function initDefaultProps(options, isBehavior = false) { const properties = {}; if (!isBehavior) { builtInProps.forEach((name) => { @@ -7256,15 +7256,15 @@ function initDefaultProps(options2, isBehavior = false) { } }; } - if (options2.behaviors) { - if (options2.behaviors.includes("__GLOBAL__://form-field")) { - if (!options2.properties || !options2.properties.name) { + if (options.behaviors) { + if (options.behaviors.includes("__GLOBAL__://form-field")) { + if (!options.properties || !options.properties.name) { properties.name = { type: null, value: "" }; } - if (!options2.properties || !options2.properties.value) { + if (!options.properties || !options.properties.value) { properties.value = { type: null, value: "" @@ -7274,10 +7274,10 @@ function initDefaultProps(options2, isBehavior = false) { } return properties; } -function initVirtualHostProps(options2) { +function initVirtualHostProps(options) { const properties = {}; { - if (options2 && options2.virtualHost) { + if (options && options.virtualHost) { properties.virtualHostStyle = { type: null, value: "" @@ -7454,7 +7454,7 @@ function applyOptions(componentOptions, vueOptions) { } function parseComponent(vueOptions, { parse: parse2, mocks: mocks2, isPage: isPage2, initRelation: initRelation2, handleLink: handleLink2, initLifetimes: initLifetimes2 }) { vueOptions = vueOptions.default || vueOptions; - const options2 = { + const options = { multipleSlots: true, // styleIsolation: 'apply-shared', addGlobalClass: true, @@ -7463,15 +7463,15 @@ function parseComponent(vueOptions, { parse: parse2, mocks: mocks2, isPage: isPa if (isArray$2(vueOptions.mixins)) { vueOptions.mixins.forEach((item) => { if (isObject$3(item.options)) { - extend(options2, item.options); + extend(options, item.options); } }); } if (vueOptions.options) { - extend(options2, vueOptions.options); + extend(options, vueOptions.options); } const mpComponentOptions = { - options: options2, + options, lifetimes: initLifetimes2({ mocks: mocks2, isPage: isPage2, initRelation: initRelation2, vueOptions }), pageLifetimes: { show() { @@ -7513,11 +7513,11 @@ let $destroyComponentFn; function getAppVm() { return getApp().$vm; } -function $createComponent(initialVNode, options2) { +function $createComponent(initialVNode, options) { if (!$createComponentFn) { $createComponentFn = getAppVm().$createComponent; } - const proxy = $createComponentFn(initialVNode, options2); + const proxy = $createComponentFn(initialVNode, options); return getExposeProxy(proxy.$) || proxy; } function $destroyComponent(instance) { @@ -7576,31 +7576,31 @@ function initTriggerEvent(mpInstance) { mpInstance._triggerEvent = newTriggerEvent; } } -function initMiniProgramHook(name, options2, isComponent) { - const oldHook = options2[name]; +function initMiniProgramHook(name, options, isComponent) { + const oldHook = options[name]; if (!oldHook) { - options2[name] = function() { + options[name] = function() { initTriggerEvent(this); }; } else { - options2[name] = function(...args) { + options[name] = function(...args) { initTriggerEvent(this); return oldHook.apply(this, args); }; } } -Page = function(options2) { - initMiniProgramHook(ON_LOAD, options2); - return MPPage(options2); +Page = function(options) { + initMiniProgramHook(ON_LOAD, options); + return MPPage(options); }; -Component = function(options2) { - initMiniProgramHook("created", options2); - const isVueComponent = options2.properties && options2.properties.uP; +Component = function(options) { + initMiniProgramHook("created", options); + const isVueComponent = options.properties && options.properties.uP; if (!isVueComponent) { - initProps(options2); - initPropsObserver(options2); + initProps(options); + initPropsObserver(options); } - return MPComponent(options2); + return MPComponent(options); }; function initLifetimes({ mocks: mocks2, isPage: isPage2, initRelation: initRelation2, vueOptions }) { return { @@ -7623,10 +7623,10 @@ function initLifetimes({ mocks: mocks2, isPage: isPage2, initRelation: initRelat slots: properties.uS || {}, // vueSlots parentComponent: relationOptions.parent && relationOptions.parent.$, - onBeforeSetup(instance, options2) { + onBeforeSetup(instance, options) { initRefs(instance, mpInstance); initMocks(instance, mpInstance, mocks2); - initComponentInstance(instance, options2); + initComponentInstance(instance, options); } }); if (!isMiniProgramPage) { @@ -7688,8 +7688,8 @@ const createSubpackageApp = initCreateSubpackageApp(); wx.createPluginApp = global.createPluginApp = createPluginApp; wx.createSubpackageApp = global.createSubpackageApp = createSubpackageApp; } -const defineMixin$1 = (options2) => { - return options2; +const defineMixin$1 = (options) => { + return options; }; function email(value) { return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(value); @@ -8613,14 +8613,14 @@ class Router { return url2 += query; } // 对外的方法名称 - async route(options2 = {}, params2 = {}) { + async route(options = {}, params2 = {}) { let mergeConfig2 = {}; - if (typeof options2 === "string") { - mergeConfig2.url = this.mixinParam(options2, params2); + if (typeof options === "string") { + mergeConfig2.url = this.mixinParam(options, params2); mergeConfig2.type = "navigateTo"; } else { - mergeConfig2 = deepMerge$1(this.config, options2); - mergeConfig2.url = this.mixinParam(options2.url, options2.params); + mergeConfig2 = deepMerge$1(this.config, options); + mergeConfig2.url = this.mixinParam(options.url, options.params); } if (mergeConfig2.url === page()) return; @@ -9554,67 +9554,67 @@ class Request { request(config2 = {}) { return this.middleware(config2); } - get(url2, options2 = {}) { + get(url2, options = {}) { return this.middleware({ url: url2, method: "GET", - ...options2 + ...options }); } - post(url2, data, options2 = {}) { + post(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "POST", - ...options2 + ...options }); } - put(url2, data, options2 = {}) { + put(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "PUT", - ...options2 + ...options }); } - delete(url2, data, options2 = {}) { + delete(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "DELETE", - ...options2 + ...options }); } - connect(url2, data, options2 = {}) { + connect(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "CONNECT", - ...options2 + ...options }); } - head(url2, data, options2 = {}) { + head(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "HEAD", - ...options2 + ...options }); } - options(url2, data, options2 = {}) { + options(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "OPTIONS", - ...options2 + ...options }); } - trace(url2, data, options2 = {}) { + trace(url2, data, options = {}) { return this.middleware({ url: url2, data, method: "TRACE", - ...options2 + ...options }); } upload(url2, config2 = {}) { @@ -12780,9 +12780,9 @@ function pluralDefault(choice, choicesLength) { } return choice ? Math.min(choice, 2) : 0; } -function getPluralIndex(options2) { - const index2 = isNumber(options2.pluralIndex) ? options2.pluralIndex : -1; - return options2.named && (isNumber(options2.named.count) || isNumber(options2.named.n)) ? isNumber(options2.named.count) ? options2.named.count : isNumber(options2.named.n) ? options2.named.n : index2 : index2; +function getPluralIndex(options) { + const index2 = isNumber(options.pluralIndex) ? options.pluralIndex : -1; + return options.named && (isNumber(options.named.count) || isNumber(options.named.n)) ? isNumber(options.named.count) ? options.named.count : isNumber(options.named.n) ? options.named.n : index2 : index2; } function normalizeNamed(pluralIndex, props2) { if (!props2.count) { @@ -12792,25 +12792,25 @@ function normalizeNamed(pluralIndex, props2) { props2.n = pluralIndex; } } -function createMessageContext(options2 = {}) { - const locale = options2.locale; - const pluralIndex = getPluralIndex(options2); - const pluralRule = isObject$1(options2.pluralRules) && isString(locale) && isFunction(options2.pluralRules[locale]) ? options2.pluralRules[locale] : pluralDefault; - const orgPluralRule = isObject$1(options2.pluralRules) && isString(locale) && isFunction(options2.pluralRules[locale]) ? pluralDefault : void 0; +function createMessageContext(options = {}) { + const locale = options.locale; + const pluralIndex = getPluralIndex(options); + const pluralRule = isObject$1(options.pluralRules) && isString(locale) && isFunction(options.pluralRules[locale]) ? options.pluralRules[locale] : pluralDefault; + const orgPluralRule = isObject$1(options.pluralRules) && isString(locale) && isFunction(options.pluralRules[locale]) ? pluralDefault : void 0; const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)]; - const _list = options2.list || []; + const _list = options.list || []; const list = (index2) => _list[index2]; - const _named = options2.named || {}; - isNumber(options2.pluralIndex) && normalizeNamed(pluralIndex, _named); + const _named = options.named || {}; + isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named); const named = (key) => _named[key]; function message(key) { - const msg = isFunction(options2.messages) ? options2.messages(key) : isObject$1(options2.messages) ? options2.messages[key] : false; - return !msg ? options2.parent ? options2.parent.message(key) : DEFAULT_MESSAGE : msg; + const msg = isFunction(options.messages) ? options.messages(key) : isObject$1(options.messages) ? options.messages[key] : false; + return !msg ? options.parent ? options.parent.message(key) : DEFAULT_MESSAGE : msg; } - const _modifier = (name) => options2.modifiers ? options2.modifiers[name] : DEFAULT_MODIFIER; - const normalize = isPlainObject(options2.processor) && isFunction(options2.processor.normalize) ? options2.processor.normalize : DEFAULT_NORMALIZE; - const interpolate = isPlainObject(options2.processor) && isFunction(options2.processor.interpolate) ? options2.processor.interpolate : DEFAULT_INTERPOLATE; - const type = isPlainObject(options2.processor) && isString(options2.processor.type) ? options2.processor.type : DEFAULT_MESSAGE_DATA_TYPE; + const _modifier = (name) => options.modifiers ? options.modifiers[name] : DEFAULT_MODIFIER; + const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize) ? options.processor.normalize : DEFAULT_NORMALIZE; + const interpolate = isPlainObject(options.processor) && isFunction(options.processor.interpolate) ? options.processor.interpolate : DEFAULT_INTERPOLATE; + const type = isPlainObject(options.processor) && isString(options.processor.type) ? options.processor.type : DEFAULT_MESSAGE_DATA_TYPE; const ctx = { [ "list" @@ -12915,8 +12915,8 @@ const errorMessages$2 = { /* UNEXPECTED_LEXICAL_ANALYSIS */ ]: `Unexpected lexical analysis in token: '{0}'` }; -function createCompileError(code2, loc, options2 = {}) { - const { domain, messages, args } = options2; +function createCompileError(code2, loc, options = {}) { + const { domain, messages, args } = options; const msg = format((messages || errorMessages$2)[code2] || "", ...args || []); const error2 = new SyntaxError(String(msg)); error2.code = code2; @@ -13003,27 +13003,27 @@ const setAdditionalMeta = (meta) => { }; const getAdditionalMeta = () => _additionalMeta; let _cid = 0; -function createCoreContext(options2 = {}) { - const version2 = isString(options2.version) ? options2.version : VERSION$1; - const locale = isString(options2.locale) ? options2.locale : "en-US"; - const fallbackLocale = isArray(options2.fallbackLocale) || isPlainObject(options2.fallbackLocale) || isString(options2.fallbackLocale) || options2.fallbackLocale === false ? options2.fallbackLocale : locale; - const messages = isPlainObject(options2.messages) ? options2.messages : { [locale]: {} }; - const datetimeFormats = isPlainObject(options2.datetimeFormats) ? options2.datetimeFormats : { [locale]: {} }; - const numberFormats = isPlainObject(options2.numberFormats) ? options2.numberFormats : { [locale]: {} }; - const modifiers = assign({}, options2.modifiers || {}, getDefaultLinkedModifiers()); - const pluralRules = options2.pluralRules || {}; - const missing = isFunction(options2.missing) ? options2.missing : null; - const missingWarn = isBoolean(options2.missingWarn) || isRegExp(options2.missingWarn) ? options2.missingWarn : true; - const fallbackWarn = isBoolean(options2.fallbackWarn) || isRegExp(options2.fallbackWarn) ? options2.fallbackWarn : true; - const fallbackFormat = !!options2.fallbackFormat; - const unresolving = !!options2.unresolving; - const postTranslation = isFunction(options2.postTranslation) ? options2.postTranslation : null; - const processor = isPlainObject(options2.processor) ? options2.processor : null; - const warnHtmlMessage = isBoolean(options2.warnHtmlMessage) ? options2.warnHtmlMessage : true; - const escapeParameter = !!options2.escapeParameter; - const messageCompiler = isFunction(options2.messageCompiler) ? options2.messageCompiler : _compiler; - const onWarn = isFunction(options2.onWarn) ? options2.onWarn : warn; - const internalOptions = options2; +function createCoreContext(options = {}) { + const version2 = isString(options.version) ? options.version : VERSION$1; + const locale = isString(options.locale) ? options.locale : "en-US"; + const fallbackLocale = isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || isString(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : locale; + const messages = isPlainObject(options.messages) ? options.messages : { [locale]: {} }; + const datetimeFormats = isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [locale]: {} }; + const numberFormats = isPlainObject(options.numberFormats) ? options.numberFormats : { [locale]: {} }; + const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers()); + const pluralRules = options.pluralRules || {}; + const missing = isFunction(options.missing) ? options.missing : null; + const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true; + const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true; + const fallbackFormat = !!options.fallbackFormat; + const unresolving = !!options.unresolving; + const postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null; + const processor = isPlainObject(options.processor) ? options.processor : null; + const warnHtmlMessage = isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true; + const escapeParameter = !!options.escapeParameter; + const messageCompiler = isFunction(options.messageCompiler) ? options.messageCompiler : _compiler; + const onWarn = isFunction(options.onWarn) ? options.onWarn : warn; + const internalOptions = options; const __datetimeFormatters = isObject$1(internalOptions.__datetimeFormatters) ? internalOptions.__datetimeFormatters : /* @__PURE__ */ new Map(); const __numberFormatters = isObject$1(internalOptions.__numberFormatters) ? internalOptions.__numberFormatters : /* @__PURE__ */ new Map(); const __meta = isObject$1(internalOptions.__meta) ? internalOptions.__meta : {}; @@ -13172,15 +13172,15 @@ const NOOP_MESSAGE_FUNCTION = () => ""; const isMessageFunction = (val) => isFunction(val); function translate(context, ...args) { const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context; - const [key, options2] = parseTranslateArgs(...args); - const missingWarn = isBoolean(options2.missingWarn) ? options2.missingWarn : context.missingWarn; - const fallbackWarn = isBoolean(options2.fallbackWarn) ? options2.fallbackWarn : context.fallbackWarn; - const escapeParameter = isBoolean(options2.escapeParameter) ? options2.escapeParameter : context.escapeParameter; - const resolvedMessage = !!options2.resolvedMessage; - const defaultMsgOrKey = isString(options2.default) || isBoolean(options2.default) ? !isBoolean(options2.default) ? options2.default : key : fallbackFormat ? key : ""; + const [key, options] = parseTranslateArgs(...args); + const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn; + const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn; + const escapeParameter = isBoolean(options.escapeParameter) ? options.escapeParameter : context.escapeParameter; + const resolvedMessage = !!options.resolvedMessage; + const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) ? !isBoolean(options.default) ? options.default : key : fallbackFormat ? key : ""; const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== ""; - const locale = isString(options2.locale) ? options2.locale : context.locale; - escapeParameter && escapeParams(options2); + const locale = isString(options.locale) ? options.locale : context.locale; + escapeParameter && escapeParams(options); let [format2, targetLocale, message] = !resolvedMessage ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) : [ key, locale, @@ -13208,7 +13208,7 @@ function translate(context, ...args) { if (occurred) { return format2; } - const ctxOptions = getMessageContextOptions(context, targetLocale, message, options2); + const ctxOptions = getMessageContextOptions(context, targetLocale, message, options); const msgContext = createMessageContext(ctxOptions); const messaged = evaluateMessage(context, msg, msgContext); const ret = postTranslation ? postTranslation(messaged) : messaged; @@ -13225,13 +13225,13 @@ function translate(context, ...args) { } return ret; } -function escapeParams(options2) { - if (isArray(options2.list)) { - options2.list = options2.list.map((item) => isString(item) ? escapeHtml(item) : item); - } else if (isObject$1(options2.named)) { - Object.keys(options2.named).forEach((key) => { - if (isString(options2.named[key])) { - options2.named[key] = escapeHtml(options2.named[key]); +function escapeParams(options) { + if (isArray(options.list)) { + options.list = options.list.map((item) => isString(item) ? escapeHtml(item) : item); + } else if (isObject$1(options.named)) { + Object.keys(options.named).forEach((key) => { + if (isString(options.named[key])) { + options.named[key] = escapeHtml(options.named[key]); } }); } @@ -13375,7 +13375,7 @@ function evaluateMessage(context, msg, msgCtx) { } function parseTranslateArgs(...args) { const [arg1, arg2, arg3] = args; - const options2 = {}; + const options = {}; if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) { throw createCoreError( 14 @@ -13384,22 +13384,22 @@ function parseTranslateArgs(...args) { } const key = isNumber(arg1) ? String(arg1) : isMessageFunction(arg1) ? arg1 : arg1; if (isNumber(arg2)) { - options2.plural = arg2; + options.plural = arg2; } else if (isString(arg2)) { - options2.default = arg2; + options.default = arg2; } else if (isPlainObject(arg2) && !isEmptyObject(arg2)) { - options2.named = arg2; + options.named = arg2; } else if (isArray(arg2)) { - options2.list = arg2; + options.list = arg2; } if (isNumber(arg3)) { - options2.plural = arg3; + options.plural = arg3; } else if (isString(arg3)) { - options2.default = arg3; + options.default = arg3; } else if (isPlainObject(arg3)) { - assign(options2, arg3); + assign(options, arg3); } - return [key, options2]; + return [key, options]; } function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) { return { @@ -13426,7 +13426,7 @@ ${codeFrame}` : message); onCacheKey: (source2) => generateFormatCacheKey(locale, key, source2) }; } -function getMessageContextOptions(context, locale, message, options2) { +function getMessageContextOptions(context, locale, message, options) { const { modifiers, pluralRules } = context; const resolveMessage = (key) => { const val = resolveValue(message, key); @@ -13452,14 +13452,14 @@ function getMessageContextOptions(context, locale, message, options2) { if (context.processor) { ctxOptions.processor = context.processor; } - if (options2.list) { - ctxOptions.list = options2.list; + if (options.list) { + ctxOptions.list = options.list; } - if (options2.named) { - ctxOptions.named = options2.named; + if (options.named) { + ctxOptions.named = options.named; } - if (isNumber(options2.plural)) { - ctxOptions.pluralIndex = options2.plural; + if (isNumber(options.plural)) { + ctxOptions.pluralIndex = options.plural; } return ctxOptions; } @@ -13478,11 +13478,11 @@ function datetime(context, ...args) { )); return MISSING_RESOLVE_VALUE; } - const [key, value, options2, overrides] = parseDateTimeArgs(...args); - const missingWarn = isBoolean(options2.missingWarn) ? options2.missingWarn : context.missingWarn; - const fallbackWarn = isBoolean(options2.fallbackWarn) ? options2.fallbackWarn : context.fallbackWarn; - const part = !!options2.part; - const locale = isString(options2.locale) ? options2.locale : context.locale; + const [key, value, options, overrides] = parseDateTimeArgs(...args); + const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn; + const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn; + const part = !!options.part; + const locale = isString(options.locale) ? options.locale : context.locale; const locales = getLocaleChain(context, fallbackLocale, locale); if (!isString(key) || key === "") { return new Intl.DateTimeFormat(locale).format(value); @@ -13536,7 +13536,7 @@ function datetime(context, ...args) { } function parseDateTimeArgs(...args) { const [arg1, arg2, arg3, arg4] = args; - let options2 = {}; + let options = {}; let overrides = {}; let value; if (isString(arg1)) { @@ -13572,19 +13572,19 @@ function parseDateTimeArgs(...args) { ); } if (isString(arg2)) { - options2.key = arg2; + options.key = arg2; } else if (isPlainObject(arg2)) { - options2 = arg2; + options = arg2; } if (isString(arg3)) { - options2.locale = arg3; + options.locale = arg3; } else if (isPlainObject(arg3)) { overrides = arg3; } if (isPlainObject(arg4)) { overrides = arg4; } - return [options2.key || "", value, options2, overrides]; + return [options.key || "", value, options, overrides]; } function clearDateTimeFormat(ctx, locale, format2) { const context = ctx; @@ -13606,11 +13606,11 @@ function number(context, ...args) { )); return MISSING_RESOLVE_VALUE; } - const [key, value, options2, overrides] = parseNumberArgs(...args); - const missingWarn = isBoolean(options2.missingWarn) ? options2.missingWarn : context.missingWarn; - const fallbackWarn = isBoolean(options2.fallbackWarn) ? options2.fallbackWarn : context.fallbackWarn; - const part = !!options2.part; - const locale = isString(options2.locale) ? options2.locale : context.locale; + const [key, value, options, overrides] = parseNumberArgs(...args); + const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn; + const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn; + const part = !!options.part; + const locale = isString(options.locale) ? options.locale : context.locale; const locales = getLocaleChain(context, fallbackLocale, locale); if (!isString(key) || key === "") { return new Intl.NumberFormat(locale).format(value); @@ -13664,7 +13664,7 @@ function number(context, ...args) { } function parseNumberArgs(...args) { const [arg1, arg2, arg3, arg4] = args; - let options2 = {}; + let options = {}; let overrides = {}; if (!isNumber(arg1)) { throw createCoreError( @@ -13674,19 +13674,19 @@ function parseNumberArgs(...args) { } const value = arg1; if (isString(arg2)) { - options2.key = arg2; + options.key = arg2; } else if (isPlainObject(arg2)) { - options2 = arg2; + options = arg2; } if (isString(arg3)) { - options2.locale = arg3; + options.locale = arg3; } else if (isPlainObject(arg3)) { overrides = arg3; } if (isPlainObject(arg4)) { overrides = arg4; } - return [options2.key || "", value, options2, overrides]; + return [options.key || "", value, options, overrides]; } function clearNumberFormat(ctx, locale, format2) { const context = ctx; @@ -13833,8 +13833,8 @@ function defineCoreMissingHandler(missing) { return missing(locale, key, getCurrentInstance() || void 0, type); }; } -function getLocaleMessages(locale, options2) { - const { messages, __i18n } = options2; +function getLocaleMessages(locale, options) { + const { messages, __i18n } = options; const ret = isPlainObject(messages) ? messages : isArray(__i18n) ? {} : { [locale]: {} }; if (isArray(__i18n)) { __i18n.forEach(({ locale: locale2, resource }) => { @@ -13846,7 +13846,7 @@ function getLocaleMessages(locale, options2) { } }); } - if (options2.flatJson) { + if (options.flatJson) { for (const key in ret) { if (hasOwn$1(ret, key)) { handleFlatJson(ret[key]); @@ -13877,32 +13877,32 @@ const getMetaInfo = () => { const instance = getCurrentInstance(); return instance && instance.type[DEVTOOLS_META] ? { [DEVTOOLS_META]: instance.type[DEVTOOLS_META] } : null; }; -function createComposer(options2 = {}) { - const { __root } = options2; +function createComposer(options = {}) { + const { __root } = options; const _isGlobal = __root === void 0; - let _inheritLocale = isBoolean(options2.inheritLocale) ? options2.inheritLocale : true; + let _inheritLocale = isBoolean(options.inheritLocale) ? options.inheritLocale : true; const _locale = ref( // prettier-ignore - __root && _inheritLocale ? __root.locale.value : isString(options2.locale) ? options2.locale : "en-US" + __root && _inheritLocale ? __root.locale.value : isString(options.locale) ? options.locale : "en-US" ); const _fallbackLocale = ref( // prettier-ignore - __root && _inheritLocale ? __root.fallbackLocale.value : isString(options2.fallbackLocale) || isArray(options2.fallbackLocale) || isPlainObject(options2.fallbackLocale) || options2.fallbackLocale === false ? options2.fallbackLocale : _locale.value + __root && _inheritLocale ? __root.fallbackLocale.value : isString(options.fallbackLocale) || isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale.value ); - const _messages = ref(getLocaleMessages(_locale.value, options2)); - const _datetimeFormats = ref(isPlainObject(options2.datetimeFormats) ? options2.datetimeFormats : { [_locale.value]: {} }); - const _numberFormats = ref(isPlainObject(options2.numberFormats) ? options2.numberFormats : { [_locale.value]: {} }); - let _missingWarn = __root ? __root.missingWarn : isBoolean(options2.missingWarn) || isRegExp(options2.missingWarn) ? options2.missingWarn : true; - let _fallbackWarn = __root ? __root.fallbackWarn : isBoolean(options2.fallbackWarn) || isRegExp(options2.fallbackWarn) ? options2.fallbackWarn : true; - let _fallbackRoot = __root ? __root.fallbackRoot : isBoolean(options2.fallbackRoot) ? options2.fallbackRoot : true; - let _fallbackFormat = !!options2.fallbackFormat; - let _missing = isFunction(options2.missing) ? options2.missing : null; - let _runtimeMissing = isFunction(options2.missing) ? defineCoreMissingHandler(options2.missing) : null; - let _postTranslation = isFunction(options2.postTranslation) ? options2.postTranslation : null; - let _warnHtmlMessage = isBoolean(options2.warnHtmlMessage) ? options2.warnHtmlMessage : true; - let _escapeParameter = !!options2.escapeParameter; - const _modifiers = __root ? __root.modifiers : isPlainObject(options2.modifiers) ? options2.modifiers : {}; - let _pluralRules = options2.pluralRules || __root && __root.pluralRules; + const _messages = ref(getLocaleMessages(_locale.value, options)); + const _datetimeFormats = ref(isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [_locale.value]: {} }); + const _numberFormats = ref(isPlainObject(options.numberFormats) ? options.numberFormats : { [_locale.value]: {} }); + let _missingWarn = __root ? __root.missingWarn : isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true; + let _fallbackWarn = __root ? __root.fallbackWarn : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true; + let _fallbackRoot = __root ? __root.fallbackRoot : isBoolean(options.fallbackRoot) ? options.fallbackRoot : true; + let _fallbackFormat = !!options.fallbackFormat; + let _missing = isFunction(options.missing) ? options.missing : null; + let _runtimeMissing = isFunction(options.missing) ? defineCoreMissingHandler(options.missing) : null; + let _postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null; + let _warnHtmlMessage = isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true; + let _escapeParameter = !!options.escapeParameter; + const _modifiers = __root ? __root.modifiers : isPlainObject(options.modifiers) ? options.modifiers : {}; + let _pluralRules = options.pluralRules || __root && __root.pluralRules; let _context; function getCoreContext() { return createCoreContext({ @@ -14270,7 +14270,7 @@ function createComposer(options2 = {}) { [NumberPartsSymbol]: numberParts, [DatetimePartsSymbol]: datetimeParts, [SetPluralRulesSymbol]: setPluralRules, - [InejctWithOption]: options2.__injectWithOption + [InejctWithOption]: options.__injectWithOption // eslint-disable-line @typescript-eslint/no-explicit-any }; { @@ -14283,35 +14283,35 @@ function createComposer(options2 = {}) { } return composer; } -function convertComposerOptions(options2) { - const locale = isString(options2.locale) ? options2.locale : "en-US"; - const fallbackLocale = isString(options2.fallbackLocale) || isArray(options2.fallbackLocale) || isPlainObject(options2.fallbackLocale) || options2.fallbackLocale === false ? options2.fallbackLocale : locale; - const missing = isFunction(options2.missing) ? options2.missing : void 0; - const missingWarn = isBoolean(options2.silentTranslationWarn) || isRegExp(options2.silentTranslationWarn) ? !options2.silentTranslationWarn : true; - const fallbackWarn = isBoolean(options2.silentFallbackWarn) || isRegExp(options2.silentFallbackWarn) ? !options2.silentFallbackWarn : true; - const fallbackRoot = isBoolean(options2.fallbackRoot) ? options2.fallbackRoot : true; - const fallbackFormat = !!options2.formatFallbackMessages; - const modifiers = isPlainObject(options2.modifiers) ? options2.modifiers : {}; - const pluralizationRules = options2.pluralizationRules; - const postTranslation = isFunction(options2.postTranslation) ? options2.postTranslation : void 0; - const warnHtmlMessage = isString(options2.warnHtmlInMessage) ? options2.warnHtmlInMessage !== "off" : true; - const escapeParameter = !!options2.escapeParameterHtml; - const inheritLocale = isBoolean(options2.sync) ? options2.sync : true; - if (options2.formatter) { +function convertComposerOptions(options) { + const locale = isString(options.locale) ? options.locale : "en-US"; + const fallbackLocale = isString(options.fallbackLocale) || isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : locale; + const missing = isFunction(options.missing) ? options.missing : void 0; + const missingWarn = isBoolean(options.silentTranslationWarn) || isRegExp(options.silentTranslationWarn) ? !options.silentTranslationWarn : true; + const fallbackWarn = isBoolean(options.silentFallbackWarn) || isRegExp(options.silentFallbackWarn) ? !options.silentFallbackWarn : true; + const fallbackRoot = isBoolean(options.fallbackRoot) ? options.fallbackRoot : true; + const fallbackFormat = !!options.formatFallbackMessages; + const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {}; + const pluralizationRules = options.pluralizationRules; + const postTranslation = isFunction(options.postTranslation) ? options.postTranslation : void 0; + const warnHtmlMessage = isString(options.warnHtmlInMessage) ? options.warnHtmlInMessage !== "off" : true; + const escapeParameter = !!options.escapeParameterHtml; + const inheritLocale = isBoolean(options.sync) ? options.sync : true; + if (options.formatter) { warn(getWarnMessage( 8 /* NOT_SUPPORTED_FORMATTER */ )); } - if (options2.preserveDirectiveContent) { + if (options.preserveDirectiveContent) { warn(getWarnMessage( 9 /* NOT_SUPPORTED_PRESERVE_DIRECTIVE */ )); } - let messages = options2.messages; - if (isPlainObject(options2.sharedMessages)) { - const sharedMessages = options2.sharedMessages; + let messages = options.messages; + if (isPlainObject(options.sharedMessages)) { + const sharedMessages = options.sharedMessages; const locales = Object.keys(sharedMessages); messages = locales.reduce((messages2, locale2) => { const message = messages2[locale2] || (messages2[locale2] = {}); @@ -14319,10 +14319,10 @@ function convertComposerOptions(options2) { return messages2; }, messages || {}); } - const { __i18n, __root, __injectWithOption } = options2; - const datetimeFormats = options2.datetimeFormats; - const numberFormats = options2.numberFormats; - const flatJson = options2.flatJson; + const { __i18n, __root, __injectWithOption } = options; + const datetimeFormats = options.datetimeFormats; + const numberFormats = options.numberFormats; + const flatJson = options.flatJson; return { locale, fallbackLocale, @@ -14346,8 +14346,8 @@ function convertComposerOptions(options2) { __injectWithOption }; } -function createVueI18n(options2 = {}) { - const composer = createComposer(convertComposerOptions(options2)); +function createVueI18n(options = {}) { + const composer = createComposer(convertComposerOptions(options)); const vueI18n = { // id id: composer.id, @@ -14482,7 +14482,7 @@ function createVueI18n(options2 = {}) { // t t(...args) { const [arg1, arg2, arg3] = args; - const options3 = {}; + const options2 = {}; let list = null; let named = null; if (!isString(arg1)) { @@ -14493,7 +14493,7 @@ function createVueI18n(options2 = {}) { } const key = arg1; if (isString(arg2)) { - options3.locale = arg2; + options2.locale = arg2; } else if (isArray(arg2)) { list = arg2; } else if (isPlainObject(arg2)) { @@ -14504,7 +14504,7 @@ function createVueI18n(options2 = {}) { } else if (isPlainObject(arg3)) { named = arg3; } - return composer.t(key, list || named || {}, options3); + return composer.t(key, list || named || {}, options2); }, rt(...args) { return composer.rt(...args); @@ -14512,7 +14512,7 @@ function createVueI18n(options2 = {}) { // tc tc(...args) { const [arg1, arg2, arg3] = args; - const options3 = { plural: 1 }; + const options2 = { plural: 1 }; let list = null; let named = null; if (!isString(arg1)) { @@ -14523,22 +14523,22 @@ function createVueI18n(options2 = {}) { } const key = arg1; if (isString(arg2)) { - options3.locale = arg2; + options2.locale = arg2; } else if (isNumber(arg2)) { - options3.plural = arg2; + options2.plural = arg2; } else if (isArray(arg2)) { list = arg2; } else if (isPlainObject(arg2)) { named = arg2; } if (isString(arg3)) { - options3.locale = arg3; + options2.locale = arg3; } else if (isArray(arg3)) { list = arg3; } else if (isPlainObject(arg3)) { named = arg3; } - return composer.t(key, list || named || {}, options3); + return composer.t(key, list || named || {}, options2); }, // te te(key, locale) { @@ -14603,7 +14603,7 @@ function createVueI18n(options2 = {}) { }, // for internal __onComponentInstanceCreated(target) { - const { componentInstanceCreatedListener } = options2; + const { componentInstanceCreatedListener } = options; if (componentInstanceCreatedListener) { componentInstanceCreatedListener(target, vueI18n); } @@ -14660,15 +14660,15 @@ const Translation = { }); const keys = Object.keys(slots).filter((key) => key !== "_"); return () => { - const options2 = {}; + const options = {}; if (props2.locale) { - options2.locale = props2.locale; + options.locale = props2.locale; } if (props2.plural !== void 0) { - options2.plural = isString(props2.plural) ? +props2.plural : props2.plural; + options.plural = isString(props2.plural) ? +props2.plural : props2.plural; } const arg = getInterpolateArg(context, keys); - i18n[TransrateVNodeSymbol](props2.keypath, arg, options2); + i18n[TransrateVNodeSymbol](props2.keypath, arg, options); assign({}, attrs); return isString(props2.tag) ? h(props2.tag) : isObject$1(props2.tag) ? h(props2.tag) : h(Fragment); }; @@ -14690,23 +14690,23 @@ function getInterpolateArg({ slots }, keys) { function renderFormatter(props2, context, slotKeys, partFormatter) { const { slots, attrs } = context; return () => { - const options2 = { part: true }; + const options = { part: true }; let overrides = {}; if (props2.locale) { - options2.locale = props2.locale; + options.locale = props2.locale; } if (isString(props2.format)) { - options2.key = props2.format; + options.key = props2.format; } else if (isObject$1(props2.format)) { if (isString(props2.format.key)) { - options2.key = props2.format.key; + options.key = props2.format.key; } - overrides = Object.keys(props2.format).reduce((options3, prop) => { - return slotKeys.includes(prop) ? assign({}, options3, { [prop]: props2.format[prop] }) : options3; + overrides = Object.keys(props2.format).reduce((options2, prop) => { + return slotKeys.includes(prop) ? assign({}, options2, { [prop]: props2.format[prop] }) : options2; }, {}); } - const parts = partFormatter(...[props2.value, options2, overrides]); - [options2.key]; + const parts = partFormatter(...[props2.value, options, overrides]); + [options.key]; if (isArray(parts)) { parts.map((part, index2) => { const slot = slots[part.type]; @@ -14847,21 +14847,21 @@ function parseValue(value) { } function makeParams(value) { const { path, locale, args, choice, plural } = value; - const options2 = {}; + const options = {}; const named = args || {}; if (isString(locale)) { - options2.locale = locale; + options.locale = locale; } if (isNumber(choice)) { - options2.plural = choice; + options.plural = choice; } if (isNumber(plural)) { - options2.plural = plural; + options.plural = plural; } - return [path, named, options2]; + return [path, named, options]; } -function apply(app, i18n, ...options2) { - const pluginOptions = isPlainObject(options2[0]) ? options2[0] : {}; +function apply(app, i18n, ...options) { + const pluginOptions = isPlainObject(options[0]) ? options[0] : {}; const useI18nComponentName = !!pluginOptions.useI18nComponentName; const globalInstall = isBoolean(pluginOptions.globalInstall) ? pluginOptions.globalInstall : true; if (globalInstall && useI18nComponentName) { @@ -15189,11 +15189,11 @@ function defineMixin(vuei18n, composer, i18n) { /* UNEXPECTED_ERROR */ ); } - const options2 = this.$options; - if (options2.i18n) { - const optionsI18n = options2.i18n; - if (options2.__i18n) { - optionsI18n.__i18n = options2.__i18n; + const options = this.$options; + if (options.i18n) { + const optionsI18n = options.i18n; + if (options.__i18n) { + optionsI18n.__i18n = options.__i18n; } optionsI18n.__root = composer; if (this === this.$root) { @@ -15202,12 +15202,12 @@ function defineMixin(vuei18n, composer, i18n) { optionsI18n.__injectWithOption = true; this.$i18n = createVueI18n(optionsI18n); } - } else if (options2.__i18n) { + } else if (options.__i18n) { if (this === this.$root) { - this.$i18n = mergeToRoot(vuei18n, options2); + this.$i18n = mergeToRoot(vuei18n, options); } else { this.$i18n = createVueI18n({ - __i18n: options2.__i18n, + __i18n: options.__i18n, __injectWithOption: true, __root: composer }); @@ -15263,36 +15263,36 @@ function defineMixin(vuei18n, composer, i18n) { } }; } -function mergeToRoot(root, options2) { - root.locale = options2.locale || root.locale; - root.fallbackLocale = options2.fallbackLocale || root.fallbackLocale; - root.missing = options2.missing || root.missing; - root.silentTranslationWarn = options2.silentTranslationWarn || root.silentFallbackWarn; - root.silentFallbackWarn = options2.silentFallbackWarn || root.silentFallbackWarn; - root.formatFallbackMessages = options2.formatFallbackMessages || root.formatFallbackMessages; - root.postTranslation = options2.postTranslation || root.postTranslation; - root.warnHtmlInMessage = options2.warnHtmlInMessage || root.warnHtmlInMessage; - root.escapeParameterHtml = options2.escapeParameterHtml || root.escapeParameterHtml; - root.sync = options2.sync || root.sync; - root.__composer[SetPluralRulesSymbol](options2.pluralizationRules || root.pluralizationRules); +function mergeToRoot(root, options) { + root.locale = options.locale || root.locale; + root.fallbackLocale = options.fallbackLocale || root.fallbackLocale; + root.missing = options.missing || root.missing; + root.silentTranslationWarn = options.silentTranslationWarn || root.silentFallbackWarn; + root.silentFallbackWarn = options.silentFallbackWarn || root.silentFallbackWarn; + root.formatFallbackMessages = options.formatFallbackMessages || root.formatFallbackMessages; + root.postTranslation = options.postTranslation || root.postTranslation; + root.warnHtmlInMessage = options.warnHtmlInMessage || root.warnHtmlInMessage; + root.escapeParameterHtml = options.escapeParameterHtml || root.escapeParameterHtml; + root.sync = options.sync || root.sync; + root.__composer[SetPluralRulesSymbol](options.pluralizationRules || root.pluralizationRules); const messages = getLocaleMessages(root.locale, { - messages: options2.messages, - __i18n: options2.__i18n + messages: options.messages, + __i18n: options.__i18n }); Object.keys(messages).forEach((locale) => root.mergeLocaleMessage(locale, messages[locale])); - if (options2.datetimeFormats) { - Object.keys(options2.datetimeFormats).forEach((locale) => root.mergeDateTimeFormat(locale, options2.datetimeFormats[locale])); + if (options.datetimeFormats) { + Object.keys(options.datetimeFormats).forEach((locale) => root.mergeDateTimeFormat(locale, options.datetimeFormats[locale])); } - if (options2.numberFormats) { - Object.keys(options2.numberFormats).forEach((locale) => root.mergeNumberFormat(locale, options2.numberFormats[locale])); + if (options.numberFormats) { + Object.keys(options.numberFormats).forEach((locale) => root.mergeNumberFormat(locale, options.numberFormats[locale])); } return root; } -function createI18n(options2 = {}) { - const __legacyMode = isBoolean(options2.legacy) ? options2.legacy : true; - const __globalInjection = !!options2.globalInjection; +function createI18n(options = {}) { + const __legacyMode = isBoolean(options.legacy) ? options.legacy : true; + const __globalInjection = !!options.globalInjection; const __instances = /* @__PURE__ */ new Map(); - const __global = __legacyMode ? createVueI18n(options2) : createComposer(options2); + const __global = __legacyMode ? createVueI18n(options) : createComposer(options); const symbol = makeSymbol("vue-i18n"); const i18n = { // mode @@ -15300,7 +15300,7 @@ function createI18n(options2 = {}) { return __legacyMode ? "legacy" : "composition"; }, // install plugin - async install(app, ...options3) { + async install(app, ...options2) { { app.__VUE_I18N__ = i18n; } @@ -15310,7 +15310,7 @@ function createI18n(options2 = {}) { injectGlobalFields(app, i18n.global); } { - apply(app, i18n, ...options3); + apply(app, i18n, ...options2); } if (__legacyMode) { app.mixin(defineMixin(__global, __global.__composer, i18n)); @@ -15355,7 +15355,7 @@ function createI18n(options2 = {}) { }; return i18n; } -function useI18n(options2 = {}) { +function useI18n(options = {}) { const instance = getCurrentInstance(); if (instance == null) { throw createI18nError( @@ -15377,9 +15377,9 @@ function useI18n(options2 = {}) { ); } const global2 = i18n.mode === "composition" ? i18n.global : i18n.global.__composer; - const scope = isEmptyObject(options2) ? "__i18n" in instance.type ? "local" : "global" : !options2.useScope ? "local" : options2.useScope; + const scope = isEmptyObject(options) ? "__i18n" in instance.type ? "local" : "global" : !options.useScope ? "local" : options.useScope; if (scope === "global") { - let messages = isObject$1(options2.messages) ? options2.messages : {}; + let messages = isObject$1(options.messages) ? options.messages : {}; if ("__i18nGlobal" in instance.type) { messages = getLocaleMessages(global2.locale.value, { messages, @@ -15392,26 +15392,26 @@ function useI18n(options2 = {}) { global2.mergeLocaleMessage(locale, messages[locale]); }); } - if (isObject$1(options2.datetimeFormats)) { - const locales2 = Object.keys(options2.datetimeFormats); + if (isObject$1(options.datetimeFormats)) { + const locales2 = Object.keys(options.datetimeFormats); if (locales2.length) { locales2.forEach((locale) => { - global2.mergeDateTimeFormat(locale, options2.datetimeFormats[locale]); + global2.mergeDateTimeFormat(locale, options.datetimeFormats[locale]); }); } } - if (isObject$1(options2.numberFormats)) { - const locales2 = Object.keys(options2.numberFormats); + if (isObject$1(options.numberFormats)) { + const locales2 = Object.keys(options.numberFormats); if (locales2.length) { locales2.forEach((locale) => { - global2.mergeNumberFormat(locale, options2.numberFormats[locale]); + global2.mergeNumberFormat(locale, options.numberFormats[locale]); }); } } return global2; } if (scope === "parent") { - let composer2 = getComposer(i18n, instance, options2.__useComponent); + let composer2 = getComposer(i18n, instance, options.__useComponent); if (composer2 == null) { { warn(getWarnMessage( @@ -15433,7 +15433,7 @@ function useI18n(options2 = {}) { let composer = i18nInternal.__getInstance(instance); if (composer == null) { const type = instance.type; - const composerOptions = assign({}, options2); + const composerOptions = assign({}, options); if (type.__i18n) { composerOptions.__i18n = type.__i18n; } @@ -17295,1146 +17295,6 @@ var Calendar = { return this.solar2lunar(cY, cM, cD); } }; -let QRCode = {}; -(function() { - function unicodeFormat8(code2) { - var c0, c1, c2; - if (code2 < 128) { - return [code2]; - } else if (code2 < 2048) { - c0 = 192 + (code2 >> 6); - c1 = 128 + (code2 & 63); - return [c0, c1]; - } else { - c0 = 224 + (code2 >> 12); - c1 = 128 + (code2 >> 6 & 63); - c2 = 128 + (code2 & 63); - return [c0, c1, c2]; - } - } - function getUTF8Bytes(string2) { - var utf8codes = []; - for (var i2 = 0; i2 < string2.length; i2++) { - var code2 = string2.charCodeAt(i2); - var utf8 = unicodeFormat8(code2); - for (var j = 0; j < utf8.length; j++) { - utf8codes.push(utf8[j]); - } - } - return utf8codes; - } - function QRCodeAlg(data, errorCorrectLevel) { - this.typeNumber = -1; - this.errorCorrectLevel = errorCorrectLevel; - this.modules = null; - this.moduleCount = 0; - this.dataCache = null; - this.rsBlocks = null; - this.totalDataCount = -1; - this.data = data; - this.utf8bytes = getUTF8Bytes(data); - this.make(); - } - QRCodeAlg.prototype = { - constructor: QRCodeAlg, - /** - * 获取二维码矩阵大小 - * @return {num} 矩阵大小 - */ - getModuleCount: function() { - return this.moduleCount; - }, - /** - * 编码 - */ - make: function() { - this.getRightType(); - this.dataCache = this.createData(); - this.createQrcode(); - }, - /** - * 设置二位矩阵功能图形 - * @param {bool} test 表示是否在寻找最好掩膜阶段 - * @param {num} maskPattern 掩膜的版本 - */ - makeImpl: function(maskPattern) { - this.moduleCount = this.typeNumber * 4 + 17; - this.modules = new Array(this.moduleCount); - for (var row = 0; row < this.moduleCount; row++) { - this.modules[row] = new Array(this.moduleCount); - } - this.setupPositionProbePattern(0, 0); - this.setupPositionProbePattern(this.moduleCount - 7, 0); - this.setupPositionProbePattern(0, this.moduleCount - 7); - this.setupPositionAdjustPattern(); - this.setupTimingPattern(); - this.setupTypeInfo(true, maskPattern); - if (this.typeNumber >= 7) { - this.setupTypeNumber(true); - } - this.mapData(this.dataCache, maskPattern); - }, - /** - * 设置二维码的位置探测图形 - * @param {num} row 探测图形的中心横坐标 - * @param {num} col 探测图形的中心纵坐标 - */ - setupPositionProbePattern: function(row, col) { - for (var r2 = -1; r2 <= 7; r2++) { - if (row + r2 <= -1 || this.moduleCount <= row + r2) - continue; - for (var c = -1; c <= 7; c++) { - if (col + c <= -1 || this.moduleCount <= col + c) - continue; - if (0 <= r2 && r2 <= 6 && (c == 0 || c == 6) || 0 <= c && c <= 6 && (r2 == 0 || r2 == 6) || 2 <= r2 && r2 <= 4 && 2 <= c && c <= 4) { - this.modules[row + r2][col + c] = true; - } else { - this.modules[row + r2][col + c] = false; - } - } - } - }, - /** - * 创建二维码 - * @return {[type]} [description] - */ - createQrcode: function() { - var minLostPoint = 0; - var pattern = 0; - var bestModules = null; - for (var i2 = 0; i2 < 8; i2++) { - this.makeImpl(i2); - var lostPoint = QRUtil.getLostPoint(this); - if (i2 == 0 || minLostPoint > lostPoint) { - minLostPoint = lostPoint; - pattern = i2; - bestModules = this.modules; - } - } - this.modules = bestModules; - this.setupTypeInfo(false, pattern); - if (this.typeNumber >= 7) { - this.setupTypeNumber(false); - } - }, - /** - * 设置定位图形 - * @return {[type]} [description] - */ - setupTimingPattern: function() { - for (var r2 = 8; r2 < this.moduleCount - 8; r2++) { - if (this.modules[r2][6] != null) { - continue; - } - this.modules[r2][6] = r2 % 2 == 0; - if (this.modules[6][r2] != null) { - continue; - } - this.modules[6][r2] = r2 % 2 == 0; - } - }, - /** - * 设置矫正图形 - * @return {[type]} [description] - */ - setupPositionAdjustPattern: function() { - var pos = QRUtil.getPatternPosition(this.typeNumber); - for (var i2 = 0; i2 < pos.length; i2++) { - for (var j = 0; j < pos.length; j++) { - var row = pos[i2]; - var col = pos[j]; - if (this.modules[row][col] != null) { - continue; - } - for (var r2 = -2; r2 <= 2; r2++) { - for (var c = -2; c <= 2; c++) { - if (r2 == -2 || r2 == 2 || c == -2 || c == 2 || r2 == 0 && c == 0) { - this.modules[row + r2][col + c] = true; - } else { - this.modules[row + r2][col + c] = false; - } - } - } - } - } - }, - /** - * 设置版本信息(7以上版本才有) - * @param {bool} test 是否处于判断最佳掩膜阶段 - * @return {[type]} [description] - */ - setupTypeNumber: function(test2) { - var bits = QRUtil.getBCHTypeNumber(this.typeNumber); - for (var i2 = 0; i2 < 18; i2++) { - var mod = !test2 && (bits >> i2 & 1) == 1; - this.modules[Math.floor(i2 / 3)][i2 % 3 + this.moduleCount - 8 - 3] = mod; - this.modules[i2 % 3 + this.moduleCount - 8 - 3][Math.floor(i2 / 3)] = mod; - } - }, - /** - * 设置格式信息(纠错等级和掩膜版本) - * @param {bool} test - * @param {num} maskPattern 掩膜版本 - * @return {} - */ - setupTypeInfo: function(test2, maskPattern) { - var data = QRErrorCorrectLevel[this.errorCorrectLevel] << 3 | maskPattern; - var bits = QRUtil.getBCHTypeInfo(data); - for (var i2 = 0; i2 < 15; i2++) { - var mod = !test2 && (bits >> i2 & 1) == 1; - if (i2 < 6) { - this.modules[i2][8] = mod; - } else if (i2 < 8) { - this.modules[i2 + 1][8] = mod; - } else { - this.modules[this.moduleCount - 15 + i2][8] = mod; - } - var mod = !test2 && (bits >> i2 & 1) == 1; - if (i2 < 8) { - this.modules[8][this.moduleCount - i2 - 1] = mod; - } else if (i2 < 9) { - this.modules[8][15 - i2 - 1 + 1] = mod; - } else { - this.modules[8][15 - i2 - 1] = mod; - } - } - this.modules[this.moduleCount - 8][8] = !test2; - }, - /** - * 数据编码 - * @return {[type]} [description] - */ - createData: function() { - var buffer2 = new QRBitBuffer(); - var lengthBits = this.typeNumber > 9 ? 16 : 8; - buffer2.put(4, 4); - buffer2.put(this.utf8bytes.length, lengthBits); - for (var i2 = 0, l = this.utf8bytes.length; i2 < l; i2++) { - buffer2.put(this.utf8bytes[i2], 8); - } - if (buffer2.length + 4 <= this.totalDataCount * 8) { - buffer2.put(0, 4); - } - while (buffer2.length % 8 != 0) { - buffer2.putBit(false); - } - while (true) { - if (buffer2.length >= this.totalDataCount * 8) { - break; - } - buffer2.put(QRCodeAlg.PAD0, 8); - if (buffer2.length >= this.totalDataCount * 8) { - break; - } - buffer2.put(QRCodeAlg.PAD1, 8); - } - return this.createBytes(buffer2); - }, - /** - * 纠错码编码 - * @param {buffer} buffer 数据编码 - * @return {[type]} - */ - createBytes: function(buffer2) { - var offset = 0; - var maxDcCount = 0; - var maxEcCount = 0; - var length = this.rsBlock.length / 3; - var rsBlocks = new Array(); - for (var i2 = 0; i2 < length; i2++) { - var count = this.rsBlock[i2 * 3 + 0]; - var totalCount = this.rsBlock[i2 * 3 + 1]; - var dataCount = this.rsBlock[i2 * 3 + 2]; - for (var j = 0; j < count; j++) { - rsBlocks.push([dataCount, totalCount]); - } - } - var dcdata = new Array(rsBlocks.length); - var ecdata = new Array(rsBlocks.length); - for (var r2 = 0; r2 < rsBlocks.length; r2++) { - var dcCount = rsBlocks[r2][0]; - var ecCount = rsBlocks[r2][1] - dcCount; - maxDcCount = Math.max(maxDcCount, dcCount); - maxEcCount = Math.max(maxEcCount, ecCount); - dcdata[r2] = new Array(dcCount); - for (var i2 = 0; i2 < dcdata[r2].length; i2++) { - dcdata[r2][i2] = 255 & buffer2.buffer[i2 + offset]; - } - offset += dcCount; - var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); - var rawPoly = new QRPolynomial(dcdata[r2], rsPoly.getLength() - 1); - var modPoly = rawPoly.mod(rsPoly); - ecdata[r2] = new Array(rsPoly.getLength() - 1); - for (var i2 = 0; i2 < ecdata[r2].length; i2++) { - var modIndex = i2 + modPoly.getLength() - ecdata[r2].length; - ecdata[r2][i2] = modIndex >= 0 ? modPoly.get(modIndex) : 0; - } - } - var data = new Array(this.totalDataCount); - var index2 = 0; - for (var i2 = 0; i2 < maxDcCount; i2++) { - for (var r2 = 0; r2 < rsBlocks.length; r2++) { - if (i2 < dcdata[r2].length) { - data[index2++] = dcdata[r2][i2]; - } - } - } - for (var i2 = 0; i2 < maxEcCount; i2++) { - for (var r2 = 0; r2 < rsBlocks.length; r2++) { - if (i2 < ecdata[r2].length) { - data[index2++] = ecdata[r2][i2]; - } - } - } - return data; - }, - /** - * 布置模块,构建最终信息 - * @param {} data - * @param {} maskPattern - * @return {} - */ - mapData: function(data, maskPattern) { - var inc = -1; - var row = this.moduleCount - 1; - var bitIndex = 7; - var byteIndex = 0; - for (var col = this.moduleCount - 1; col > 0; col -= 2) { - if (col == 6) - col--; - while (true) { - for (var c = 0; c < 2; c++) { - if (this.modules[row][col - c] == null) { - var dark = false; - if (byteIndex < data.length) { - dark = (data[byteIndex] >>> bitIndex & 1) == 1; - } - var mask = QRUtil.getMask(maskPattern, row, col - c); - if (mask) { - dark = !dark; - } - this.modules[row][col - c] = dark; - bitIndex--; - if (bitIndex == -1) { - byteIndex++; - bitIndex = 7; - } - } - } - row += inc; - if (row < 0 || this.moduleCount <= row) { - row -= inc; - inc = -inc; - break; - } - } - } - } - }; - QRCodeAlg.PAD0 = 236; - QRCodeAlg.PAD1 = 17; - var QRErrorCorrectLevel = [1, 0, 3, 2]; - var QRMaskPattern = { - PATTERN000: 0, - PATTERN001: 1, - PATTERN010: 2, - PATTERN011: 3, - PATTERN100: 4, - PATTERN101: 5, - PATTERN110: 6, - PATTERN111: 7 - }; - var QRUtil = { - /* - 每个版本矫正图形的位置 - */ - PATTERN_POSITION_TABLE: [ - [], - [6, 18], - [6, 22], - [6, 26], - [6, 30], - [6, 34], - [6, 22, 38], - [6, 24, 42], - [6, 26, 46], - [6, 28, 50], - [6, 30, 54], - [6, 32, 58], - [6, 34, 62], - [6, 26, 46, 66], - [6, 26, 48, 70], - [6, 26, 50, 74], - [6, 30, 54, 78], - [6, 30, 56, 82], - [6, 30, 58, 86], - [6, 34, 62, 90], - [6, 28, 50, 72, 94], - [6, 26, 50, 74, 98], - [6, 30, 54, 78, 102], - [6, 28, 54, 80, 106], - [6, 32, 58, 84, 110], - [6, 30, 58, 86, 114], - [6, 34, 62, 90, 118], - [6, 26, 50, 74, 98, 122], - [6, 30, 54, 78, 102, 126], - [6, 26, 52, 78, 104, 130], - [6, 30, 56, 82, 108, 134], - [6, 34, 60, 86, 112, 138], - [6, 30, 58, 86, 114, 142], - [6, 34, 62, 90, 118, 146], - [6, 30, 54, 78, 102, 126, 150], - [6, 24, 50, 76, 102, 128, 154], - [6, 28, 54, 80, 106, 132, 158], - [6, 32, 58, 84, 110, 136, 162], - [6, 26, 54, 82, 110, 138, 166], - [6, 30, 58, 86, 114, 142, 170] - ], - G15: 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0, - G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0, - G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1, - /* - BCH编码格式信息 - */ - getBCHTypeInfo: function(data) { - var d = data << 10; - while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { - d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15); - } - return (data << 10 | d) ^ QRUtil.G15_MASK; - }, - /* - BCH编码版本信息 - */ - getBCHTypeNumber: function(data) { - var d = data << 12; - while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { - d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18); - } - return data << 12 | d; - }, - /* - 获取BCH位信息 - */ - getBCHDigit: function(data) { - var digit = 0; - while (data != 0) { - digit++; - data >>>= 1; - } - return digit; - }, - /* - 获取版本对应的矫正图形位置 - */ - getPatternPosition: function(typeNumber) { - return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; - }, - /* - 掩膜算法 - */ - getMask: function(maskPattern, i2, j) { - switch (maskPattern) { - case QRMaskPattern.PATTERN000: - return (i2 + j) % 2 == 0; - case QRMaskPattern.PATTERN001: - return i2 % 2 == 0; - case QRMaskPattern.PATTERN010: - return j % 3 == 0; - case QRMaskPattern.PATTERN011: - return (i2 + j) % 3 == 0; - case QRMaskPattern.PATTERN100: - return (Math.floor(i2 / 2) + Math.floor(j / 3)) % 2 == 0; - case QRMaskPattern.PATTERN101: - return i2 * j % 2 + i2 * j % 3 == 0; - case QRMaskPattern.PATTERN110: - return (i2 * j % 2 + i2 * j % 3) % 2 == 0; - case QRMaskPattern.PATTERN111: - return (i2 * j % 3 + (i2 + j) % 2) % 2 == 0; - default: - throw new Error("bad maskPattern:" + maskPattern); - } - }, - /* - 获取RS的纠错多项式 - */ - getErrorCorrectPolynomial: function(errorCorrectLength) { - var a = new QRPolynomial([1], 0); - for (var i2 = 0; i2 < errorCorrectLength; i2++) { - a = a.multiply(new QRPolynomial([1, QRMath.gexp(i2)], 0)); - } - return a; - }, - /* - 获取评价 - */ - getLostPoint: function(qrCode) { - var moduleCount = qrCode.getModuleCount(), lostPoint = 0, darkCount = 0; - for (var row = 0; row < moduleCount; row++) { - var sameCount = 0; - var head = qrCode.modules[row][0]; - for (var col = 0; col < moduleCount; col++) { - var current = qrCode.modules[row][col]; - if (col < moduleCount - 6) { - if (current && !qrCode.modules[row][col + 1] && qrCode.modules[row][col + 2] && qrCode.modules[row][col + 3] && qrCode.modules[row][col + 4] && !qrCode.modules[row][col + 5] && qrCode.modules[row][col + 6]) { - if (col < moduleCount - 10) { - if (qrCode.modules[row][col + 7] && qrCode.modules[row][col + 8] && qrCode.modules[row][col + 9] && qrCode.modules[row][col + 10]) { - lostPoint += 40; - } - } else if (col > 3) { - if (qrCode.modules[row][col - 1] && qrCode.modules[row][col - 2] && qrCode.modules[row][col - 3] && qrCode.modules[row][col - 4]) { - lostPoint += 40; - } - } - } - } - if (row < moduleCount - 1 && col < moduleCount - 1) { - var count = 0; - if (current) - count++; - if (qrCode.modules[row + 1][col]) - count++; - if (qrCode.modules[row][col + 1]) - count++; - if (qrCode.modules[row + 1][col + 1]) - count++; - if (count == 0 || count == 4) { - lostPoint += 3; - } - } - if (head ^ current) { - sameCount++; - } else { - head = current; - if (sameCount >= 5) { - lostPoint += 3 + sameCount - 5; - } - sameCount = 1; - } - if (current) { - darkCount++; - } - } - } - for (var col = 0; col < moduleCount; col++) { - var sameCount = 0; - var head = qrCode.modules[0][col]; - for (var row = 0; row < moduleCount; row++) { - var current = qrCode.modules[row][col]; - if (row < moduleCount - 6) { - if (current && !qrCode.modules[row + 1][col] && qrCode.modules[row + 2][col] && qrCode.modules[row + 3][col] && qrCode.modules[row + 4][col] && !qrCode.modules[row + 5][col] && qrCode.modules[row + 6][col]) { - if (row < moduleCount - 10) { - if (qrCode.modules[row + 7][col] && qrCode.modules[row + 8][col] && qrCode.modules[row + 9][col] && qrCode.modules[row + 10][col]) { - lostPoint += 40; - } - } else if (row > 3) { - if (qrCode.modules[row - 1][col] && qrCode.modules[row - 2][col] && qrCode.modules[row - 3][col] && qrCode.modules[row - 4][col]) { - lostPoint += 40; - } - } - } - } - if (head ^ current) { - sameCount++; - } else { - head = current; - if (sameCount >= 5) { - lostPoint += 3 + sameCount - 5; - } - sameCount = 1; - } - } - } - var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; - lostPoint += ratio * 10; - return lostPoint; - } - }; - var QRMath = { - /* - 将n转化为a^m - */ - glog: function(n2) { - if (n2 < 1) { - throw new Error("glog(" + n2 + ")"); - } - return QRMath.LOG_TABLE[n2]; - }, - /* - 将a^m转化为n - */ - gexp: function(n2) { - while (n2 < 0) { - n2 += 255; - } - while (n2 >= 256) { - n2 -= 255; - } - return QRMath.EXP_TABLE[n2]; - }, - EXP_TABLE: new Array(256), - LOG_TABLE: new Array(256) - }; - for (var i = 0; i < 8; i++) { - QRMath.EXP_TABLE[i] = 1 << i; - } - for (var i = 8; i < 256; i++) { - QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8]; - } - for (var i = 0; i < 255; i++) { - QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i; - } - function QRPolynomial(num, shift) { - if (num.length == void 0) { - throw new Error(num.length + "/" + shift); - } - var offset = 0; - while (offset < num.length && num[offset] == 0) { - offset++; - } - this.num = new Array(num.length - offset + shift); - for (var i2 = 0; i2 < num.length - offset; i2++) { - this.num[i2] = num[i2 + offset]; - } - } - QRPolynomial.prototype = { - get: function(index2) { - return this.num[index2]; - }, - getLength: function() { - return this.num.length; - }, - /** - * 多项式乘法 - * @param {QRPolynomial} e 被乘多项式 - * @return {[type]} [description] - */ - multiply: function(e2) { - var num = new Array(this.getLength() + e2.getLength() - 1); - for (var i2 = 0; i2 < this.getLength(); i2++) { - for (var j = 0; j < e2.getLength(); j++) { - num[i2 + j] ^= QRMath.gexp(QRMath.glog(this.get(i2)) + QRMath.glog(e2.get(j))); - } - } - return new QRPolynomial(num, 0); - }, - /** - * 多项式模运算 - * @param {QRPolynomial} e 模多项式 - * @return {} - */ - mod: function(e2) { - var tl = this.getLength(), el = e2.getLength(); - if (tl - el < 0) { - return this; - } - var num = new Array(tl); - for (var i2 = 0; i2 < tl; i2++) { - num[i2] = this.get(i2); - } - while (num.length >= el) { - var ratio = QRMath.glog(num[0]) - QRMath.glog(e2.get(0)); - for (var i2 = 0; i2 < e2.getLength(); i2++) { - num[i2] ^= QRMath.gexp(QRMath.glog(e2.get(i2)) + ratio); - } - while (num[0] == 0) { - num.shift(); - } - } - return new QRPolynomial(num, 0); - } - }; - var RS_BLOCK_TABLE = [ - // L - // M - // Q - // H - // 1 - [1, 26, 19], - [1, 26, 16], - [1, 26, 13], - [1, 26, 9], - // 2 - [1, 44, 34], - [1, 44, 28], - [1, 44, 22], - [1, 44, 16], - // 3 - [1, 70, 55], - [1, 70, 44], - [2, 35, 17], - [2, 35, 13], - // 4 - [1, 100, 80], - [2, 50, 32], - [2, 50, 24], - [4, 25, 9], - // 5 - [1, 134, 108], - [2, 67, 43], - [2, 33, 15, 2, 34, 16], - [2, 33, 11, 2, 34, 12], - // 6 - [2, 86, 68], - [4, 43, 27], - [4, 43, 19], - [4, 43, 15], - // 7 - [2, 98, 78], - [4, 49, 31], - [2, 32, 14, 4, 33, 15], - [4, 39, 13, 1, 40, 14], - // 8 - [2, 121, 97], - [2, 60, 38, 2, 61, 39], - [4, 40, 18, 2, 41, 19], - [4, 40, 14, 2, 41, 15], - // 9 - [2, 146, 116], - [3, 58, 36, 2, 59, 37], - [4, 36, 16, 4, 37, 17], - [4, 36, 12, 4, 37, 13], - // 10 - [2, 86, 68, 2, 87, 69], - [4, 69, 43, 1, 70, 44], - [6, 43, 19, 2, 44, 20], - [6, 43, 15, 2, 44, 16], - // 11 - [4, 101, 81], - [1, 80, 50, 4, 81, 51], - [4, 50, 22, 4, 51, 23], - [3, 36, 12, 8, 37, 13], - // 12 - [2, 116, 92, 2, 117, 93], - [6, 58, 36, 2, 59, 37], - [4, 46, 20, 6, 47, 21], - [7, 42, 14, 4, 43, 15], - // 13 - [4, 133, 107], - [8, 59, 37, 1, 60, 38], - [8, 44, 20, 4, 45, 21], - [12, 33, 11, 4, 34, 12], - // 14 - [3, 145, 115, 1, 146, 116], - [4, 64, 40, 5, 65, 41], - [11, 36, 16, 5, 37, 17], - [11, 36, 12, 5, 37, 13], - // 15 - [5, 109, 87, 1, 110, 88], - [5, 65, 41, 5, 66, 42], - [5, 54, 24, 7, 55, 25], - [11, 36, 12], - // 16 - [5, 122, 98, 1, 123, 99], - [7, 73, 45, 3, 74, 46], - [15, 43, 19, 2, 44, 20], - [3, 45, 15, 13, 46, 16], - // 17 - [1, 135, 107, 5, 136, 108], - [10, 74, 46, 1, 75, 47], - [1, 50, 22, 15, 51, 23], - [2, 42, 14, 17, 43, 15], - // 18 - [5, 150, 120, 1, 151, 121], - [9, 69, 43, 4, 70, 44], - [17, 50, 22, 1, 51, 23], - [2, 42, 14, 19, 43, 15], - // 19 - [3, 141, 113, 4, 142, 114], - [3, 70, 44, 11, 71, 45], - [17, 47, 21, 4, 48, 22], - [9, 39, 13, 16, 40, 14], - // 20 - [3, 135, 107, 5, 136, 108], - [3, 67, 41, 13, 68, 42], - [15, 54, 24, 5, 55, 25], - [15, 43, 15, 10, 44, 16], - // 21 - [4, 144, 116, 4, 145, 117], - [17, 68, 42], - [17, 50, 22, 6, 51, 23], - [19, 46, 16, 6, 47, 17], - // 22 - [2, 139, 111, 7, 140, 112], - [17, 74, 46], - [7, 54, 24, 16, 55, 25], - [34, 37, 13], - // 23 - [4, 151, 121, 5, 152, 122], - [4, 75, 47, 14, 76, 48], - [11, 54, 24, 14, 55, 25], - [16, 45, 15, 14, 46, 16], - // 24 - [6, 147, 117, 4, 148, 118], - [6, 73, 45, 14, 74, 46], - [11, 54, 24, 16, 55, 25], - [30, 46, 16, 2, 47, 17], - // 25 - [8, 132, 106, 4, 133, 107], - [8, 75, 47, 13, 76, 48], - [7, 54, 24, 22, 55, 25], - [22, 45, 15, 13, 46, 16], - // 26 - [10, 142, 114, 2, 143, 115], - [19, 74, 46, 4, 75, 47], - [28, 50, 22, 6, 51, 23], - [33, 46, 16, 4, 47, 17], - // 27 - [8, 152, 122, 4, 153, 123], - [22, 73, 45, 3, 74, 46], - [8, 53, 23, 26, 54, 24], - [12, 45, 15, 28, 46, 16], - // 28 - [3, 147, 117, 10, 148, 118], - [3, 73, 45, 23, 74, 46], - [4, 54, 24, 31, 55, 25], - [11, 45, 15, 31, 46, 16], - // 29 - [7, 146, 116, 7, 147, 117], - [21, 73, 45, 7, 74, 46], - [1, 53, 23, 37, 54, 24], - [19, 45, 15, 26, 46, 16], - // 30 - [5, 145, 115, 10, 146, 116], - [19, 75, 47, 10, 76, 48], - [15, 54, 24, 25, 55, 25], - [23, 45, 15, 25, 46, 16], - // 31 - [13, 145, 115, 3, 146, 116], - [2, 74, 46, 29, 75, 47], - [42, 54, 24, 1, 55, 25], - [23, 45, 15, 28, 46, 16], - // 32 - [17, 145, 115], - [10, 74, 46, 23, 75, 47], - [10, 54, 24, 35, 55, 25], - [19, 45, 15, 35, 46, 16], - // 33 - [17, 145, 115, 1, 146, 116], - [14, 74, 46, 21, 75, 47], - [29, 54, 24, 19, 55, 25], - [11, 45, 15, 46, 46, 16], - // 34 - [13, 145, 115, 6, 146, 116], - [14, 74, 46, 23, 75, 47], - [44, 54, 24, 7, 55, 25], - [59, 46, 16, 1, 47, 17], - // 35 - [12, 151, 121, 7, 152, 122], - [12, 75, 47, 26, 76, 48], - [39, 54, 24, 14, 55, 25], - [22, 45, 15, 41, 46, 16], - // 36 - [6, 151, 121, 14, 152, 122], - [6, 75, 47, 34, 76, 48], - [46, 54, 24, 10, 55, 25], - [2, 45, 15, 64, 46, 16], - // 37 - [17, 152, 122, 4, 153, 123], - [29, 74, 46, 14, 75, 47], - [49, 54, 24, 10, 55, 25], - [24, 45, 15, 46, 46, 16], - // 38 - [4, 152, 122, 18, 153, 123], - [13, 74, 46, 32, 75, 47], - [48, 54, 24, 14, 55, 25], - [42, 45, 15, 32, 46, 16], - // 39 - [20, 147, 117, 4, 148, 118], - [40, 75, 47, 7, 76, 48], - [43, 54, 24, 22, 55, 25], - [10, 45, 15, 67, 46, 16], - // 40 - [19, 148, 118, 6, 149, 119], - [18, 75, 47, 31, 76, 48], - [34, 54, 24, 34, 55, 25], - [20, 45, 15, 61, 46, 16] - ]; - QRCodeAlg.prototype.getRightType = function() { - for (var typeNumber = 1; typeNumber < 41; typeNumber++) { - var rsBlock = RS_BLOCK_TABLE[(typeNumber - 1) * 4 + this.errorCorrectLevel]; - if (rsBlock == void 0) { - throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + this.errorCorrectLevel); - } - var length = rsBlock.length / 3; - var totalDataCount = 0; - for (var i2 = 0; i2 < length; i2++) { - var count = rsBlock[i2 * 3 + 0]; - var dataCount = rsBlock[i2 * 3 + 2]; - totalDataCount += dataCount * count; - } - var lengthBytes = typeNumber > 9 ? 2 : 1; - if (this.utf8bytes.length + lengthBytes < totalDataCount || typeNumber == 40) { - this.typeNumber = typeNumber; - this.rsBlock = rsBlock; - this.totalDataCount = totalDataCount; - break; - } - } - }; - function QRBitBuffer() { - this.buffer = new Array(); - this.length = 0; - } - QRBitBuffer.prototype = { - get: function(index2) { - var bufIndex = Math.floor(index2 / 8); - return this.buffer[bufIndex] >>> 7 - index2 % 8 & 1; - }, - put: function(num, length) { - for (var i2 = 0; i2 < length; i2++) { - this.putBit(num >>> length - i2 - 1 & 1); - } - }, - putBit: function(bit) { - var bufIndex = Math.floor(this.length / 8); - if (this.buffer.length <= bufIndex) { - this.buffer.push(0); - } - if (bit) { - this.buffer[bufIndex] |= 128 >>> this.length % 8; - } - this.length++; - } - }; - let qrcodeAlgObjCache = []; - QRCode = function(opt) { - this.options = { - text: "", - size: 256, - correctLevel: 3, - background: "#ffffff", - foreground: "#000000", - pdground: "#000000", - image: "", - imageSize: 30, - canvasId: opt.canvasId, - nvueContext: opt.nvueContext, - context: opt.context, - usingComponents: opt.usingComponents, - showLoading: opt.showLoading, - loadingText: opt.loadingText - }; - let canvas = null; - if (typeof opt === "string") { - opt = { - text: opt - }; - } - if (opt) { - for (var i2 in opt) { - this.options[i2] = opt[i2]; - } - } - var qrCodeAlg = null; - for (var i2 = 0, l = qrcodeAlgObjCache.length; i2 < l; i2++) { - if (qrcodeAlgObjCache[i2].text == this.options.text && qrcodeAlgObjCache[i2].text.correctLevel == this.options.correctLevel) { - qrCodeAlg = qrcodeAlgObjCache[i2].obj; - break; - } - } - if (i2 == l) { - qrCodeAlg = new QRCodeAlg(this.options.text, this.options.correctLevel); - qrcodeAlgObjCache.push({ - text: this.options.text, - correctLevel: this.options.correctLevel, - obj: qrCodeAlg - }); - } - let getForeGround = function(config2) { - var options2 = config2.options; - if (options2.pdground && (config2.row > 1 && config2.row < 5 && config2.col > 1 && config2.col < 5 || config2.row > config2.count - 6 && config2.row < config2.count - 2 && config2.col > 1 && config2.col < 5 || config2.row > 1 && config2.row < 5 && config2.col > config2.count - 6 && config2.col < config2.count - 2)) { - return options2.pdground; - } - return options2.foreground; - }; - let getCanvas = async (id) => { - return new Promise((resolve2, reject) => { - try { - const query = index$1.createSelectorQuery().in(this.options.context); - query.select(`#${id}`).fields({ node: true, size: true }).exec((res) => { - resolve2(res[0].node); - }); - } catch (e2) { - console.error("createCanvasContextFail", e2); - } - }); - }; - let createCanvas = async function(options2) { - let isApp = false; - if (options2.showLoading) { - index$1.showLoading({ - title: options2.loadingText, - mask: true - }); - } - var ctx = ""; - if (options2.nvueContext) { - ctx = options2.nvueContext; - } else { - canvas = await getCanvas(options2.canvasId); - canvas.width = options2.size; - canvas.height = options2.size; - ctx = canvas.getContext("2d"); - } - options2.context.ctx = ctx; - options2.context.canvas = canvas; - var count = qrCodeAlg.getModuleCount(); - var ratioSize = options2.size; - var ratioImgSize = options2.imageSize; - var tileW = (ratioSize / count).toPrecision(4); - var tileH = (ratioSize / count).toPrecision(4); - for (var row = 0; row < count; row++) { - for (var col = 0; col < count; col++) { - var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW); - var h2 = Math.ceil((row + 1) * tileH) - Math.floor(row * tileH); - var foreground = getForeGround({ - row, - col, - count, - options: options2 - }); - if (options2.nvueContext) { - ctx.setFillStyle(qrCodeAlg.modules[row][col] ? foreground : options2.background); - } else { - ctx.fillStyle = qrCodeAlg.modules[row][col] ? foreground : options2.background; - } - ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h2); - } - } - if (options2.image) { - let drawRoundedRect = function(ctxi, x2, y2, width, height, r2, lineWidth, fill, stroke) { - if (options2.nvueContext || isApp) { - ctxi.setLineWidth(lineWidth); - ctxi.setFillStyle(options2.background); - ctxi.setStrokeStyle(options2.background); - } else { - ctxi.lineWidth = lineWidth; - ctxi.fillStyle = options2.background; - ctxi.strokeStyle = options2.background; - } - ctxi.beginPath(); - ctxi.moveTo(x2 + r2, y2); - ctxi.lineTo(x2 + width, y2); - ctxi.arc(x2 + width - r2, y2 + r2, r2, -Math.PI / 2, 0); - ctxi.lineTo(x2 + width, y2 + height - r2); - ctxi.arc(x2 + width - r2, y2 + height - r2, r2, 0, Math.PI / 2); - ctxi.lineTo(x2 + r2, y2 + height); - ctxi.arc(x2 + r2, y2 + height - r2, r2, Math.PI / 2, Math.PI); - ctxi.lineTo(x2, y2 + r2); - ctxi.arc(x2 + r2, y2 + r2, r2, Math.PI, Math.PI * 3 / 2); - ctxi.closePath(); - if (fill) { - ctxi.fill(); - } - if (stroke) { - ctxi.stroke(); - } - }; - var x = Number(((ratioSize - ratioImgSize) / 2).toFixed(2)); - var y = Number(((ratioSize - ratioImgSize) / 2).toFixed(2)); - drawRoundedRect(ctx, x, y, ratioImgSize, ratioImgSize, 2, 6, true, true); - if (options2.nvueContext) { - ctx.drawImage(options2.image, x, y, ratioImgSize, ratioImgSize); - } else { - const img = canvas.createImage(); - img.onload = () => { - ctx.drawImage(img, x, y, ratioImgSize, ratioImgSize); - }; - img.src = options2.image; - } - } - setTimeout(() => { - if (options2.nvueContext || isApp) { - ctx.draw(true, () => { - setTimeout(() => { - if (options2.nvueContext) { - ctx.toTempFilePath( - 0, - 0, - options2.width, - options2.height, - options2.width, - options2.height, - "", - 1, - function(res) { - if (options2.cbResult) { - options2.cbResult(res.tempFilePath); - } - } - ); - } else { - index$1.canvasToTempFilePath({ - width: options2.width, - height: options2.height, - destWidth: options2.width, - destHeight: options2.height, - canvasId: options2.canvasId, - quality: Number(1), - success: function(res) { - if (options2.cbResult) { - if (!empty2(res.tempFilePath)) { - options2.cbResult(res.tempFilePath); - } else if (!empty2(res.apFilePath)) { - options2.cbResult(res.apFilePath); - } else { - options2.cbResult(res.tempFilePath); - } - } - }, - fail: function(res) { - if (options2.cbResult) { - options2.cbResult(res); - } - }, - complete: function() { - index$1.hideLoading(); - } - }, options2.context); - } - }, options2.text.length + 100); - }); - } else { - options2.cbResult(""); - } - }, options2.usingComponents ? 0 : 150); - }; - createCanvas(this.options); - let empty2 = function(v) { - let tp = typeof v, rt = false; - if (tp == "number" && String(v) == "") { - rt = true; - } else if (tp == "undefined") { - rt = true; - } else if (tp == "object") { - if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) - rt = true; - } else if (tp == "string") { - if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") - rt = true; - } else if (tp == "function") { - rt = false; - } - return rt; - }; - }; - QRCode.prototype.clear = function(fn) { - var ctx = ""; - if (options.nvueContext) { - ctx = options.nvueContext; - } else { - index$1.createCanvasContext(this.options.canvasId, this.options.context); - } - ctx.clearRect(0, 0, this.options.size, this.options.size); - ctx.draw(false, () => { - if (fn) { - fn(); - } - }); - }; -})(); -const QRCode$1 = QRCode; const props$8 = defineMixin$1({ props: { // 输入框的内容 @@ -19279,7 +18139,6 @@ const props = defineMixin$1({ } }); exports.Calendar = Calendar; -exports.QRCode = QRCode$1; exports._export_sfc = _export_sfc; exports.addStyle = addStyle; exports.addUnit = addUnit; @@ -19334,3 +18193,4 @@ exports.throttle = throttle; exports.toast = toast; exports.transitionMixin = transitionMixin; exports.uviewPlus = uviewPlus; +exports.wx$1 = wx$1; diff --git a/miniprogram/dist/dev/mp-weixin/modules/api/AppServer.js b/miniprogram/dist/dev/mp-weixin/modules/api/AppServer.js index 8d3943f..ded88b7 100644 --- a/miniprogram/dist/dev/mp-weixin/modules/api/AppServer.js +++ b/miniprogram/dist/dev/mp-weixin/modules/api/AppServer.js @@ -185,9 +185,13 @@ AppServer.prototype.deleteData = async function(url) { return err; }); }; -AppServer.prototype.WechatLogin = async function(code) { +AppServer.prototype.WechatLogin = async function(code, invitationCode) { var url = serverConfig.apiUrl_Auth_WechatLogin; - return this.postData(url, { code }).then((data) => { + var postData = { code }; + if (invitationCode) { + postData.invitationCode = invitationCode; + } + return this.postData(url, postData).then((data) => { return data; }); }; diff --git a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.js b/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.js deleted file mode 100644 index 1cce21c..0000000 --- a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.js +++ /dev/null @@ -1,363 +0,0 @@ -"use strict"; -const common_vendor = require("../../../../common/vendor.js"); -let qrcode; -const _sfc_main = { - name: "u-qrcode", - props: { - cid: { - type: String, - default: () => `u-qrcode-canvas${Math.floor(Math.random() * 1e6)}` - }, - size: { - type: Number, - default: 200 - }, - unit: { - type: String, - default: "px" - }, - show: { - type: Boolean, - default: true - }, - val: { - type: String, - default: "" - }, - background: { - type: String, - default: "#ffffff" - }, - foreground: { - type: String, - default: "#000000" - }, - pdground: { - type: String, - default: "#000000" - }, - icon: { - type: String, - default: "" - }, - iconSize: { - type: Number, - default: 40 - }, - lv: { - type: Number, - default: 3 - }, - onval: { - type: Boolean, - default: true - }, - loadMake: { - type: Boolean, - default: true - }, - usingComponents: { - type: Boolean, - default: true - }, - showLoading: { - type: Boolean, - default: true - }, - loadingText: { - type: String, - default: "生成中" - }, - allowPreview: { - type: Boolean, - default: false - }, - // 是否使用根节点宽高 - useRootHeightAndWidth: { - type: Boolean, - default: () => false - } - }, - emits: ["result", "longpressCallback"], - data() { - return { - loading: false, - result: "", - popupShow: false, - list: [ - { - name: "保存二维码" - } - ], - rootId: `rootId${Number(Math.random() * 100).toFixed(0)}`, - ganvas: null, - context: "", - canvasObj: {}, - sizeLocal: this.size, - ctx: null, - // ctx 在new Qrcode 时js文件内部设置 - canvas: null - // ctx 在new Qrcode 时js文件内部设置 - }; - }, - async mounted() { - if (this.useRootHeightAndWidth) { - await this.setNewSize(); - } - if (this.loadMake) { - if (!this._empty(this.val)) { - setTimeout(() => { - setTimeout(() => { - this._makeCode(); - }); - }, 0); - } - } - }, - methods: { - _makeCode() { - let that2 = this; - if (!this._empty(this.val)) { - this.loading = true; - qrcode = new common_vendor.QRCode({ - context: that2, - // 上下文环境 - canvasId: that2.cid, - // canvas-id - nvueContext: that2.context, - usingComponents: that2.usingComponents, - // 是否是自定义组件 - showLoading: false, - // 是否显示loading - loadingText: that2.loadingText, - // loading文字 - text: that2.val, - // 生成内容 - size: that2.sizeLocal, - // 二维码大小 - background: that2.background, - // 背景色 - foreground: that2.foreground, - // 前景色 - pdground: that2.pdground, - // 定位角点颜色 - correctLevel: that2.lv, - // 容错级别 - image: that2.icon, - // 二维码图标 - imageSize: that2.iconSize, - // 二维码图标大小 - cbResult: function(res) { - that2._result(res); - } - }); - } else { - common_vendor.index.showToast({ - title: "二维码内容不能为空", - icon: "none", - duration: 2e3 - }); - } - }, - _clearCode() { - this._result(""); - qrcode.clear(); - }, - _saveCode() { - let that2 = this; - if (this.result != "") { - common_vendor.index.saveImageToPhotosAlbum({ - filePath: that2.result, - success: function() { - common_vendor.index.showToast({ - title: "二维码保存成功", - icon: "success", - duration: 2e3 - }); - } - }); - } - }, - preview(e) { - if (this.allowPreview) { - common_vendor.index.previewImage({ - urls: [this.result], - longPressActions: { - itemList: ["保存二维码图片"], - success: function(data) { - switch (data.tapIndex) { - case 0: - that._saveCode(); - break; - } - }, - fail: function(err) { - console.log(err.errMsg); - } - } - }); - } - this.$emit("preview", { - url: this.result - }, e); - }, - async toTempFilePath({ success, fail }) { - if (this.context) { - this.ctx.toTempFilePath( - 0, - 0, - this.sizeLocal, - this.sizeLocal, - this.sizeLocal, - this.sizeLocal, - "", - 1, - (res) => { - success(res); - } - ); - } else { - const canvas = await this.getNode(this.cid, true); - common_vendor.index.canvasToTempFilePath( - { - canvas, - success: (res) => { - success(res); - }, - fail - }, - this - ); - } - }, - async longpress() { - this.toTempFilePath({ - success: (res) => { - this.$emit("longpressCallback", res.tempFilePath); - }, - fail: (err) => { - } - }); - }, - /** - * 使用根节点宽高 设置新的size - * @return {Promise} - */ - async setNewSize() { - const rootNode = await this.getNode(this.rootId, false); - const { width, height } = rootNode; - if (width > height) { - this.sizeLocal = height; - } else { - this.sizeLocal = width; - } - }, - /** - * 获取节点 - * @param id 节点id - * @param isCanvas 是否为Canvas节点 - * @return {Promise} - */ - async getNode(id, isCanvas) { - return new Promise((resolve, reject) => { - try { - const query = common_vendor.index.createSelectorQuery().in(this); - query.select(`#${id}`).fields({ node: true, size: true }).exec((res) => { - if (isCanvas) { - resolve(res[0].node); - } else { - resolve(res[0]); - } - }); - } catch (e) { - console.error("获取节点失败", e); - } - }); - }, - selectClick(index) { - switch (index) { - case 0: - alert("保存二维码"); - this._saveCode(); - break; - } - }, - _result(res) { - this.loading = false; - this.result = res; - this.$emit("result", res); - }, - _empty(v) { - let tp = typeof v, rt = false; - if (tp == "number" && String(v) == "") { - rt = true; - } else if (tp == "undefined") { - rt = true; - } else if (tp == "object") { - if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) - rt = true; - } else if (tp == "string") { - if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") - rt = true; - } else if (tp == "function") { - rt = false; - } - return rt; - } - }, - watch: { - size: function(n, o) { - if (n != o && !this._empty(n)) { - this.cSize = n; - if (!this._empty(this.val)) { - setTimeout(() => { - this._makeCode(); - }, 100); - } - } - }, - val: function(n, o) { - if (this.onval) { - if (n != o && !this._empty(n)) { - setTimeout(() => { - this._makeCode(); - }, 0); - } - } - } - }, - computed: {} -}; -if (!Array) { - const _easycom_up_loading_icon2 = common_vendor.resolveComponent("up-loading-icon"); - _easycom_up_loading_icon2(); -} -const _easycom_up_loading_icon = () => "../u-loading-icon/u-loading-icon.js"; -if (!Math) { - _easycom_up_loading_icon(); -} -function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { - return common_vendor.e({ - a: $props.cid, - b: $props.cid, - c: $data.sizeLocal + $props.unit, - d: $data.sizeLocal + $props.unit, - e: $props.showLoading && $data.loading - }, $props.showLoading && $data.loading ? { - f: common_vendor.p({ - vertical: true, - text: $props.loadingText, - textSize: "14px" - }), - g: $data.sizeLocal + $props.unit, - h: $data.sizeLocal + $props.unit - } : {}, { - i: common_vendor.o((...args) => $options.preview && $options.preview(...args)), - j: $data.rootId, - k: $props.useRootHeightAndWidth ? "100%" : "auto", - l: $props.useRootHeightAndWidth ? "100%" : "auto", - m: common_vendor.o((...args) => $options.longpress && $options.longpress(...args)) - }); -} -const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-444ebaa9"], ["__file", "F:/gitCode/uniapp/appointment_system/miniprogram/node_modules/uview-plus/components/u-qrcode/u-qrcode.vue"]]); -wx.createComponent(Component); diff --git a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.json b/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.json deleted file mode 100644 index a33cad0..0000000 --- a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "component": true, - "usingComponents": { - "up-loading-icon": "../u-loading-icon/u-loading-icon" - } -} \ No newline at end of file diff --git a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.wxml b/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.wxml deleted file mode 100644 index ecd8c17..0000000 --- a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.wxml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.wxss b/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.wxss deleted file mode 100644 index 9d37da3..0000000 --- a/miniprogram/dist/dev/mp-weixin/node-modules/uview-plus/components/u-qrcode/u-qrcode.wxss +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 这里是uni-app内置的常用样式变量 - * - * uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量 - * 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App - * - */ -/** - * 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能 - * - * 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件 - */ -/* 颜色变量 */ -/* 行为相关颜色 */ -/* 文字基本颜色 */ -/* 背景颜色 */ -/* 边框颜色 */ -/* 尺寸变量 */ -/* 文字尺寸 */ -/* 图片尺寸 */ -/* Border Radius */ -/* 水平间距 */ -/* 垂直间距 */ -/* 透明度 */ -/* 文章场景相关 */ -.u-qrcode__loading.data-v-444ebaa9 { - display: flex; - justify-content: center; - align-items: center; - background-color: #f7f7f7; - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; -} -.u-qrcode__content.data-v-444ebaa9 { - position: relative; -} -.u-qrcode__content__canvas.data-v-444ebaa9 { - position: fixed; - top: -99999rpx; - left: -99999rpx; - z-index: -99999; -} \ No newline at end of file diff --git a/miniprogram/dist/dev/mp-weixin/pages/index/index.js b/miniprogram/dist/dev/mp-weixin/pages/index/index.js index 8b0217e..b7b31d9 100644 --- a/miniprogram/dist/dev/mp-weixin/pages/index/index.js +++ b/miniprogram/dist/dev/mp-weixin/pages/index/index.js @@ -17,7 +17,33 @@ const _sfc_main = { // 应用名称 }; }, - onLoad() { + onLoad(options) { + let inviteCode = ""; + if (options && options.inviteCode) { + inviteCode = options.inviteCode; + } + if (options && options.scene) { + const scene = decodeURIComponent(options.scene); + console.log("小程序码 scene:", scene); + const params = {}; + scene.split("&").forEach((item) => { + const [key, value] = item.split("="); + if (key && value) { + params[key] = value; + } + }); + if (params.inviteCode) { + inviteCode = params.inviteCode; + } + } + if (inviteCode) { + console.log("收到邀请码:", inviteCode); + const app = getApp(); + if (app && app.globalData) { + app.globalData.inviteCode = inviteCode; + } + common_vendor.index.setStorageSync("inviteCode", inviteCode); + } this.loadConfig(); this.loadBanners(); this.loadHotServices(); diff --git a/miniprogram/dist/dev/mp-weixin/pages/login/login-page.js b/miniprogram/dist/dev/mp-weixin/pages/login/login-page.js index 70ba3ca..61727a7 100644 --- a/miniprogram/dist/dev/mp-weixin/pages/login/login-page.js +++ b/miniprogram/dist/dev/mp-weixin/pages/login/login-page.js @@ -47,8 +47,18 @@ const _sfc_main = { this.isLoading = false; return; } + let invitationCode = ""; + const app = getApp(); + if (app && app.globalData && app.globalData.inviteCode) { + invitationCode = app.globalData.inviteCode; + } else { + invitationCode = common_vendor.index.getStorageSync("inviteCode") || ""; + } + if (invitationCode) { + console.log("使用邀请码登录:", invitationCode); + } const appserver = new modules_api_AppServer.AppServer(); - const data = await appserver.WechatLogin(loginRes.code); + const data = await appserver.WechatLogin(loginRes.code, invitationCode); console.log("登录接口返回:", data); if (!data) { console.error("登录接口无响应"); @@ -80,6 +90,14 @@ const _sfc_main = { console.log("登录成功,保存认证信息"); const token = "Bearer " + data.data.token; utils_auth.saveAuthData(token, data.data.refreshToken, data.data.user); + if (invitationCode) { + const app2 = getApp(); + if (app2 && app2.globalData) { + app2.globalData.inviteCode = ""; + } + common_vendor.index.removeStorageSync("inviteCode"); + console.log("邀请码已清除"); + } common_vendor.index.showToast({ title: this.$t("login.loginSuccess") || "登录成功", icon: "success", diff --git a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.js b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.js index 3c91d67..8ed0087 100644 --- a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.js +++ b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.js @@ -16,6 +16,12 @@ const _sfc_main = { qrcodeDataUrl: "", qrcodeValue: "", // 二维码内容 + wxQrcodeImage: "", + // 微信小程序码图片(base64) + qrcodeLoading: false, + // 小程序码加载状态 + qrcodeError: "", + // 小程序码错误信息 appLogo: "", // 应用logo,用于分享图片 applyStep: 1, @@ -124,7 +130,7 @@ const _sfc_main = { this.commissionStats = res.data; this.updateWithdrawDisplay(); const inviteCode = res.data.invitationCode || ""; - this.qrcodeValue = `https://your-domain.com/invite?code=${inviteCode}`; + this.qrcodeValue = `/pages/index/index?inviteCode=${inviteCode}`; } } catch (error) { console.error("获取佣金统计失败:", error); @@ -205,21 +211,30 @@ const _sfc_main = { showCancel: false }); }, - generateQRCode() { - const inviteCode = this.commissionStats.invitationCode || ""; - this.qrcodeValue = `https://your-domain.com/invite?code=${inviteCode}`; - this.showQRCodeContent = false; + async generateQRCode() { + if (this.wxQrcodeImage) { + this.showQRCodeModal = true; + return; + } this.showQRCodeModal = true; - }, - onQRCodePopupOpen() { - setTimeout(() => { - this.showQRCodeContent = true; - }, 100); + this.qrcodeLoading = true; + this.qrcodeError = ""; + try { + const res = await appServer.GetMiniProgramQRCode({ width: 430 }); + if (res && res.code === 0 && res.data && res.data.qrcodeUrl) { + this.wxQrcodeImage = res.data.qrcodeUrl; + } else { + this.qrcodeError = (res == null ? void 0 : res.message) || "生成小程序码失败"; + } + } catch (error) { + console.error("生成小程序码失败:", error); + this.qrcodeError = "网络错误,请重试"; + } finally { + this.qrcodeLoading = false; + } }, closeQRCodeModal() { - this.showQRCodeContent = false; this.showQRCodeModal = false; - this.qrcodeDataUrl = ""; }, shareQRCodeToFriend() { common_vendor.index.showToast({ @@ -228,52 +243,58 @@ const _sfc_main = { }); }, saveQRCodeImage() { - if (this.$refs.uQrcode) { - this.$refs.uQrcode.toTempFilePath({ - success: (res) => { - common_vendor.index.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: () => { - common_vendor.index.showToast({ - title: this.$t("invite.saveSuccess") || "保存成功", - icon: "success" - }); - }, - fail: (err) => { - console.error("保存图片失败:", err); - if (err.errMsg && err.errMsg.includes("auth deny")) { - common_vendor.index.showModal({ - title: "提示", - content: "需要您授权保存图片到相册", - success: (modalRes) => { - if (modalRes.confirm) { - common_vendor.index.openSetting(); - } - } - }); - } else { - common_vendor.index.showToast({ - title: "保存失败", - icon: "none" - }); - } - } - }); - }, - fail: (err) => { - console.error("获取二维码图片失败:", err); - common_vendor.index.showToast({ - title: "获取二维码失败", - icon: "none" - }); - } - }); - } else { + if (!this.wxQrcodeImage) { common_vendor.index.showToast({ - title: "二维码生成中,请稍候", + title: "小程序码加载中,请稍候", icon: "none" }); + return; } + const base64Data = this.wxQrcodeImage.replace(/^data:image\/\w+;base64,/, ""); + const filePath = `${common_vendor.wx$1.env.USER_DATA_PATH}/qrcode_${Date.now()}.png`; + const fs = common_vendor.index.getFileSystemManager(); + fs.writeFile({ + filePath, + data: base64Data, + encoding: "base64", + success: () => { + common_vendor.index.saveImageToPhotosAlbum({ + filePath, + success: () => { + common_vendor.index.showToast({ + title: this.$t("invite.saveSuccess") || "保存成功", + icon: "success" + }); + }, + fail: (err) => { + console.error("保存图片失败:", err); + if (err.errMsg && err.errMsg.includes("auth deny")) { + common_vendor.index.showModal({ + title: "提示", + content: "需要您授权保存图片到相册", + success: (modalRes) => { + if (modalRes.confirm) { + common_vendor.index.openSetting(); + } + } + }); + } else { + common_vendor.index.showToast({ + title: "保存失败", + icon: "none" + }); + } + } + }); + }, + fail: (err) => { + console.error("写入文件失败:", err); + common_vendor.index.showToast({ + title: "保存失败", + icon: "none" + }); + } + }); }, shareToFriend() { common_vendor.index.share({ @@ -439,13 +460,11 @@ const _sfc_main = { }; if (!Array) { const _easycom_up_popup2 = common_vendor.resolveComponent("up-popup"); - const _easycom_u_qrcode2 = common_vendor.resolveComponent("u-qrcode"); - (_easycom_up_popup2 + _easycom_u_qrcode2)(); + _easycom_up_popup2(); } const _easycom_up_popup = () => "../../node-modules/uview-plus/components/u-popup/u-popup.js"; -const _easycom_u_qrcode = () => "../../node-modules/uview-plus/components/u-qrcode/u-qrcode.js"; if (!Math) { - (_easycom_up_popup + _easycom_u_qrcode)(); + _easycom_up_popup(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ @@ -521,22 +540,17 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { bgColor: "#ffffff" }), N: common_vendor.t(_ctx.$t("invite.qrcodeTitle") || "邀请好友,赢现金"), - O: $data.showQRCodeContent - }, $data.showQRCodeContent ? { - P: common_vendor.sr("uQrcode", "830ba560-2,830ba560-1"), - Q: common_vendor.p({ - val: $data.qrcodeValue, - size: 200, - unit: "px", - ["load-make"]: true, - ["using-components"]: true - }) - } : {}, { - R: common_vendor.t(_ctx.$t("invite.shareToFriend") || "分享给好友"), - S: common_vendor.t(_ctx.$t("invite.saveImage") || "保存图片"), - T: common_vendor.o((...args) => $options.saveQRCodeImage && $options.saveQRCodeImage(...args)), - U: common_vendor.o($options.closeQRCodeModal), - V: common_vendor.o($options.onQRCodePopupOpen), + O: $data.wxQrcodeImage + }, $data.wxQrcodeImage ? { + P: $data.wxQrcodeImage + } : $data.qrcodeLoading ? {} : { + R: common_vendor.t($data.qrcodeError || "加载失败") + }, { + Q: $data.qrcodeLoading, + S: common_vendor.t(_ctx.$t("invite.shareToFriend") || "分享给好友"), + T: common_vendor.t(_ctx.$t("invite.saveImage") || "保存图片"), + U: common_vendor.o((...args) => $options.saveQRCodeImage && $options.saveQRCodeImage(...args)), + V: common_vendor.o($options.closeQRCodeModal), W: common_vendor.p({ show: $data.showQRCodeModal, mode: "center", diff --git a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.json b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.json index a63086e..83c6aff 100644 --- a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.json +++ b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.json @@ -2,7 +2,6 @@ "navigationBarTitleText": "", "navigationStyle": "custom", "usingComponents": { - "up-popup": "../../node-modules/uview-plus/components/u-popup/u-popup", - "u-qrcode": "../../node-modules/uview-plus/components/u-qrcode/u-qrcode" + "up-popup": "../../node-modules/uview-plus/components/u-popup/u-popup" } } \ No newline at end of file diff --git a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxml b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxml index f2a3cf3..c36aff7 100644 --- a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxml +++ b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxml @@ -1 +1 @@ -{{c}}{{e}}{{f}}{{g}}{{h}}{{i}}{{j}}{{k}}{{m}}{{p}}{{q}}{{item.a}}{{t}}{{item.b}}{{v}}{{x}}{{y}}{{z}}{{A}}{{B}}{{item.a}}{{item.b}}{{item.c}}¥0{{E}}{{F}}{{H}}{{I}}{{J}}{{item.a}}¥{{item.b}}{{item.c}}{{N}}{{S}}{{Y}} {{Z}}/2{{ab}}{{af}}{{ag}}{{ah}}1.{{ak}}{{al}}{{ao}}{{ar}}2.{{aw}}+2.{{aB}}{{aC}}{{aG}}{{aK}}{{aO}} ({{aP}}){{aT}} \ No newline at end of file +{{c}}{{e}}{{f}}{{g}}{{h}}{{i}}{{j}}{{k}}{{m}}{{p}}{{q}}{{item.a}}{{t}}{{item.b}}{{v}}{{x}}{{y}}{{z}}{{A}}{{B}}{{item.a}}{{item.b}}{{item.c}}¥0{{E}}{{F}}{{H}}{{I}}{{J}}{{item.a}}¥{{item.b}}{{item.c}}{{N}}加载中...{{R}}{{T}}{{Y}} {{Z}}/2{{ab}}{{af}}{{ag}}{{ah}}1.{{ak}}{{al}}{{ao}}{{ar}}2.{{aw}}+2.{{aB}}{{aC}}{{aG}}{{aK}}{{aO}} ({{aP}}){{aT}} \ No newline at end of file diff --git a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxss b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxss index 043b0f2..431bcf9 100644 --- a/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxss +++ b/miniprogram/dist/dev/mp-weixin/pages/me/invite-reward-page.wxss @@ -480,19 +480,23 @@ margin-bottom: 30rpx; box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); position: relative; - overflow: visible; + overflow: hidden; } -.qrcode-modal-content .qrcode-box.data-v-830ba560 .u-qrcode { - position: static !important; +.qrcode-modal-content .qrcode-box .wx-qrcode-image.data-v-830ba560 { + width: 400rpx; + height: 400rpx; +} +.qrcode-modal-content .qrcode-box .qrcode-loading.data-v-830ba560 { display: flex; align-items: center; justify-content: center; + color: #999; + font-size: 28rpx; } -.qrcode-modal-content .qrcode-box.data-v-830ba560 .u-qrcode__content { - position: static !important; - display: flex; - align-items: center; - justify-content: center; +.qrcode-modal-content .qrcode-box .qrcode-error.data-v-830ba560 { + color: #ff4d4f; + font-size: 26rpx; + text-align: center; } .qrcode-modal-content .qrcode-box.data-v-830ba560 .u-qrcode__canvas { position: static !important; diff --git a/miniprogram/dist/dev/mp-weixin/project.config.json b/miniprogram/dist/dev/mp-weixin/project.config.json index 7fe64a9..56a2a4d 100644 --- a/miniprogram/dist/dev/mp-weixin/project.config.json +++ b/miniprogram/dist/dev/mp-weixin/project.config.json @@ -14,7 +14,7 @@ "compileType": "miniprogram", "libVersion": "", "appid": "wx34e8a031d0d78b81", - "projectname": "appointment_system", + "projectname": "一起飞Go Mundo", "condition": { "search": { "current": -1, diff --git a/miniprogram/src/App.vue b/miniprogram/src/App.vue index ea232a2..d00fe89 100644 --- a/miniprogram/src/App.vue +++ b/miniprogram/src/App.vue @@ -7,7 +7,8 @@ user: null, shouldRefresh: false, loginTime: 0, - config: null // 应用配置(从后端获取) + config: null, // 应用配置(从后端获取) + inviteCode: '' // 邀请码(从分享链接获取) }, onLaunch: function() { console.log('App Launch') diff --git a/miniprogram/src/manifest.json b/miniprogram/src/manifest.json index 62f99f2..e878979 100644 --- a/miniprogram/src/manifest.json +++ b/miniprogram/src/manifest.json @@ -1,5 +1,5 @@ { - "name" : "appointment_system", + "name" : "一起飞Go Mundo", "appid" : "__UNI__C6C43F9", "description" : "", "versionName" : "1.0.0", diff --git a/miniprogram/src/modules/api/AppServer.js b/miniprogram/src/modules/api/AppServer.js index 403b554..2668948 100644 --- a/miniprogram/src/modules/api/AppServer.js +++ b/miniprogram/src/modules/api/AppServer.js @@ -269,10 +269,15 @@ AppServer.prototype.deleteData = async function(url) { /** * 微信登录 * @param {String} code - 微信登录code + * @param {String} invitationCode - 邀请码(可选) */ -AppServer.prototype.WechatLogin = async function(code) { +AppServer.prototype.WechatLogin = async function(code, invitationCode) { var url = serverConfig.apiUrl_Auth_WechatLogin - return this.postData(url, { code }).then((data) => { + var postData = { code } + if (invitationCode) { + postData.invitationCode = invitationCode + } + return this.postData(url, postData).then((data) => { return data; }) } diff --git a/miniprogram/src/pages/index/index.vue b/miniprogram/src/pages/index/index.vue index eff99e9..d877ed2 100644 --- a/miniprogram/src/pages/index/index.vue +++ b/miniprogram/src/pages/index/index.vue @@ -70,7 +70,45 @@ appName: '' // 应用名称 } }, - onLoad() { + onLoad(options) { + // 处理邀请码参数 + let inviteCode = '' + + // 方式1:普通分享链接,直接从 options.inviteCode 获取 + if (options && options.inviteCode) { + inviteCode = options.inviteCode + } + + // 方式2:小程序码扫码进入,从 scene 参数解析 + // 小程序码的 scene 格式为 "inviteCode=XXXXXX" + if (options && options.scene) { + const scene = decodeURIComponent(options.scene) + console.log('小程序码 scene:', scene) + // 解析 scene 参数 + const params = {} + scene.split('&').forEach(item => { + const [key, value] = item.split('=') + if (key && value) { + params[key] = value + } + }) + if (params.inviteCode) { + inviteCode = params.inviteCode + } + } + + // 保存邀请码 + if (inviteCode) { + console.log('收到邀请码:', inviteCode) + // 保存邀请码到全局数据,登录时使用 + const app = getApp() + if (app && app.globalData) { + app.globalData.inviteCode = inviteCode + } + // 同时保存到本地存储,防止丢失 + uni.setStorageSync('inviteCode', inviteCode) + } + // 不在首页检查登录状态,允许游客浏览 this.loadConfig() this.loadBanners() diff --git a/miniprogram/src/pages/login/login-page.vue b/miniprogram/src/pages/login/login-page.vue index 14b9e4f..5c6e270 100644 --- a/miniprogram/src/pages/login/login-page.vue +++ b/miniprogram/src/pages/login/login-page.vue @@ -104,9 +104,22 @@ return } - // 调用后端登录接口 + // 获取邀请码(从全局数据或本地存储) + let invitationCode = '' + const app = getApp() + if (app && app.globalData && app.globalData.inviteCode) { + invitationCode = app.globalData.inviteCode + } else { + invitationCode = uni.getStorageSync('inviteCode') || '' + } + + if (invitationCode) { + console.log('使用邀请码登录:', invitationCode) + } + + // 调用后端登录接口(带邀请码) const appserver = new AppServer(); - const data = await appserver.WechatLogin(loginRes.code); + const data = await appserver.WechatLogin(loginRes.code, invitationCode); console.log('登录接口返回:', data); @@ -148,6 +161,16 @@ // 保存认证信息 const token = "Bearer " + data.data.token saveAuthData(token, data.data.refreshToken, data.data.user) + + // 清除邀请码(已使用) + if (invitationCode) { + const app = getApp() + if (app && app.globalData) { + app.globalData.inviteCode = '' + } + uni.removeStorageSync('inviteCode') + console.log('邀请码已清除') + } // 登录成功 uni.showToast({ diff --git a/miniprogram/src/pages/me/INVITE_SYSTEM.md b/miniprogram/src/pages/me/INVITE_SYSTEM.md new file mode 100644 index 0000000..2a60783 --- /dev/null +++ b/miniprogram/src/pages/me/INVITE_SYSTEM.md @@ -0,0 +1,179 @@ +# 邀请新人系统文档 + +## 功能概述 + +用户可以通过分享邀请链接或小程序码邀请新用户注册,新用户注册后会自动绑定邀请关系,邀请人可获得佣金奖励。 + +## 完整流程 + +``` +邀请者分享 → 新用户点击/扫码 → 进入小程序 → 保存邀请码 → 登录注册 → 绑定邀请关系 +``` + +## 分享方式 + +### 1. 分享给微信好友 +- 入口:邀请奖励页面 → 分享给好友按钮 +- 实现:`onShareAppMessage()` +- 链接格式:`/pages/index/index?inviteCode=XXXXXX` + +### 2. 分享到朋友圈 +- 入口:邀请奖励页面 → 右上角分享 +- 实现:`onShareTimeline()` +- 参数格式:`inviteCode=XXXXXX` + +### 3. 小程序码 +- 入口:邀请奖励页面 → 生成二维码按钮 +- 实现:调用后端 `/api/v1/qrcode/miniprogram` 接口 +- 参数格式:`scene=inviteCode=XXXXXX` + +## 技术实现 + +### 前端文件 + +| 文件 | 功能 | +|------|------| +| `App.vue` | 定义 `globalData.inviteCode` 存储邀请码 | +| `pages/index/index.vue` | 接收并保存邀请码 | +| `pages/login/login-page.vue` | 登录时传递邀请码 | +| `pages/me/invite-reward-page.vue` | 邀请奖励页面,分享功能 | +| `modules/api/AppServer.js` | API调用,`WechatLogin(code, invitationCode)` | + +### 后端文件 + +| 文件 | 功能 | +|------|------| +| `services/authService.js` | 微信登录,处理邀请码绑定 | +| `routes/qrcodeRoutes.js` | 生成小程序码 | +| `models/User.js` | 用户模型,`invitedBy` 字段 | +| `models/Invitation.js` | 邀请关系模型 | + +### 邀请码接收逻辑 (index.vue) + +```javascript +onLoad(options) { + let inviteCode = '' + + // 方式1:普通分享链接 + if (options && options.inviteCode) { + inviteCode = options.inviteCode + } + + // 方式2:小程序码扫码(scene参数) + if (options && options.scene) { + const scene = decodeURIComponent(options.scene) + const params = {} + scene.split('&').forEach(item => { + const [key, value] = item.split('=') + if (key && value) params[key] = value + }) + if (params.inviteCode) inviteCode = params.inviteCode + } + + // 保存邀请码 + if (inviteCode) { + getApp().globalData.inviteCode = inviteCode + uni.setStorageSync('inviteCode', inviteCode) + } +} +``` + +### 登录绑定逻辑 (login-page.vue) + +```javascript +async handleWechatLogin() { + // 获取邀请码 + let invitationCode = '' + const app = getApp() + if (app?.globalData?.inviteCode) { + invitationCode = app.globalData.inviteCode + } else { + invitationCode = uni.getStorageSync('inviteCode') || '' + } + + // 调用登录接口(带邀请码) + const data = await appserver.WechatLogin(loginRes.code, invitationCode) + + // 登录成功后清除邀请码 + if (invitationCode) { + app.globalData.inviteCode = '' + uni.removeStorageSync('inviteCode') + } +} +``` + +### 后端绑定逻辑 (authService.js) + +```javascript +const wechatLogin = async (code, userInfo, invitationCode, deviceInfo) => { + // ... 获取openId + + let user = await User.findOne({ where: { wechatOpenId: openId } }) + + if (!user) { + // 新用户注册 + const userData = { + wechatOpenId: openId, + invitationCode: await generateUniqueInvitationCode(), + } + + // 处理邀请关系 + if (invitationCode) { + const inviter = await User.findOne({ where: { invitationCode } }) + if (inviter) { + userData.invitedBy = inviter.id + // 创建邀请记录 + await Invitation.create({ + inviterId: inviter.id, + inviteeId: user.id, + invitationCode, + registeredAt: new Date(), + rewardStatus: 'pending', + }) + } + } + + user = await User.create(userData) + } + // ... 返回token +} +``` + +## 数据模型 + +### User 表 +- `invitationCode`: 用户的邀请码(唯一) +- `invitedBy`: 邀请人ID + +### Invitation 表 +- `inviterId`: 邀请人ID +- `inviteeId`: 被邀请人ID +- `invitationCode`: 使用的邀请码 +- `registeredAt`: 注册时间 +- `firstPaymentAt`: 首次付款时间 +- `rewardAmount`: 奖励金额 +- `rewardStatus`: 奖励状态 (pending/credited/cancelled) + +## 注意事项 + +1. **小程序码限制**:`page` 参数必须是已发布的小程序页面 +2. **开发环境**:开发版/体验版扫码可能无法正常跳转 +3. **邀请码有效性**:只对新用户有效,老用户登录不会重复绑定 +4. **scene参数限制**:最长32字符,格式为 `inviteCode=XXXXXX` + +## API接口 + +### 生成小程序码 +``` +POST /api/v1/qrcode/miniprogram +Authorization: Bearer {token} +Body: { width: 430 } +Response: { code: 0, data: { invitationCode, qrcodeUrl } } +``` + +### 微信登录(带邀请码) +``` +POST /api/v1/auth/wechat-login +Body: { code, invitationCode } +Response: { code: 0, data: { token, user } } +``` diff --git a/miniprogram/src/pages/me/invite-reward-page.vue b/miniprogram/src/pages/me/invite-reward-page.vue index 0554b5c..0d4a077 100644 --- a/miniprogram/src/pages/me/invite-reward-page.vue +++ b/miniprogram/src/pages/me/invite-reward-page.vue @@ -159,11 +159,15 @@ - + {{ $t('invite.qrcodeTitle') || '邀请好友,赢现金' }} - + + + 加载中... + + {{ qrcodeError || '加载失败' }} @@ -291,6 +295,9 @@ showQRCodeContent: false, // 控制二维码内容显示 qrcodeDataUrl: '', qrcodeValue: '', // 二维码内容 + wxQrcodeImage: '', // 微信小程序码图片(base64) + qrcodeLoading: false, // 小程序码加载状态 + qrcodeError: '', // 小程序码错误信息 appLogo: '', // 应用logo,用于分享图片 applyStep: 1, withdrawAmount: '', @@ -404,9 +411,9 @@ this.commissionStats = res.data // 更新提现记录显示 this.updateWithdrawDisplay() - // 预先设置二维码内容,用于分享 + // 预先设置二维码内容,用于分享(使用小程序路径) const inviteCode = res.data.invitationCode || '' - this.qrcodeValue = `https://your-domain.com/invite?code=${inviteCode}` + this.qrcodeValue = `/pages/index/index?inviteCode=${inviteCode}` } } catch (error) { console.error('获取佣金统计失败:', error) @@ -491,26 +498,36 @@ showCancel: false }) }, - generateQRCode() { - // 构建邀请链接,包含邀请码 - const inviteCode = this.commissionStats.invitationCode || '' - // 设置二维码内容为邀请链接 - this.qrcodeValue = `https://your-domain.com/invite?code=${inviteCode}` - // 先隐藏二维码内容 - this.showQRCodeContent = false - // 打开二维码弹窗 + async generateQRCode() { + // 如果已有小程序码,直接显示 + if (this.wxQrcodeImage) { + this.showQRCodeModal = true + return + } + + // 显示弹窗并开始加载 this.showQRCodeModal = true - }, - onQRCodePopupOpen() { - // 弹窗打开后延迟显示二维码 - setTimeout(() => { - this.showQRCodeContent = true - }, 100) + this.qrcodeLoading = true + this.qrcodeError = '' + + try { + // 调用后端API获取微信小程序码 + const res = await appServer.GetMiniProgramQRCode({ width: 430 }) + + if (res && res.code === 0 && res.data && res.data.qrcodeUrl) { + this.wxQrcodeImage = res.data.qrcodeUrl + } else { + this.qrcodeError = res?.message || '生成小程序码失败' + } + } catch (error) { + console.error('生成小程序码失败:', error) + this.qrcodeError = '网络错误,请重试' + } finally { + this.qrcodeLoading = false + } }, closeQRCodeModal() { - this.showQRCodeContent = false this.showQRCodeModal = false - this.qrcodeDataUrl = '' }, shareQRCodeToFriend() { // 分享给好友 @@ -524,53 +541,62 @@ }) }, saveQRCodeImage() { - // 使用 u-qrcode 组件的 toTempFilePath 方法获取图片并保存 - if (this.$refs.uQrcode) { - this.$refs.uQrcode.toTempFilePath({ - success: (res) => { - uni.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: () => { - uni.showToast({ - title: this.$t('invite.saveSuccess') || '保存成功', - icon: 'success' - }) - }, - fail: (err) => { - console.error('保存图片失败:', err) - if (err.errMsg && err.errMsg.includes('auth deny')) { - uni.showModal({ - title: '提示', - content: '需要您授权保存图片到相册', - success: (modalRes) => { - if (modalRes.confirm) { - uni.openSetting() - } - } - }) - } else { - uni.showToast({ - title: '保存失败', - icon: 'none' - }) - } - } - }) - }, - fail: (err) => { - console.error('获取二维码图片失败:', err) - uni.showToast({ - title: '获取二维码失败', - icon: 'none' - }) - } - }) - } else { + if (!this.wxQrcodeImage) { uni.showToast({ - title: '二维码生成中,请稍候', + title: '小程序码加载中,请稍候', icon: 'none' }) + return } + + // 将 base64 图片保存到相册 + // 先将 base64 转为临时文件 + const base64Data = this.wxQrcodeImage.replace(/^data:image\/\w+;base64,/, '') + const filePath = `${wx.env.USER_DATA_PATH}/qrcode_${Date.now()}.png` + + const fs = uni.getFileSystemManager() + fs.writeFile({ + filePath: filePath, + data: base64Data, + encoding: 'base64', + success: () => { + uni.saveImageToPhotosAlbum({ + filePath: filePath, + success: () => { + uni.showToast({ + title: this.$t('invite.saveSuccess') || '保存成功', + icon: 'success' + }) + }, + fail: (err) => { + console.error('保存图片失败:', err) + if (err.errMsg && err.errMsg.includes('auth deny')) { + uni.showModal({ + title: '提示', + content: '需要您授权保存图片到相册', + success: (modalRes) => { + if (modalRes.confirm) { + uni.openSetting() + } + } + }) + } else { + uni.showToast({ + title: '保存失败', + icon: 'none' + }) + } + } + }) + }, + fail: (err) => { + console.error('写入文件失败:', err) + uni.showToast({ + title: '保存失败', + icon: 'none' + }) + } + }) }, shareToFriend() { uni.share({ @@ -1295,21 +1321,25 @@ margin-bottom: 30rpx; box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); position: relative; - overflow: visible; + overflow: hidden; - // 修复 u-qrcode 组件的 canvas 定位问题 - :deep(.u-qrcode) { - position: static !important; - display: flex; - align-items: center; - justify-content: center; + .wx-qrcode-image { + width: 400rpx; + height: 400rpx; } - :deep(.u-qrcode__content) { - position: static !important; + .qrcode-loading { display: flex; align-items: center; justify-content: center; + color: #999; + font-size: 28rpx; + } + + .qrcode-error { + color: #ff4d4f; + font-size: 26rpx; + text-align: center; } :deep(.u-qrcode__canvas) {