From b4b23e70f587299929950ef5443806a0d4d46755 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 27 Apr 2021 20:52:11 +0800 Subject: [PATCH] feat: uniCloud --- .eslintrc.js | 4 +- packages/shims-node.d.ts | 1 + packages/uni-cli-shared/package.json | 1 + packages/uni-cli-shared/src/index.ts | 1 + packages/uni-cli-shared/src/uni/compiler.ts | 44 + packages/uni-cli-shared/src/uni/index.ts | 3 + packages/uni-cli-shared/src/uni/plugin.ts | 27 + packages/uni-cli-shared/src/uni/utils.ts | 61 + packages/uni-cloud/dist/uni-cloud.esm.js | 3300 +++++++++++++++++ packages/uni-cloud/lib/uni.config.js | 81 + packages/uni-cloud/package.json | 23 + packages/uni-h5/dist/uni-h5.esm.js | 297 +- packages/uni-h5/vite.config.ts | 10 +- packages/vite-plugin-uni/src/config/index.ts | 4 +- .../src/config/optimizeDeps.ts | 1 + .../vite-plugin-uni/src/config/resolve.ts | 4 +- .../src/configResolved/plugins/index.ts | 18 +- .../src/configResolved/plugins/pagesJson.ts | 3 +- .../src/configureServer/index.ts | 3 + packages/vite-plugin-uni/src/index.ts | 5 + .../vite-plugin-uni/src/resolveId/index.ts | 17 +- yarn.lock | 5 + 22 files changed, 3632 insertions(+), 281 deletions(-) create mode 100644 packages/uni-cli-shared/src/uni/compiler.ts create mode 100644 packages/uni-cli-shared/src/uni/index.ts create mode 100644 packages/uni-cli-shared/src/uni/plugin.ts create mode 100644 packages/uni-cli-shared/src/uni/utils.ts create mode 100644 packages/uni-cloud/dist/uni-cloud.esm.js create mode 100644 packages/uni-cloud/lib/uni.config.js create mode 100644 packages/uni-cloud/package.json diff --git a/.eslintrc.js b/.eslintrc.js index 9b8ea89f5..4bb94069c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -35,7 +35,7 @@ module.exports = { // Packages targeting DOM { files: [ - 'packages/{uni-components,uni-h5,uni-h5-vue,uni-shared,uni-core}/**', + 'packages/{uni-api,uni-app,uni-components,uni-core,uni-h5,uni-h5-vue,uni-i18n,uni-shared,uni-vue}/**', ], rules: { 'no-restricted-globals': ['error', ...NodeGlobals], @@ -44,7 +44,7 @@ module.exports = { // Packages targeting Node { files: [ - 'packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx,vite-plugin-uni}/**', + 'packages/{uni-cli-shared,vite-plugin-uni}/**', 'packages/*/vite.config.ts', ], rules: { diff --git a/packages/shims-node.d.ts b/packages/shims-node.d.ts index e8734be66..5d4c863f9 100644 --- a/packages/shims-node.d.ts +++ b/packages/shims-node.d.ts @@ -3,5 +3,6 @@ declare namespace NodeJS { UNI_PLATFORM: UniApp.PLATFORM UNI_INPUT_DIR: string UNI_OUTPUT_DIR: string + UNI_CLI_CONTEXT: string } } diff --git a/packages/uni-cli-shared/package.json b/packages/uni-cli-shared/package.json index f327f3ec2..a78b479f0 100644 --- a/packages/uni-cli-shared/package.json +++ b/packages/uni-cli-shared/package.json @@ -25,6 +25,7 @@ "debug": "^4.3.1", "jsonc-parser": "^3.0.0", "slash": "^3.0.0", + "tapable": "^2.2.0", "xregexp": "3.1.0" }, "peerDependencies": { diff --git a/packages/uni-cli-shared/src/index.ts b/packages/uni-cli-shared/src/index.ts index b0a12c682..516d35bce 100644 --- a/packages/uni-cli-shared/src/index.ts +++ b/packages/uni-cli-shared/src/index.ts @@ -1,3 +1,4 @@ +export * from './uni' export * from './url' export * from './json' export * from './utils' diff --git a/packages/uni-cli-shared/src/uni/compiler.ts b/packages/uni-cli-shared/src/uni/compiler.ts new file mode 100644 index 000000000..130d3b8c0 --- /dev/null +++ b/packages/uni-cli-shared/src/uni/compiler.ts @@ -0,0 +1,44 @@ +import debug from 'debug' +import { SyncHook, SyncWaterfallHook } from 'tapable' +import { UniPlugin } from './plugin' + +interface UniCompilerHooks { + init: SyncHook + define: SyncWaterfallHook> + inject: SyncWaterfallHook> + done: SyncHook +} + +const debugCompiler = debug('uni:compiler') + +export class UniCompiler { + hooks: UniCompilerHooks + constructor({ plugins }: { plugins: UniPlugin[] }) { + this.hooks = { + init: new SyncHook(), + define: new SyncWaterfallHook(['define']), + inject: new SyncWaterfallHook(['inject']), + done: new SyncHook(), + } + plugins.forEach((plugin) => { + debugCompiler('plugin', plugin.name) + plugin.apply(this) + }) + } + init() { + return this.hooks.init.call() + } + define() { + const define = this.hooks.define.call({}) + debugCompiler('define', define) + return define + } + inject() { + const inject = this.hooks.inject.call({}) + debugCompiler('inject', inject) + return inject + } + done() { + return this.hooks.done.call() + } +} diff --git a/packages/uni-cli-shared/src/uni/index.ts b/packages/uni-cli-shared/src/uni/index.ts new file mode 100644 index 000000000..0931b3b14 --- /dev/null +++ b/packages/uni-cli-shared/src/uni/index.ts @@ -0,0 +1,3 @@ +export * from './utils' +export * from './compiler' +export * from './plugin' diff --git a/packages/uni-cli-shared/src/uni/plugin.ts b/packages/uni-cli-shared/src/uni/plugin.ts new file mode 100644 index 000000000..17ea0b7a7 --- /dev/null +++ b/packages/uni-cli-shared/src/uni/plugin.ts @@ -0,0 +1,27 @@ +import { isFunction } from '@vue/shared' +import { UniCompiler } from './compiler' + +export interface UniPluginConfig { + init?: () => void + define?: () => Record + inject?: () => Record + done?: () => void +} +export class UniPlugin { + name: string + private options: UniPluginConfig + constructor(name: string, config: UniPluginConfig = {}) { + this.name = name + this.options = config + } + apply(compiler: UniCompiler) { + const { + name, + options: { init, define, inject, done }, + } = this + isFunction(init) && compiler.hooks.init.tap(name, init) + isFunction(define) && compiler.hooks.define.tap(name, define) + isFunction(inject) && compiler.hooks.inject.tap(name, inject) + isFunction(done) && compiler.hooks.done.tap(name, done) + } +} diff --git a/packages/uni-cli-shared/src/uni/utils.ts b/packages/uni-cli-shared/src/uni/utils.ts new file mode 100644 index 000000000..d305909c8 --- /dev/null +++ b/packages/uni-cli-shared/src/uni/utils.ts @@ -0,0 +1,61 @@ +import path from 'path' +import { UniCompiler } from './compiler' +import { UniPlugin } from './plugin' +interface PluginConfig { + id: string + name: string + config: { + name: string + main?: string + } +} + +interface InitUniCompilerOptions { + root: string +} + +export function initUniCompiler(opts: InitUniCompilerOptions) { + return new UniCompiler({ plugins: initPlugins(resolvePlugins(opts)) }) +} + +function initPlugin(plugin: PluginConfig) { + const configFile = path.join( + plugin.id, + plugin.config.main || '/lib/uni.config.js' + ) + try { + /* eslint-disable no-restricted-globals */ + return new UniPlugin(plugin.id, require(configFile)) + } catch (e) { + console.warn(`${configFile} not found`) + } +} + +function initPlugins(plugins: PluginConfig[]): UniPlugin[] { + return plugins + .map((plugin) => initPlugin(plugin)) + .filter(Boolean as any) +} + +function resolvePlugins(opts: InitUniCompilerOptions) { + /* eslint-disable no-restricted-globals */ + const pkg = require(path.join(opts.root, 'package.json')) + return Object.keys(pkg.devDependencies || {}) + .concat(Object.keys(pkg.dependencies || {})) + .map((id) => { + try { + /* eslint-disable no-restricted-globals */ + const pluginPkg = require(id + '/package.json') + const config = pluginPkg['uni-app'] + if (!config || !config.name) { + return + } + return { + id, + name: config.name, + config, + } + } catch (e) {} + }) + .filter(Boolean as any) +} diff --git a/packages/uni-cloud/dist/uni-cloud.esm.js b/packages/uni-cloud/dist/uni-cloud.esm.js new file mode 100644 index 000000000..5dbed563b --- /dev/null +++ b/packages/uni-cloud/dist/uni-cloud.esm.js @@ -0,0 +1,3300 @@ +import { + initVueI18n as e +} from "@dcloudio/uni-i18n"; +"undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : "undefined" != typeof global ? + global : "undefined" != typeof self && self; + +function t(e) { + return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e +} + +function s(e, t, s) { + return e(s = { + path: t, + exports: {}, + require: function(e, t) { + return function() { + throw new Error( + "Dynamic requires are not currently supported by @rollup/plugin-commonjs") + }(null == t && s.path) + } + }, s.exports), s.exports +} +var n = s((function(e, t) { + var s; + e.exports = (s = s || function(e, t) { + var s = Object.create || function() { + function e() {} + return function(t) { + var s; + return e.prototype = t, s = new e, e.prototype = null, s + } + }(), + n = {}, + r = n.lib = {}, + o = r.Base = { + extend: function(e) { + var t = s(this); + return e && t.mixIn(e), t.hasOwnProperty("init") && this.init !== t.init || + (t.init = function() { + t.$super.init.apply(this, arguments) + }), t.init.prototype = t, t.$super = this, t + }, + create: function() { + var e = this.extend(); + return e.init.apply(e, arguments), e + }, + init: function() {}, + mixIn: function(e) { + for (var t in e) e.hasOwnProperty(t) && (this[t] = e[t]); + e.hasOwnProperty("toString") && (this.toString = e.toString) + }, + clone: function() { + return this.init.prototype.extend(this) + } + }, + i = r.WordArray = o.extend({ + init: function(e, t) { + e = this.words = e || [], this.sigBytes = null != t ? t : 4 * e.length + }, + toString: function(e) { + return (e || c).stringify(this) + }, + concat: function(e) { + var t = this.words, + s = e.words, + n = this.sigBytes, + r = e.sigBytes; + if (this.clamp(), n % 4) + for (var o = 0; o < r; o++) { + var i = s[o >>> 2] >>> 24 - o % 4 * 8 & 255; + t[n + o >>> 2] |= i << 24 - (n + o) % 4 * 8 + } else + for (o = 0; o < r; o += 4) t[n + o >>> 2] = s[o >>> 2]; + return this.sigBytes += r, this + }, + clamp: function() { + var t = this.words, + s = this.sigBytes; + t[s >>> 2] &= 4294967295 << 32 - s % 4 * 8, t.length = e.ceil(s / 4) + }, + clone: function() { + var e = o.clone.call(this); + return e.words = this.words.slice(0), e + }, + random: function(t) { + for (var s, n = [], r = function(t) { + t = t; + var s = 987654321, + n = 4294967295; + return function() { + var r = ((s = 36969 * (65535 & s) + (s >> 16) & + n) << 16) + (t = 18e3 * (65535 & t) + (t >> + 16) & n) & n; + return r /= 4294967296, (r += .5) * (e.random() > + .5 ? 1 : -1) + } + }, o = 0; o < t; o += 4) { + var a = r(4294967296 * (s || e.random())); + s = 987654071 * a(), n.push(4294967296 * a() | 0) + } + return new i.init(n, t) + } + }), + a = n.enc = {}, + c = a.Hex = { + stringify: function(e) { + for (var t = e.words, s = e.sigBytes, n = [], r = 0; r < s; r++) { + var o = t[r >>> 2] >>> 24 - r % 4 * 8 & 255; + n.push((o >>> 4).toString(16)), n.push((15 & o).toString(16)) + } + return n.join("") + }, + parse: function(e) { + for (var t = e.length, s = [], n = 0; n < t; n += 2) s[n >>> 3] |= parseInt( + e.substr(n, 2), 16) << 24 - n % 8 * 4; + return new i.init(s, t / 2) + } + }, + u = a.Latin1 = { + stringify: function(e) { + for (var t = e.words, s = e.sigBytes, n = [], r = 0; r < s; r++) { + var o = t[r >>> 2] >>> 24 - r % 4 * 8 & 255; + n.push(String.fromCharCode(o)) + } + return n.join("") + }, + parse: function(e) { + for (var t = e.length, s = [], n = 0; n < t; n++) s[n >>> 2] |= (255 & e + .charCodeAt(n)) << 24 - n % 4 * 8; + return new i.init(s, t) + } + }, + h = a.Utf8 = { + stringify: function(e) { + try { + return decodeURIComponent(escape(u.stringify(e))) + } catch (e) { + throw new Error("Malformed UTF-8 data") + } + }, + parse: function(e) { + return u.parse(unescape(encodeURIComponent(e))) + } + }, + l = r.BufferedBlockAlgorithm = o.extend({ + reset: function() { + this._data = new i.init, this._nDataBytes = 0 + }, + _append: function(e) { + "string" == typeof e && (e = h.parse(e)), this._data.concat(e), this + ._nDataBytes += e.sigBytes + }, + _process: function(t) { + var s = this._data, + n = s.words, + r = s.sigBytes, + o = this.blockSize, + a = r / (4 * o), + c = (a = t ? e.ceil(a) : e.max((0 | a) - this._minBufferSize, 0)) * + o, + u = e.min(4 * c, r); + if (c) { + for (var h = 0; h < c; h += o) this._doProcessBlock(n, h); + var l = n.splice(0, c); + s.sigBytes -= u + } + return new i.init(l, u) + }, + clone: function() { + var e = o.clone.call(this); + return e._data = this._data.clone(), e + }, + _minBufferSize: 0 + }), + d = (r.Hasher = l.extend({ + cfg: o.extend(), + init: function(e) { + this.cfg = this.cfg.extend(e), this.reset() + }, + reset: function() { + l.reset.call(this), this._doReset() + }, + update: function(e) { + return this._append(e), this._process(), this + }, + finalize: function(e) { + return e && this._append(e), this._doFinalize() + }, + blockSize: 16, + _createHelper: function(e) { + return function(t, s) { + return new e.init(s).finalize(t) + } + }, + _createHmacHelper: function(e) { + return function(t, s) { + return new d.HMAC.init(e, s).finalize(t) + } + } + }), n.algo = {}); + return n + }(Math), s) + })), + r = (s((function(e, t) { + var s; + e.exports = (s = n, function(e) { + var t = s, + n = t.lib, + r = n.WordArray, + o = n.Hasher, + i = t.algo, + a = []; + ! function() { + for (var t = 0; t < 64; t++) a[t] = 4294967296 * e.abs(e.sin(t + 1)) | 0 + }(); + var c = i.MD5 = o.extend({ + _doReset: function() { + this._hash = new r.init([1732584193, 4023233417, 2562383102, + 271733878 + ]) + }, + _doProcessBlock: function(e, t) { + for (var s = 0; s < 16; s++) { + var n = t + s, + r = e[n]; + e[n] = 16711935 & (r << 8 | r >>> 24) | 4278255360 & (r << 24 | + r >>> 8) + } + var o = this._hash.words, + i = e[t + 0], + c = e[t + 1], + f = e[t + 2], + p = e[t + 3], + g = e[t + 4], + m = e[t + 5], + y = e[t + 6], + _ = e[t + 7], + v = e[t + 8], + w = e[t + 9], + S = e[t + 10], + T = e[t + 11], + k = e[t + 12], + A = e[t + 13], + P = e[t + 14], + I = e[t + 15], + E = o[0], + O = o[1], + U = o[2], + b = o[3]; + E = u(E, O, U, b, i, 7, a[0]), b = u(b, E, O, U, c, 12, a[1]), U = + u(U, b, E, O, f, 17, a[2]), O = u(O, U, b, E, p, 22, a[3]), E = + u(E, O, U, b, g, 7, a[4]), b = u(b, E, O, U, m, 12, a[5]), U = + u(U, b, E, O, y, 17, a[6]), O = u(O, U, b, E, _, 22, a[7]), E = + u(E, O, U, b, v, 7, a[8]), b = u(b, E, O, U, w, 12, a[9]), U = + u(U, b, E, O, S, 17, a[10]), O = u(O, U, b, E, T, 22, a[11]), + E = u(E, O, U, b, k, 7, a[12]), b = u(b, E, O, U, A, 12, a[13]), + U = u(U, b, E, O, P, 17, a[14]), E = h(E, O = u(O, U, b, E, I, + 22, a[15]), U, b, c, 5, a[16]), b = h(b, E, O, U, y, 9, a[ + 17]), U = h(U, b, E, O, T, 14, a[18]), O = h(O, U, b, E, i, + 20, a[19]), E = h(E, O, U, b, m, 5, a[20]), b = h(b, E, O, + U, S, 9, a[21]), U = h(U, b, E, O, I, 14, a[22]), O = h(O, + U, b, E, g, 20, a[23]), E = h(E, O, U, b, w, 5, a[24]), b = + h(b, E, O, U, P, 9, a[25]), U = h(U, b, E, O, p, 14, a[26]), O = + h(O, U, b, E, v, 20, a[27]), E = h(E, O, U, b, A, 5, a[28]), b = + h(b, E, O, U, f, 9, a[29]), U = h(U, b, E, O, _, 14, a[30]), E = + l(E, O = h(O, U, b, E, k, 20, a[31]), U, b, m, 4, a[32]), b = l( + b, E, O, U, v, 11, a[33]), U = l(U, b, E, O, T, 16, a[34]), + O = l(O, U, b, E, P, 23, a[35]), E = l(E, O, U, b, c, 4, a[36]), + b = l(b, E, O, U, g, 11, a[37]), U = l(U, b, E, O, _, 16, a[ + 38]), O = l(O, U, b, E, S, 23, a[39]), E = l(E, O, U, b, A, + 4, + a[40]), b = l(b, E, O, U, i, 11, a[41]), U = l(U, b, E, O, + p, 16, a[42]), O = l(O, U, b, E, y, 23, a[43]), E = l(E, O, + U, b, w, 4, a[44]), b = l(b, E, O, U, k, 11, a[45]), U = l( + U, b, E, O, I, 16, a[46]), E = d(E, O = l(O, U, b, E, f, 23, + a[47]), U, b, i, 6, a[48]), b = d(b, E, O, U, _, 10, a[49]), + U = d(U, b, E, O, P, 15, a[50]), O = d(O, U, b, E, m, 21, a[ + 51]), E = d(E, O, U, b, k, 6, a[52]), b = d(b, E, O, U, p, + 10, + a[53]), U = d(U, b, E, O, S, 15, a[54]), O = d(O, U, b, E, + c, 21, a[55]), E = d(E, O, U, b, v, 6, a[56]), b = d(b, E, + O, U, I, 10, a[57]), U = d(U, b, E, O, y, 15, a[58]), O = d( + O, U, b, E, A, 21, a[59]), E = d(E, O, U, b, g, 6, a[60]), + b = d(b, E, O, U, T, 10, a[61]), U = d(U, b, E, O, f, 15, a[ + 62]), O = d(O, U, b, E, w, 21, a[63]), o[0] = o[0] + E | 0, + o[ + 1] = o[1] + O | 0, o[2] = o[2] + U | 0, o[3] = o[3] + b | 0 + }, + _doFinalize: function() { + var t = this._data, + s = t.words, + n = 8 * this._nDataBytes, + r = 8 * t.sigBytes; + s[r >>> 5] |= 128 << 24 - r % 32; + var o = e.floor(n / 4294967296), + i = n; + s[15 + (r + 64 >>> 9 << 4)] = 16711935 & (o << 8 | o >>> 24) | + 4278255360 & (o << 24 | o >>> 8), s[14 + (r + 64 >>> 9 << 4)] = + 16711935 & (i << 8 | i >>> 24) | 4278255360 & (i << 24 | i >>> + 8), t.sigBytes = 4 * (s.length + 1), this._process(); + for (var a = this._hash, c = a.words, u = 0; u < 4; u++) { + var h = c[u]; + c[u] = 16711935 & (h << 8 | h >>> 24) | 4278255360 & (h << 24 | + h >>> 8) + } + return a + }, + clone: function() { + var e = o.clone.call(this); + return e._hash = this._hash.clone(), e + } + }); + + function u(e, t, s, n, r, o, i) { + var a = e + (t & s | ~t & n) + r + i; + return (a << o | a >>> 32 - o) + t + } + + function h(e, t, s, n, r, o, i) { + var a = e + (t & n | s & ~n) + r + i; + return (a << o | a >>> 32 - o) + t + } + + function l(e, t, s, n, r, o, i) { + var a = e + (t ^ s ^ n) + r + i; + return (a << o | a >>> 32 - o) + t + } + + function d(e, t, s, n, r, o, i) { + var a = e + (s ^ (t | ~n)) + r + i; + return (a << o | a >>> 32 - o) + t + } + t.MD5 = o._createHelper(c), t.HmacMD5 = o._createHmacHelper(c) + }(Math), s.MD5) + })), s((function(e, t) { + var s, r, o; + e.exports = (r = (s = n).lib.Base, o = s.enc.Utf8, void(s.algo.HMAC = r.extend({ + init: function(e, t) { + e = this._hasher = new e.init, "string" == typeof t && (t = o.parse(t)); + var s = e.blockSize, + n = 4 * s; + t.sigBytes > n && (t = e.finalize(t)), t.clamp(); + for (var r = this._oKey = t.clone(), i = this._iKey = t.clone(), a = r + .words, c = i.words, u = 0; u < s; u++) a[u] ^= 1549556828, c[ + u] ^= 909522486; + r.sigBytes = i.sigBytes = n, this.reset() + }, + reset: function() { + var e = this._hasher; + e.reset(), e.update(this._iKey) + }, + update: function(e) { + return this._hasher.update(e), this + }, + finalize: function(e) { + var t = this._hasher, + s = t.finalize(e); + return t.reset(), t.finalize(this._oKey.clone().concat(s)) + } + }))) + })), s((function(e, t) { + e.exports = n.HmacMD5 + }))); + +function o(e) { + return function(t) { + if (!((t = t || {}).success || t.fail || t.complete)) return e.call(this, t); + e.call(this, t).then(e => { + t.success && t.success(e), t.complete && t.complete(e) + }, e => { + t.fail && t.fail(e), t.complete && t.complete(e) + }) + } +} +class i extends Error { + constructor(e) { + super(e.message), this.errMsg = e.message || "", Object.defineProperties(this, { + code: { + get: () => e.code + }, + requestId: { + get: () => e.requestId + }, + message: { + get() { + return this.errMsg + }, + set(e) { + this.errMsg = e + } + } + }) + } +} +const { + t: a, + setLocale: c, + getLocale: u +} = e("zh-Hans", { + "zh-Hans": { + "uniCloud.init.paramRequired": "缺少参数:{param}", + "uniCloud.uploadFile.fileError": "filePath应为File对象" + }, + "zh-Hant": { + "uniCloud.init.paramRequired": "缺少参数:{param}", + "uniCloud.uploadFile.fileError": "filePath应为File对象" + }, + en: { + "uniCloud.init.paramRequired": "{param} required", + "uniCloud.uploadFile.fileError": "filePath should be instance of File" + }, + fr: { + "uniCloud.init.paramRequired": "{param} required", + "uniCloud.uploadFile.fileError": "filePath should be instance of File" + }, + es: { + "uniCloud.init.paramRequired": "{param} required", + "uniCloud.uploadFile.fileError": "filePath should be instance of File" + } +}); +let h, l, d; +try { + h = require("uni-stat-config").default || require("uni-stat-config") +} catch (e) { + h = { + appid: "" + } +} + +function f(e = 8) { + let t = ""; + for (; t.length < e;) t += Math.random().toString(32).substring(2); + return t.substring(0, e) +} + +function p() { + if ("n" === g()) { + try { + l = plus.runtime.getDCloudId() + } catch (e) { + l = "" + } + return l + } + return l || (l = f(32), uni.setStorage({ + key: "__DC_CLOUD_UUID", + data: l + })), l +} + +function g() { + return { + "app-plus": "n", + h5: "h5", + "mp-weixin": "wx", + [ + ["y", "a", "p", "mp-ali"].reverse().join("") + ]: "ali", + "mp-baidu": "bd", + "mp-toutiao": "tt", + "mp-qq": "qq", + "quickapp-native": "qn" + } [process.env.VUE_APP_PLATFORM] +} +var m = { + sign: function(e, t) { + let s = ""; + return Object.keys(e).sort().forEach((function(t) { + e[t] && (s = s + "&" + t + "=" + e[t]) + })), s = s.slice(1), r(s, t).toString() + }, + wrappedRequest: function(e, t) { + return new Promise((s, n) => { + t(Object.assign(e, { + complete(e) { + e || (e = {}), "h5" === process.env.VUE_APP_PLATFORM && + "development" === process.env.NODE_ENV && e.errMsg && 0 === e.errMsg + .indexOf("request:fail") && console.warn( + "发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5" + ); + const t = e.data && e.data.header && e.data.header[ + "x-serverless-request-id"] || e.header && e.header["request-id"]; + if (!e.statusCode || e.statusCode >= 400) return n(new i({ + code: "SYS_ERR", + message: e.errMsg || "request:fail", + requestId: t + })); + const r = e.data; + if (r.error) return n(new i({ + code: r.error.code, + message: r.error.message, + requestId: t + })); + r.result = r.data, r.requestId = t, delete r.data, s(r) + } + })) + }) + } +}; +const y = { + request: e => uni.request(e), + uploadFile: e => uni.uploadFile(e), + setStorageSync: (e, t) => uni.setStorageSync(e, t), + getStorageSync: e => uni.getStorageSync(e), + removeStorageSync: e => uni.removeStorageSync(e), + clearStorageSync: () => uni.clearStorageSync() +}; +class _ { + constructor(e) { + ["spaceId", "clientSecret"].forEach(t => { + if (!Object.prototype.hasOwnProperty.call(e, t)) throw new Error(a( + "uniCloud.init.paramRequired", { + param: t + })) + }), this.config = Object.assign({}, { + endpoint: "https://api.bspapp.com" + }, e), this.config.provider = "aliyun", this.config.requestUrl = this.config.endpoint + "/client", this + .config.envType = this.config.envType || "public", this.config.accessTokenKey = "access_token_" + this + .config.spaceId, this.adapter = y + } + get hasAccessToken() { + return !!this.accessToken + } + setAccessToken(e) { + this.accessToken = e + } + requestWrapped(e) { + return m.wrappedRequest(e, this.adapter.request) + } + requestAuth(e) { + return this.requestWrapped(e) + } + request(e, t) { + return Promise.resolve().then(() => this.hasAccessToken ? t ? this.requestWrapped(e) : this.requestWrapped( + e).catch(t => new Promise((e, s) => { + !t || "GATEWAY_INVALID_TOKEN" !== t.code && "InvalidParameter.InvalidToken" !== t.code ? + s(t) : e() + }).then(() => this.getAccessToken()).then(() => { + const t = this.rebuildRequest(e); + return this.request(t, !0) + })) : this.getAccessToken().then(() => { + const t = this.rebuildRequest(e); + return this.request(t, !0) + })) + } + rebuildRequest(e) { + const t = Object.assign({}, e); + return t.data.token = this.accessToken, t.header["x-basement-token"] = this.accessToken, t.header[ + "x-serverless-sign"] = m.sign(t.data, this.config.clientSecret), t + } + setupRequest(e, t) { + const s = Object.assign({}, e, { + spaceId: this.config.spaceId, + timestamp: Date.now() + }), + n = { + "Content-Type": "application/json" + }; + return "auth" !== t && (s.token = this.accessToken, n["x-basement-token"] = this.accessToken), n[ + "x-serverless-sign"] = m.sign(s, this.config.clientSecret), { + url: this.config.requestUrl, + method: "POST", + data: s, + dataType: "json", + header: n + } + } + getAccessToken() { + return this.requestAuth(this.setupRequest({ + method: "serverless.auth.user.anonymousAuthorize", + params: "{}" + }, "auth")).then(e => new Promise((t, s) => { + e.result && e.result.accessToken ? (this.setAccessToken(e.result.accessToken), t(this + .accessToken)) : s(new i({ + code: "AUTH_FAILED", + message: "获取accessToken失败" + })) + })) + } + authorize() { + this.getAccessToken() + } + callFunction(e) { + const t = { + method: "serverless.function.runtime.invoke", + params: JSON.stringify({ + functionTarget: e.name, + functionArgs: e.data || {} + }) + }; + return this.request(this.setupRequest(t)) + } + getOSSUploadOptionsFromPath(e) { + const t = { + method: "serverless.file.resource.generateProximalSign", + params: JSON.stringify(e) + }; + return this.request(this.setupRequest(t)) + } + uploadFileToOSS({ + url: e, + formData: t, + name: s, + filePath: n, + fileType: r, + onUploadProgress: o + }) { + return new Promise((a, c) => { + const u = this.adapter.uploadFile({ + url: e, + formData: t, + name: s, + filePath: n, + fileType: r, + header: { + "X-OSS-server-side-encrpytion": "AES256" + }, + success(e) { + e && e.statusCode < 400 ? a(e) : c(new i({ + code: "UPLOAD_FAILED", + message: "文件上传失败" + })) + }, + fail(e) { + c(new i({ + code: e.code || "UPLOAD_FAILED", + message: e.message || e.errMsg || "文件上传失败" + })) + } + }); + "function" == typeof o && u && "function" == typeof u.onProgressUpdate && u.onProgressUpdate( + e => { + o({ + loaded: e.totalBytesSent, + total: e.totalBytesExpectedToSend + }) + }) + }) + } + reportOSSUpload(e) { + const t = { + method: "serverless.file.resource.report", + params: JSON.stringify(e) + }; + return this.request(this.setupRequest(t)) + } + uploadFile({ + filePath: e, + cloudPath: t, + fileType: s = "image", + onUploadProgress: n, + config: r + }) { + if (!t) throw new i({ + code: "CLOUDPATH_REQUIRED", + message: "cloudPath不可为空" + }); + const o = r && r.envType || this.config.envType; + let a, c; + return this.getOSSUploadOptionsFromPath({ + env: o, + filename: t + }).then(t => { + const r = t.result; + a = r.id, c = "https://" + r.cdnDomain + "/" + r.ossPath; + const o = { + url: "https://" + r.host, + formData: { + "Cache-Control": "max-age=2592000", + "Content-Disposition": "attachment", + OSSAccessKeyId: r.accessKeyId, + Signature: r.signature, + host: r.host, + id: a, + key: r.ossPath, + policy: r.policy, + success_action_status: 200 + }, + fileName: "file", + name: "file", + filePath: e, + fileType: s + }; + return this.uploadFileToOSS(Object.assign({}, o, { + onUploadProgress: n + })) + }).then(() => this.reportOSSUpload({ + id: a + })).then(t => new Promise((s, n) => { + t.success ? s({ + success: !0, + filePath: e, + fileID: c + }) : n(new i({ + code: "UPLOAD_FAILED", + message: "文件上传失败" + })) + })) + } + deleteFile({ + fileList: e + }) { + const t = { + method: "serverless.file.resource.delete", + params: JSON.stringify({ + id: e[0] + }) + }; + return this.request(this.setupRequest(t)) + } + getTempFileURL({ + fileList: e + } = {}) { + return new Promise((t, s) => { + Array.isArray(e) && 0 !== e.length || s(new i({ + code: "INVALID_PARAM", + message: "fileList的元素必须是非空的字符串" + })), t({ + fileList: e.map(e => ({ + fileID: e, + tempFileURL: e + })) + }) + }) + } +} +const v = { + init(e) { + const t = new _(e); + ["deleteFile", "getTempFileURL"].forEach(e => { + t[e] = o(t[e]).bind(t) + }); + const s = { + signInAnonymously: function() { + return t.authorize() + }, + getLoginState: function() { + return Promise.resolve(!1) + } + }; + return t.auth = function() { + return s + }, t.customAuth = t.auth, t + } + }, + w = "undefined" != typeof location && "http:" === location.protocol ? "http:" : "https:", + S = "undefined" != typeof process && "e2e" === process.env.NODE_ENV && "pre" === process.env.END_POINT ? + "//tcb-pre.tencentcloudapi.com/web" : "//tcb-api.tencentcloudapi.com/web"; +var T; +! function(e) { + e.local = "local", e.none = "none", e.session = "session" +}(T || (T = {})); +var k = function() {}; +s((function(e, t) { + var s; + e.exports = (s = n, function(e) { + var t = s, + n = t.lib, + r = n.WordArray, + o = n.Hasher, + i = t.algo, + a = [], + c = []; + ! function() { + function t(t) { + for (var s = e.sqrt(t), n = 2; n <= s; n++) + if (!(t % n)) return !1; + return !0 + } + + function s(e) { + return 4294967296 * (e - (0 | e)) | 0 + } + for (var n = 2, r = 0; r < 64;) t(n) && (r < 8 && (a[r] = s(e.pow(n, .5))), c[r] = s(e + .pow(n, 1 / 3)), r++), n++ + }(); + var u = [], + h = i.SHA256 = o.extend({ + _doReset: function() { + this._hash = new r.init(a.slice(0)) + }, + _doProcessBlock: function(e, t) { + for (var s = this._hash.words, n = s[0], r = s[1], o = s[2], i = s[3], + a = s[4], h = s[5], l = s[6], d = s[7], f = 0; f < 64; f++) { + if (f < 16) u[f] = 0 | e[t + f]; + else { + var p = u[f - 15], + g = (p << 25 | p >>> 7) ^ (p << 14 | p >>> 18) ^ p >>> 3, + m = u[f - 2], + y = (m << 15 | m >>> 17) ^ (m << 13 | m >>> 19) ^ m >>> 10; + u[f] = g + u[f - 7] + y + u[f - 16] + } + var _ = n & r ^ n & o ^ r & o, + v = (n << 30 | n >>> 2) ^ (n << 19 | n >>> 13) ^ (n << 10 | + n >>> 22), + w = d + ((a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | + a >>> 25)) + (a & h ^ ~a & l) + c[f] + u[f]; + d = l, l = h, h = a, a = i + w | 0, i = o, o = r, r = n, n = w + ( + v + _) | 0 + } + s[0] = s[0] + n | 0, s[1] = s[1] + r | 0, s[2] = s[2] + o | 0, s[3] = s[ + 3] + i | 0, s[4] = s[4] + a | 0, s[5] = s[5] + h | 0, s[6] = s[ + 6] + l | 0, s[7] = s[7] + d | 0 + }, + _doFinalize: function() { + var t = this._data, + s = t.words, + n = 8 * this._nDataBytes, + r = 8 * t.sigBytes; + return s[r >>> 5] |= 128 << 24 - r % 32, s[14 + (r + 64 >>> 9 << 4)] = e + .floor(n / 4294967296), s[15 + (r + 64 >>> 9 << 4)] = n, t + .sigBytes = 4 * s.length, this._process(), this._hash + }, + clone: function() { + var e = o.clone.call(this); + return e._hash = this._hash.clone(), e + } + }); + t.SHA256 = o._createHelper(h), t.HmacSHA256 = o._createHmacHelper(h) + }(Math), s.SHA256) +})), s((function(e, t) { + e.exports = n.HmacSHA256 +})), s((function(e, t) { + var s, r, o; + e.exports = (r = (s = o = n).lib.WordArray, s.enc.Base64 = { + stringify: function(e) { + var t = e.words, + s = e.sigBytes, + n = this._map; + e.clamp(); + for (var r = [], o = 0; o < s; o += 3) + for (var i = (t[o >>> 2] >>> 24 - o % 4 * 8 & 255) << 16 | (t[o + 1 >>> 2] >>> + 24 - (o + 1) % 4 * 8 & 255) << 8 | t[o + 2 >>> 2] >>> 24 - (o + 2) % + 4 * 8 & 255, a = 0; a < 4 && o + .75 * a < s; a++) r.push(n.charAt(i >>> + 6 * (3 - a) & 63)); + var c = n.charAt(64); + if (c) + for (; r.length % 4;) r.push(c); + return r.join("") + }, + parse: function(e) { + var t = e.length, + s = this._map, + n = this._reverseMap; + if (!n) { + n = this._reverseMap = []; + for (var o = 0; o < s.length; o++) n[s.charCodeAt(o)] = o + } + var i = s.charAt(64); + if (i) { + var a = e.indexOf(i); - 1 !== a && (t = a) + } + return function(e, t, s) { + for (var n = [], o = 0, i = 0; i < t; i++) + if (i % 4) { + var a = s[e.charCodeAt(i - 1)] << i % 4 * 2, + c = s[e.charCodeAt(i)] >>> 6 - i % 4 * 2; + n[o >>> 2] |= (a | c) << 24 - o % 4 * 8, o++ + } return r.create(n, o) + }(e, t, n) + }, + _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" + }, o.enc.Base64) +})), s((function(e, t) { + e.exports = n.enc.Utf8 +})); +const A = () => { + let e; + if (!Promise) { + e = () => {}, e.promise = {}; + const t = () => { + throw new Error( + 'Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.' + ) + }; + return Object.defineProperty(e.promise, "then", { + get: t + }), Object.defineProperty(e.promise, "catch", { + get: t + }), e + } + const t = new Promise((t, s) => { + e = (e, n) => e ? s(e) : t(n) + }); + return e.promise = t, e +}; + +function P(e) { + return void 0 === e +} + +function I(e) { + return "[object Null]" === Object.prototype.toString.call(e) +} +var E; + +function O(e) { + const t = (s = e, "[object Array]" === Object.prototype.toString.call(s) ? e : [e]); + var s; + for (const e of t) { + const { + isMatch: t, + genAdapter: s, + runtime: n + } = e; + if (t()) return { + adapter: s(), + runtime: n + } + } +}! function(e) { + e.WEB = "web", e.WX_MP = "wx_mp" +}(E || (E = {})); +const U = { + adapter: null, + runtime: void 0 + }, + b = ["anonymousUuidKey"]; +class D extends k { + constructor() { + super(), U.adapter.root.tcbObject || (U.adapter.root.tcbObject = {}) + } + setItem(e, t) { + U.adapter.root.tcbObject[e] = t + } + getItem(e) { + return U.adapter.root.tcbObject[e] + } + removeItem(e) { + delete U.adapter.root.tcbObject[e] + } + clear() { + delete U.adapter.root.tcbObject + } +} + +function C(e, t) { + switch (e) { + case "local": + return t.localStorage || new D; + case "none": + return new D; + default: + return t.sessionStorage || new D + } +} +class R { + constructor(e) { + if (!this._storage) { + this._persistence = U.adapter.primaryStorage || e.persistence, this._storage = C(this._persistence, U + .adapter); + const t = "access_token_" + e.env, + s = "access_token_expire_" + e.env, + n = "refresh_token_" + e.env, + r = "anonymous_uuid_" + e.env, + o = "login_type_" + e.env, + i = "user_info_" + e.env; + this.keys = { + accessTokenKey: t, + accessTokenExpireKey: s, + refreshTokenKey: n, + anonymousUuidKey: r, + loginTypeKey: o, + userInfoKey: i + } + } + } + updatePersistence(e) { + if (e === this._persistence) return; + const t = "local" === this._persistence; + this._persistence = e; + const s = C(e, U.adapter); + for (const e in this.keys) { + const n = this.keys[e]; + if (t && b.includes(e)) continue; + const r = this._storage.getItem(n); + P(r) || I(r) || (s.setItem(n, r), this._storage.removeItem(n)) + } + this._storage = s + } + setStore(e, t, s) { + if (!this._storage) return; + const n = { + version: s || "localCachev1", + content: t + }, + r = JSON.stringify(n); + try { + this._storage.setItem(e, r) + } catch (e) { + throw e + } + } + getStore(e, t) { + try { + if (!this._storage) return + } catch (e) { + return "" + } + t = t || "localCachev1"; + const s = this._storage.getItem(e); + if (!s) return ""; + if (s.indexOf(t) >= 0) { + return JSON.parse(s).content + } + return "" + } + removeStore(e) { + this._storage.removeItem(e) + } +} +const x = {}, + q = {}; + +function F(e) { + return x[e] +} +class L { + constructor(e, t) { + this.data = t || null, this.name = e + } +} +class N extends L { + constructor(e, t) { + super("error", { + error: e, + data: t + }), this.error = e + } +} +const M = new class { + constructor() { + this._listeners = {} + } + on(e, t) { + return function(e, t, s) { + s[e] = s[e] || [], s[e].push(t) + }(e, t, this._listeners), this + } + off(e, t) { + return function(e, t, s) { + if (s && s[e]) { + const n = s[e].indexOf(t); - 1 !== n && s[e].splice(n, 1) + } + }(e, t, this._listeners), this + } + fire(e, t) { + if (e instanceof N) return console.error(e.error), this; + const s = "string" == typeof e ? new L(e, t || {}) : e; + const n = s.name; + if (this._listens(n)) { + s.target = this; + const e = this._listeners[n] ? [...this._listeners[n]] : []; + for (const t of e) t.call(this, s) + } + return this + } + _listens(e) { + return this._listeners[e] && this._listeners[e].length > 0 + } +}; + +function $(e, t) { + M.on(e, t) +} + +function K(e, t = {}) { + M.fire(e, t) +} + +function B(e, t) { + M.off(e, t) +} +const j = "loginStateChanged", + H = "loginStateExpire", + W = "loginTypeChanged", + V = "anonymousConverted", + z = "refreshAccessToken"; +var Y; +! function(e) { + e.ANONYMOUS = "ANONYMOUS", e.WECHAT = "WECHAT", e.WECHAT_PUBLIC = "WECHAT-PUBLIC", e.WECHAT_OPEN = "WECHAT-OPEN", e + .CUSTOM = "CUSTOM", e.EMAIL = "EMAIL", e.USERNAME = "USERNAME", e.NULL = "NULL" +}(Y || (Y = {})); +const J = ["auth.getJwt", "auth.logout", "auth.signInWithTicket", "auth.signInAnonymously", "auth.signIn", + "auth.fetchAccessTokenWithRefreshToken", "auth.signUpWithEmailAndPassword", "auth.activateEndUserMail", + "auth.sendPasswordResetEmail", "auth.resetPasswordWithToken", "auth.isUsernameRegistered" + ], + X = { + "X-SDK-Version": "1.3.5" + }; + +function G(e, t, s) { + const n = e[t]; + e[t] = function(t) { + const r = {}, + o = {}; + s.forEach(s => { + const { + data: n, + headers: i + } = s.call(e, t); + Object.assign(r, n), Object.assign(o, i) + }); + const i = t.data; + return i && (() => { + var e; + if (e = i, "[object FormData]" !== Object.prototype.toString.call(e)) t.data = { + ...i, + ...r + }; + else + for (const e in r) i.append(e, r[e]) + })(), t.headers = { + ...t.headers || {}, + ...o + }, n.call(e, t) + } +} + +function Q() { + const e = Math.random().toString(16).slice(2); + return { + data: { + seqId: e + }, + headers: { + ...X, + "x-seqid": e + } + } +} +class Z { + constructor(e = {}) { + var t; + this.config = e, this._reqClass = new U.adapter.reqClass({ + timeout: this.config.timeout, + timeoutMsg: `请求在${this.config.timeout/1e3}s内未完成,已中断`, + restrictedMethods: ["post"] + }), this._cache = F(this.config.env), this._localCache = (t = this.config.env, q[t]), G(this._reqClass, + "post", [Q]), G(this._reqClass, "upload", [Q]), G(this._reqClass, "download", [Q]) + } + async post(e) { + return await this._reqClass.post(e) + } + async upload(e) { + return await this._reqClass.upload(e) + } + async download(e) { + return await this._reqClass.download(e) + } + async refreshAccessToken() { + let e, t; + this._refreshAccessTokenPromise || (this._refreshAccessTokenPromise = this._refreshAccessToken()); + try { + e = await this._refreshAccessTokenPromise + } catch (e) { + t = e + } + if (this._refreshAccessTokenPromise = null, this._shouldRefreshAccessTokenHook = null, t) throw t; + return e + } + async _refreshAccessToken() { + const { + accessTokenKey: e, + accessTokenExpireKey: t, + refreshTokenKey: s, + loginTypeKey: n, + anonymousUuidKey: r + } = this._cache.keys; + this._cache.removeStore(e), this._cache.removeStore(t); + let o = this._cache.getStore(s); + if (!o) throw new Error("未登录CloudBase"); + const i = { + refresh_token: o + }, + a = await this.request("auth.fetchAccessTokenWithRefreshToken", i); + if (a.data.code) { + const { + code: e + } = a.data; + if ("SIGN_PARAM_INVALID" === e || "REFRESH_TOKEN_EXPIRED" === e || "INVALID_REFRESH_TOKEN" === e) { + if (this._cache.getStore(n) === Y.ANONYMOUS && "INVALID_REFRESH_TOKEN" === e) { + const e = this._cache.getStore(r), + t = this._cache.getStore(s), + n = await this.send("auth.signInAnonymously", { + anonymous_uuid: e, + refresh_token: t + }); + return this.setRefreshToken(n.refresh_token), this._refreshAccessToken() + } + K(H), this._cache.removeStore(s) + } + throw new Error("刷新access token失败:" + a.data.code) + } + if (a.data.access_token) return K(z), this._cache.setStore(e, a.data.access_token), this._cache.setStore(t, + a.data.access_token_expire + Date.now()), { + accessToken: a.data.access_token, + accessTokenExpire: a.data.access_token_expire + }; + a.data.refresh_token && (this._cache.removeStore(s), this._cache.setStore(s, a.data.refresh_token), this + ._refreshAccessToken()) + } + async getAccessToken() { + const { + accessTokenKey: e, + accessTokenExpireKey: t, + refreshTokenKey: s + } = this._cache.keys; + if (!this._cache.getStore(s)) throw new Error("refresh token不存在,登录状态异常"); + let n = this._cache.getStore(e), + r = this._cache.getStore(t), + o = !0; + return this._shouldRefreshAccessTokenHook && !await this._shouldRefreshAccessTokenHook(n, r) && (o = !1), (! + n || !r || r < Date.now()) && o ? this.refreshAccessToken() : { + accessToken: n, + accessTokenExpire: r + } + } + async request(e, t, s) { + const n = "x-tcb-trace_" + this.config.env; + let r = "application/x-www-form-urlencoded"; + const o = { + action: e, + env: this.config.env, + dataVersion: "2019-08-16", + ...t + }; + if (-1 === J.indexOf(e)) { + const { + refreshTokenKey: e + } = this._cache.keys; + this._cache.getStore(e) && (o.access_token = (await this.getAccessToken()).accessToken) + } + let i; + if ("storage.uploadFile" === e) { + i = new FormData; + for (let e in i) i.hasOwnProperty(e) && void 0 !== i[e] && i.append(e, o[e]); + r = "multipart/form-data" + } else { + r = "application/json;charset=UTF-8", i = {}; + for (let e in o) void 0 !== o[e] && (i[e] = o[e]) + } + let a = { + headers: { + "content-type": r + } + }; + s && s.onUploadProgress && (a.onUploadProgress = s.onUploadProgress); + const c = this._localCache.getStore(n); + c && (a.headers["X-TCB-Trace"] = c); + const { + parse: u, + inQuery: h, + search: l + } = t; + let d = { + env: this.config.env + }; + u && (d.parse = !0), h && (d = { + ...h, + ...d + }); + let f = function(e, t, s = {}) { + const n = /\?/.test(t); + let r = ""; + for (let e in s) "" === r ? !n && (t += "?") : r += "&", r += `${e}=${encodeURIComponent(s[e])}`; + return /^http(s)?\:\/\//.test(t += r) ? t : `${e}${t}` + }(w, S, d); + l && (f += l); + const p = await this.post({ + url: f, + data: i, + ...a + }), + g = p.header && p.header["x-tcb-trace"]; + if (g && this._localCache.setStore(n, g), 200 !== Number(p.status) && 200 !== Number(p.statusCode) || !p + .data) throw new Error("network request error"); + return p + } + async send(e, t = {}) { + const s = await this.request(e, t, { + onUploadProgress: t.onUploadProgress + }); + if ("ACCESS_TOKEN_EXPIRED" === s.data.code && -1 === J.indexOf(e)) { + await this.refreshAccessToken(); + const s = await this.request(e, t, { + onUploadProgress: t.onUploadProgress + }); + if (s.data.code) throw new Error(`[${s.data.code}] ${s.data.message}`); + return s.data + } + if (s.data.code) throw new Error(`[${s.data.code}] ${s.data.message}`); + return s.data + } + setRefreshToken(e) { + const { + accessTokenKey: t, + accessTokenExpireKey: s, + refreshTokenKey: n + } = this._cache.keys; + this._cache.removeStore(t), this._cache.removeStore(s), this._cache.setStore(n, e) + } +} +const ee = {}; + +function te(e) { + return ee[e] +} +class se { + constructor(e) { + this.config = e, this._cache = F(e.env), this._request = te(e.env) + } + setRefreshToken(e) { + const { + accessTokenKey: t, + accessTokenExpireKey: s, + refreshTokenKey: n + } = this._cache.keys; + this._cache.removeStore(t), this._cache.removeStore(s), this._cache.setStore(n, e) + } + setAccessToken(e, t) { + const { + accessTokenKey: s, + accessTokenExpireKey: n + } = this._cache.keys; + this._cache.setStore(s, e), this._cache.setStore(n, t) + } + async refreshUserInfo() { + const { + data: e + } = await this._request.send("auth.getUserInfo", {}); + return this.setLocalUserInfo(e), e + } + setLocalUserInfo(e) { + const { + userInfoKey: t + } = this._cache.keys; + this._cache.setStore(t, e) + } +} +class ne { + constructor(e) { + if (!e) throw new Error("envId is not defined"); + this._envId = e, this._cache = F(this._envId), this._request = te(this._envId), this.setUserInfo() + } + linkWithTicket(e) { + if ("string" != typeof e) throw new Error("ticket must be string"); + return this._request.send("auth.linkWithTicket", { + ticket: e + }) + } + linkWithRedirect(e) { + e.signInWithRedirect() + } + updatePassword(e, t) { + return this._request.send("auth.updatePassword", { + oldPassword: t, + newPassword: e + }) + } + updateEmail(e) { + return this._request.send("auth.updateEmail", { + newEmail: e + }) + } + updateUsername(e) { + if ("string" != typeof e) throw new Error("username must be a string"); + return this._request.send("auth.updateUsername", { + username: e + }) + } + async getLinkedUidList() { + const { + data: e + } = await this._request.send("auth.getLinkedUidList", {}); + let t = !1; + const { + users: s + } = e; + return s.forEach(e => { + e.wxOpenId && e.wxPublicId && (t = !0) + }), { + users: s, + hasPrimaryUid: t + } + } + setPrimaryUid(e) { + return this._request.send("auth.setPrimaryUid", { + uid: e + }) + } + unlink(e) { + return this._request.send("auth.unlink", { + platform: e + }) + } + async update(e) { + const { + nickName: t, + gender: s, + avatarUrl: n, + province: r, + country: o, + city: i + } = e, { + data: a + } = await this._request.send("auth.updateUserInfo", { + nickName: t, + gender: s, + avatarUrl: n, + province: r, + country: o, + city: i + }); + this.setLocalUserInfo(a) + } + async refresh() { + const { + data: e + } = await this._request.send("auth.getUserInfo", {}); + return this.setLocalUserInfo(e), e + } + setUserInfo() { + const { + userInfoKey: e + } = this._cache.keys, t = this._cache.getStore(e); + ["uid", "loginType", "openid", "wxOpenId", "wxPublicId", "unionId", "qqMiniOpenId", "email", "hasPassword", + "customUserId", "nickName", "gender", "avatarUrl" + ].forEach(e => { + this[e] = t[e] + }), this.location = { + country: t.country, + province: t.province, + city: t.city + } + } + setLocalUserInfo(e) { + const { + userInfoKey: t + } = this._cache.keys; + this._cache.setStore(t, e), this.setUserInfo() + } +} +class re { + constructor(e) { + if (!e) throw new Error("envId is not defined"); + this._cache = F(e); + const { + refreshTokenKey: t, + accessTokenKey: s, + accessTokenExpireKey: n + } = this._cache.keys, r = this._cache.getStore(t), o = this._cache.getStore(s), i = this._cache.getStore(n); + this.credential = { + refreshToken: r, + accessToken: o, + accessTokenExpire: i + }, this.user = new ne(e) + } + get isAnonymousAuth() { + return this.loginType === Y.ANONYMOUS + } + get isCustomAuth() { + return this.loginType === Y.CUSTOM + } + get isWeixinAuth() { + return this.loginType === Y.WECHAT || this.loginType === Y.WECHAT_OPEN || this.loginType === Y.WECHAT_PUBLIC + } + get loginType() { + return this._cache.getStore(this._cache.keys.loginTypeKey) + } +} +class oe extends se { + async signIn() { + this._cache.updatePersistence("local"); + const { + anonymousUuidKey: e, + refreshTokenKey: t + } = this._cache.keys, s = this._cache.getStore(e) || void 0, n = this._cache.getStore(t) || void 0, r = + await this._request.send("auth.signInAnonymously", { + anonymous_uuid: s, + refresh_token: n + }); + if (r.uuid && r.refresh_token) { + this._setAnonymousUUID(r.uuid), this.setRefreshToken(r.refresh_token), await this._request + .refreshAccessToken(), K(j), K(W, { + env: this.config.env, + loginType: Y.ANONYMOUS, + persistence: "local" + }); + const e = new re(this.config.env); + return await e.user.refresh(), e + } + throw new Error("匿名登录失败") + } + async linkAndRetrieveDataWithTicket(e) { + const { + anonymousUuidKey: t, + refreshTokenKey: s + } = this._cache.keys, n = this._cache.getStore(t), r = this._cache.getStore(s), o = await this._request + .send("auth.linkAndRetrieveDataWithTicket", { + anonymous_uuid: n, + refresh_token: r, + ticket: e + }); + if (o.refresh_token) return this._clearAnonymousUUID(), this.setRefreshToken(o.refresh_token), await this + ._request.refreshAccessToken(), K(V, { + env: this.config.env + }), K(W, { + loginType: Y.CUSTOM, + persistence: "local" + }), { + credential: { + refreshToken: o.refresh_token + } + }; + throw new Error("匿名转化失败") + } + _setAnonymousUUID(e) { + const { + anonymousUuidKey: t, + loginTypeKey: s + } = this._cache.keys; + this._cache.removeStore(t), this._cache.setStore(t, e), this._cache.setStore(s, Y.ANONYMOUS) + } + _clearAnonymousUUID() { + this._cache.removeStore(this._cache.keys.anonymousUuidKey) + } +} +class ie extends se { + async signIn(e) { + if ("string" != typeof e) throw new Error("ticket must be a string"); + const { + refreshTokenKey: t + } = this._cache.keys, s = await this._request.send("auth.signInWithTicket", { + ticket: e, + refresh_token: this._cache.getStore(t) || "" + }); + if (s.refresh_token) return this.setRefreshToken(s.refresh_token), await this._request.refreshAccessToken(), + K(j), K(W, { + env: this.config.env, + loginType: Y.CUSTOM, + persistence: this.config.persistence + }), await this.refreshUserInfo(), new re(this.config.env); + throw new Error("自定义登录失败") + } +} +class ae extends se { + async signIn(e, t) { + if ("string" != typeof e) throw new Error("email must be a string"); + const { + refreshTokenKey: s + } = this._cache.keys, n = await this._request.send("auth.signIn", { + loginType: "EMAIL", + email: e, + password: t, + refresh_token: this._cache.getStore(s) || "" + }), { + refresh_token: r, + access_token: o, + access_token_expire: i + } = n; + if (r) return this.setRefreshToken(r), o && i ? this.setAccessToken(o, i) : await this._request + .refreshAccessToken(), await this.refreshUserInfo(), K(j), K(W, { + env: this.config.env, + loginType: Y.EMAIL, + persistence: this.config.persistence + }), new re(this.config.env); + throw n.code ? new Error(`邮箱登录失败: [${n.code}] ${n.message}`) : new Error("邮箱登录失败") + } + async activate(e) { + return this._request.send("auth.activateEndUserMail", { + token: e + }) + } + async resetPasswordWithToken(e, t) { + return this._request.send("auth.resetPasswordWithToken", { + token: e, + newPassword: t + }) + } +} +class ce extends se { + async signIn(e, t) { + if ("string" != typeof e) throw new Error("username must be a string"); + "string" != typeof t && (t = "", console.warn("password is empty")); + const { + refreshTokenKey: s + } = this._cache.keys, n = await this._request.send("auth.signIn", { + loginType: Y.USERNAME, + username: e, + password: t, + refresh_token: this._cache.getStore(s) || "" + }), { + refresh_token: r, + access_token_expire: o, + access_token: i + } = n; + if (r) return this.setRefreshToken(r), i && o ? this.setAccessToken(i, o) : await this._request + .refreshAccessToken(), await this.refreshUserInfo(), K(j), K(W, { + env: this.config.env, + loginType: Y.USERNAME, + persistence: this.config.persistence + }), new re(this.config.env); + throw n.code ? new Error(`用户名密码登录失败: [${n.code}] ${n.message}`) : new Error("用户名密码登录失败") + } +} +class ue { + constructor(e) { + this.config = e, this._cache = F(e.env), this._request = te(e.env), this._onAnonymousConverted = this + ._onAnonymousConverted.bind(this), this._onLoginTypeChanged = this._onLoginTypeChanged.bind(this), $(W, + this._onLoginTypeChanged) + } + get currentUser() { + const e = this.hasLoginState(); + return e && e.user || null + } + get loginType() { + return this._cache.getStore(this._cache.keys.loginTypeKey) + } + anonymousAuthProvider() { + return new oe(this.config) + } + customAuthProvider() { + return new ie(this.config) + } + emailAuthProvider() { + return new ae(this.config) + } + usernameAuthProvider() { + return new ce(this.config) + } + async signInAnonymously() { + return new oe(this.config).signIn() + } + async signInWithEmailAndPassword(e, t) { + return new ae(this.config).signIn(e, t) + } + signInWithUsernameAndPassword(e, t) { + return new ce(this.config).signIn(e, t) + } + async linkAndRetrieveDataWithTicket(e) { + this._anonymousAuthProvider || (this._anonymousAuthProvider = new oe(this.config)), $(V, this + ._onAnonymousConverted); + return await this._anonymousAuthProvider.linkAndRetrieveDataWithTicket(e) + } + async signOut() { + if (this.loginType === Y.ANONYMOUS) throw new Error("匿名用户不支持登出操作"); + const { + refreshTokenKey: e, + accessTokenKey: t, + accessTokenExpireKey: s + } = this._cache.keys, n = this._cache.getStore(e); + if (!n) return; + const r = await this._request.send("auth.logout", { + refresh_token: n + }); + return this._cache.removeStore(e), this._cache.removeStore(t), this._cache.removeStore(s), K(j), K(W, { + env: this.config.env, + loginType: Y.NULL, + persistence: this.config.persistence + }), r + } + async signUpWithEmailAndPassword(e, t) { + return this._request.send("auth.signUpWithEmailAndPassword", { + email: e, + password: t + }) + } + async sendPasswordResetEmail(e) { + return this._request.send("auth.sendPasswordResetEmail", { + email: e + }) + } + onLoginStateChanged(e) { + $(j, () => { + const t = this.hasLoginState(); + e.call(this, t) + }); + const t = this.hasLoginState(); + e.call(this, t) + } + onLoginStateExpired(e) { + $(H, e.bind(this)) + } + onAccessTokenRefreshed(e) { + $(z, e.bind(this)) + } + onAnonymousConverted(e) { + $(V, e.bind(this)) + } + onLoginTypeChanged(e) { + $(W, () => { + const t = this.hasLoginState(); + e.call(this, t) + }) + } + async getAccessToken() { + return { + accessToken: (await this._request.getAccessToken()).accessToken, + env: this.config.env + } + } + hasLoginState() { + const { + refreshTokenKey: e + } = this._cache.keys; + return this._cache.getStore(e) ? new re(this.config.env) : null + } + async isUsernameRegistered(e) { + if ("string" != typeof e) throw new Error("username must be a string"); + const { + data: t + } = await this._request.send("auth.isUsernameRegistered", { + username: e + }); + return t && t.isRegistered + } + getLoginState() { + return Promise.resolve(this.hasLoginState()) + } + async signInWithTicket(e) { + return new ie(this.config).signIn(e) + } + shouldRefreshAccessToken(e) { + this._request._shouldRefreshAccessTokenHook = e.bind(this) + } + getUserInfo() { + return this._request.send("auth.getUserInfo", {}).then(e => e.code ? e : { + ...e.data, + requestId: e.seqId + }) + } + getAuthHeader() { + const { + refreshTokenKey: e, + accessTokenKey: t + } = this._cache.keys, s = this._cache.getStore(e); + return { + "x-cloudbase-credentials": this._cache.getStore(t) + "/@@/" + s + } + } + _onAnonymousConverted(e) { + const { + env: t + } = e.data; + t === this.config.env && this._cache.updatePersistence(this.config.persistence) + } + _onLoginTypeChanged(e) { + const { + loginType: t, + persistence: s, + env: n + } = e.data; + n === this.config.env && (this._cache.updatePersistence(s), this._cache.setStore(this._cache.keys + .loginTypeKey, t)) + } +} +const he = function(e, t) { + t = t || A(); + const s = te(this.config.env), + { + cloudPath: n, + filePath: r, + onUploadProgress: o, + fileType: i = "image" + } = e; + return s.send("storage.getUploadMetadata", { + path: n + }).then(e => { + const { + data: { + url: a, + authorization: c, + token: u, + fileId: h, + cosFileId: l + }, + requestId: d + } = e, f = { + key: n, + signature: c, + "x-cos-meta-fileid": l, + success_action_status: "201", + "x-cos-security-token": u + }; + s.upload({ + url: a, + data: f, + file: r, + name: n, + fileType: i, + onUploadProgress: o + }).then(e => { + 201 === e.statusCode ? t(null, { + fileID: h, + requestId: d + }) : t(new Error("STORAGE_REQUEST_FAIL: " + e.data)) + }).catch(e => { + t(e) + }) + }).catch(e => { + t(e) + }), t.promise + }, + le = function(e, t) { + t = t || A(); + const s = te(this.config.env), + { + cloudPath: n + } = e; + return s.send("storage.getUploadMetadata", { + path: n + }).then(e => { + t(null, e) + }).catch(e => { + t(e) + }), t.promise + }, + de = function({ + fileList: e + }, t) { + if (t = t || A(), !e || !Array.isArray(e)) return { + code: "INVALID_PARAM", + message: "fileList必须是非空的数组" + }; + for (let t of e) + if (!t || "string" != typeof t) return { + code: "INVALID_PARAM", + message: "fileList的元素必须是非空的字符串" + }; + const s = { + fileid_list: e + }; + return te(this.config.env).send("storage.batchDeleteFile", s).then(e => { + e.code ? t(null, e) : t(null, { + fileList: e.data.delete_list, + requestId: e.requestId + }) + }).catch(e => { + t(e) + }), t.promise + }, + fe = function({ + fileList: e + }, t) { + t = t || A(), e && Array.isArray(e) || t(null, { + code: "INVALID_PARAM", + message: "fileList必须是非空的数组" + }); + let s = []; + for (let n of e) "object" == typeof n ? (n.hasOwnProperty("fileID") && n.hasOwnProperty("maxAge") || t(null, { + code: "INVALID_PARAM", + message: "fileList的元素必须是包含fileID和maxAge的对象" + }), s.push({ + fileid: n.fileID, + max_age: n.maxAge + })) : "string" == typeof n ? s.push({ + fileid: n + }) : t(null, { + code: "INVALID_PARAM", + message: "fileList的元素必须是字符串" + }); + const n = { + file_list: s + }; + return te(this.config.env).send("storage.batchGetDownloadUrl", n).then(e => { + e.code ? t(null, e) : t(null, { + fileList: e.data.download_list, + requestId: e.requestId + }) + }).catch(e => { + t(e) + }), t.promise + }, + pe = async function({ + fileID: e + }, t) { + const s = (await fe.call(this, { + fileList: [{ + fileID: e, + maxAge: 600 + }] + })).fileList[0]; + if ("SUCCESS" !== s.code) return t ? t(s) : new Promise(e => { + e(s) + }); + const n = te(this.config.env); + let r = s.download_url; + if (r = encodeURI(r), !t) return n.download({ + url: r + }); + t(await n.download({ + url: r + })) + }, ge = function({ + name: e, + data: t, + query: s, + parse: n, + search: r + }, o) { + const i = o || A(); + let a; + try { + a = t ? JSON.stringify(t) : "" + } catch (e) { + return Promise.reject(e) + } + if (!e) return Promise.reject(new Error("函数名不能为空")); + const c = { + inQuery: s, + parse: n, + search: r, + function_name: e, + request_data: a + }; + return te(this.config.env).send("functions.invokeFunction", c).then(e => { + if (e.code) i(null, e); + else { + let t = e.data.response_data; + if (n) i(null, { + result: t, + requestId: e.requestId + }); + else try { + t = JSON.parse(e.data.response_data), i(null, { + result: t, + requestId: e.requestId + }) + } catch (e) { + i(new Error("response data must be json")) + } + } + return i.promise + }).catch(e => { + i(e) + }), i.promise + }, me = { + timeout: 15e3, + persistence: "session" + }, ye = {}; +class _e { + constructor(e) { + this.config = e || this.config, this.authObj = void 0 + } + init(e) { + switch (U.adapter || (this.requestClient = new U.adapter.reqClass({ + timeout: e.timeout || 5e3, + timeoutMsg: `请求在${(e.timeout||5e3)/1e3}s内未完成,已中断` + })), this.config = { + ...me, + ...e + }, !0) { + case this.config.timeout > 6e5: + console.warn("timeout大于可配置上限[10分钟],已重置为上限数值"), this.config.timeout = 6e5; + break; + case this.config.timeout < 100: + console.warn("timeout小于可配置下限[100ms],已重置为下限数值"), this.config.timeout = 100 + } + return new _e(this.config) + } + auth({ + persistence: e + } = {}) { + if (this.authObj) return this.authObj; + const t = e || U.adapter.primaryStorage || me.persistence; + var s; + return t !== this.config.persistence && (this.config.persistence = t), + function(e) { + const { + env: t + } = e; + x[t] = new R(e), q[t] = new R({ + ...e, + persistence: "local" + }) + }(this.config), s = this.config, ee[s.env] = new Z(s), this.authObj = new ue(this.config), this.authObj + } + on(e, t) { + return $.apply(this, [e, t]) + } + off(e, t) { + return B.apply(this, [e, t]) + } + callFunction(e, t) { + return ge.apply(this, [e, t]) + } + deleteFile(e, t) { + return de.apply(this, [e, t]) + } + getTempFileURL(e, t) { + return fe.apply(this, [e, t]) + } + downloadFile(e, t) { + return pe.apply(this, [e, t]) + } + uploadFile(e, t) { + return he.apply(this, [e, t]) + } + getUploadMetadata(e, t) { + return le.apply(this, [e, t]) + } + registerExtension(e) { + ye[e.name] = e + } + async invokeExtension(e, t) { + const s = ye[e]; + if (!s) throw Error(`扩展${e} 必须先注册`); + return await s.invoke(t, this) + } + useAdapters(e) { + const { + adapter: t, + runtime: s + } = O(e) || {}; + t && (U.adapter = t), s && (U.runtime = s) + } +} +const ve = new _e; + +function we(e, t, s) { + void 0 === s && (s = {}); + var n = /\?/.test(t), + r = ""; + for (var o in s) "" === r ? !n && (t += "?") : r += "&", r += o + "=" + encodeURIComponent(s[o]); + return /^http(s)?:\/\//.test(t += r) ? t : "" + e + t +} +class Se { + post(e) { + const { + url: t, + data: s, + headers: n + } = e; + return new Promise((e, r) => { + y.request({ + url: we("https:", t), + data: s, + method: "POST", + header: n, + success(t) { + e(t) + }, + fail(e) { + r(e) + } + }) + }) + } + upload(e) { + return new Promise((t, s) => { + const { + url: n, + file: r, + data: o, + headers: i, + fileType: a + } = e, c = y.uploadFile({ + url: we("https:", n), + name: "file", + formData: Object.assign({}, o), + filePath: r, + fileType: a, + header: i, + success(e) { + const s = { + statusCode: e.statusCode, + data: e.data || {} + }; + 200 === e.statusCode && o.success_action_status && (s.statusCode = parseInt(o + .success_action_status, 10)), t(s) + }, + fail(e) { + "mp-alipay" === process.env.VUE_APP_PLATFORM && "development" === process.env + .NODE_ENV && console.warn("支付宝小程序开发工具上传腾讯云时无法准确判断是否上传成功,请使用真机测试"), s( + new Error(e.errMsg || "uploadFile:fail")) + } + }); + "function" == typeof e.onUploadProgress && c && "function" == typeof c.onProgressUpdate && c + .onProgressUpdate(t => { + e.onUploadProgress({ + loaded: t.totalBytesSent, + total: t.totalBytesExpectedToSend + }) + }) + }) + } +} +const Te = { + setItem(e, t) { + y.setStorageSync(e, t) + }, + getItem: e => y.getStorageSync(e), + removeItem(e) { + y.removeStorageSync(e) + }, + clear() { + y.clearStorageSync() + } +}; +const ke = { + genAdapter: function() { + return { + root: {}, + reqClass: Se, + localStorage: Te, + primaryStorage: "local" + } + }, + isMatch: function() { + return !0 + }, + runtime: "uni_app" +}; +ve.useAdapters(ke); +const Ae = ve, + Pe = Ae.init; +Ae.init = function(e) { + e.env = e.spaceId; + const t = Pe.call(this, e); + t.config.provider = "tencent", t.config.spaceId = e.spaceId; + const s = t.auth; + t.auth = function(e) { + const t = s.call(this, e); + return ["linkAndRetrieveDataWithTicket", "signInAnonymously", "signOut", "getAccessToken", + "getLoginState", "signInWithTicket", "getUserInfo" + ].forEach(e => { + t[e] = o(t[e]).bind(t) + }), t + }, t.customAuth = t.auth; + return ["deleteFile", "getTempFileURL", "downloadFile"].forEach(e => { + t[e] = o(t[e]).bind(t) + }), t +}; +class Ie extends _ { + getAccessToken() { + return new Promise((e, t) => { + this.setAccessToken("Anonymous_Access_token"), e("Anonymous_Access_token") + }) + } + uploadFileToOSS({ + url: e, + formData: t, + name: s, + filePath: n, + fileType: r, + onUploadProgress: o + }) { + return new Promise((a, c) => { + const u = this.adapter.uploadFile({ + url: e, + formData: t, + name: s, + filePath: n, + fileType: r, + success(e) { + e && e.statusCode < 400 ? a(e) : c(new i({ + code: "UPLOAD_FAILED", + message: "文件上传失败" + })) + }, + fail(e) { + c(new i({ + code: e.code || "UPLOAD_FAILED", + message: e.message || e.errMsg || "文件上传失败" + })) + } + }); + "function" == typeof o && u && "function" == typeof u.onProgressUpdate && u.onProgressUpdate( + e => { + o({ + loaded: e.totalBytesSent, + total: e.totalBytesExpectedToSend + }) + }) + }) + } + uploadFile({ + filePath: e, + cloudPath: t, + fileType: s = "image", + onUploadProgress: n + }) { + if (!t) throw new i({ + code: "CLOUDPATH_REQUIRED", + message: "cloudPath不可为空" + }); + let r; + return this.getOSSUploadOptionsFromPath({ + filename: t + }).then(t => { + const { + url: o, + formData: i, + name: a, + fileUrl: c + } = t.result; + r = c; + const u = { + url: o, + formData: i, + name: a, + filePath: e, + fileType: s + }; + return this.uploadFileToOSS(Object.assign({}, u, { + onUploadProgress: n + })) + }).then(() => this.reportOSSUpload({ + id: t + })).then(t => new Promise((s, n) => { + t.success ? s({ + success: !0, + filePath: e, + fileID: r + }) : n(new i({ + code: "UPLOAD_FAILED", + message: "文件上传失败" + })) + })) + } +} +const Ee = { + init(e) { + const t = new Ie(e); + ["deleteFile", "getTempFileURL"].forEach(e => { + t[e] = o(t[e]).bind(t) + }); + const s = { + signInAnonymously: function() { + return t.authorize() + }, + getLoginState: function() { + return Promise.resolve(!1) + } + }; + return t.auth = function() { + return s + }, t.customAuth = t.auth, t + } +}; +let Oe, Ue; + +function be({ + name: e, + data: t, + spaceId: s, + provider: n +}) { + Oe || (Oe = function() { + const { + deviceId: e + } = uni.getSystemInfoSync(); + return { + PLATFORM: process.env.VUE_APP_PLATFORM, + OS: d, + APPID: h.appid, + LOCALE: u(), + DEVICEID: e, + CLIENT_SDK_VERSION: "1.0.1" + } + }(), Ue = { + ak: h.appid, + p: "android" === d ? "a" : "i", + ut: g(), + uuid: p() + }); + const r = JSON.parse(JSON.stringify(t || {})), + o = e, + i = s, + a = { + tencent: "t", + aliyun: "a" + } [n]; { + const e = Object.assign({}, Ue, { + fn: o, + sid: i, + pvd: a + }); + Object.assign(r, { + clientInfo: Oe, + uniCloudClientInfo: encodeURIComponent(JSON.stringify(e)) + }); + const { + deviceId: t + } = uni.getSystemInfoSync(); + r.uniCloudDeviceId = t + } + if (!r.uniIdToken) { + const e = y.getStorageSync("uni_id_token") || y.getStorageSync("uniIdToken"); + e && (r.uniIdToken = e) + } + return r +} + +function De({ + name: e, + data: t +}) { + const { + localAddress: s, + localPort: n + } = this, r = { + aliyun: "aliyun", + tencent: "tcb" + } [this.config.provider], o = this.config.spaceId, a = `http://${s}:${n}/system/check-function`, c = + `http://${s}:${n}/cloudfunctions/${e}`; + return new Promise((t, s) => { + y.request({ + method: "POST", + url: a, + data: { + name: e, + platform: process.env.VUE_APP_PLATFORM, + provider: r, + spaceId: o + }, + timeout: 3e3, + success(e) { + t(e) + }, + fail() { + t({ + data: { + code: "NETWORK_ERROR", + message: "连接本地调试服务失败,请检查客户端是否和主机在同一局域网下,自动切换为已部署的云函数。" + } + }) + } + }) + }).then(({ + data: e + } = {}) => { + const { + code: t, + message: s + } = e || {}; + return { + code: 0 === t ? 0 : t || "SYS_ERR", + message: s || "SYS_ERR" + } + }).then(({ + code: s, + message: n + }) => { + if (0 !== s) { + switch (s) { + case "MODULE_ENCRYPTED": + console.error(`此云函数(${e})依赖加密公共模块不可本地调试,自动切换为云端已部署的云函数`); + break; + case "FUNCTION_ENCRYPTED": + console.error(`此云函数(${e})已加密不可本地调试,自动切换为云端已部署的云函数`); + break; + case "ACTION_ENCRYPTED": + console.error(n || "需要访问加密的uni-clientDB-action,自动切换为云端环境"); + break; + case "NETWORK_ERROR": { + const e = "连接本地调试服务失败,请检查客户端是否和主机在同一局域网下"; + throw console.error(e), new Error(e) + } + case "SWITCH_TO_CLOUD": + break; + default: { + const e = `检测本地调试服务出现错误:${n},请检查网络环境或重启客户端再试`; + throw console.error(e), new Error(e) + } + } + return this.originCallFunction({ + name: e, + data: t + }) + } + return new Promise((s, n) => { + const a = be({ + name: e, + data: t, + provider: this.config.provider, + spaceId: o + }); + y.request({ + method: "POST", + url: c, + data: { + provider: r, + platform: process.env.VUE_APP_PLATFORM, + param: a + }, + success: ({ + statusCode: e, + data: t + } = {}) => !e || e >= 400 ? n(new i({ + code: t.code || "SYS_ERR", + message: t.message || "request:fail" + })) : s({ + result: t + }), + fail(e) { + n(new i({ + code: e.code || e.errCode || "SYS_ERR", + message: e.message || e.errMsg || "request:fail" + })) + } + }) + }) + }) +} +const Ce = [{ + rule: /fc_function_not_found|FUNCTION_NOT_FOUND/, + content: ",云函数[{functionName}]在云端不存在,请检查此云函数名称是否正确已经是否已上传到服务空间", + mode: "append" +}]; +var Re = /[\\^$.*+?()[\]{}|]/g, + xe = RegExp(Re.source); + +function qe(e, t, s) { + return e.replace(new RegExp((n = t) && xe.test(n) ? n.replace(Re, "\\$&") : n, "g"), s); + var n +} + +function Fe(e) { + const t = e.callFunction; + e.callFunction = function(e) { + let s; + s = this.isReady ? Promise.resolve() : this.initUniCloud; + const n = e.name; + return s.then(() => { + e.data = be({ + name: n, + data: e.data, + provider: this.config.provider, + spaceId: this.config.spaceId + }); + const s = { + aliyun: "aliyun", + tencent: "tcb" + } [this.config.provider]; + return new Promise((r, o) => { + t.call(this, e).then(e => { + if (this.config.useDebugFunction && e && e.requestId) { + const t = JSON.stringify({ + spaceId: this.config.spaceId, + functionName: n, + requestId: e.requestId + }); + console.log(`[${s}-request]${t}[/${s}-request]`) + } + r(e) + }).catch(t => { + if (this.config.useDebugFunction && t && t.requestId) { + const e = JSON.stringify({ + spaceId: this.config.spaceId, + functionName: n, + requestId: t.requestId + }); + console.log(`[${s}-request]${e}[/${s}-request]`) + } + t && t.message && (t.message = function({ + message: e = "", + extraInfo: t = {}, + formatter: s = [] + } = {}) { + for (let n = 0; n < s.length; n++) { + const { + rule: r, + content: o, + mode: i + } = s[n], a = e.match(r); + if (!a) continue; + let c = o; + for (let e = 1; e < a.length; e++) c = qe(c, `{$${e}}`, + a[e]); + for (const e in t) c = qe(c, `{${e}}`, t[e]); + switch (i) { + case "replace": + return c; + case "append": + default: + return e + c + } + } + return e + }({ + message: `[${e.name}]: ${t.message}`, + formatter: Ce, + extraInfo: { + functionName: n + } + })), o(t) + }) + }) + }) + }; + const s = e.callFunction; + e.originCallFunction = e.callFunction, e.callFunction = function(t) { + return o((function(t) { + let n; + return n = e.isReady ? Promise.resolve() : e.initUniCloud, n.then(() => "development" === + process.env.NODE_ENV && e.debugInfo && !e.debugInfo.forceRemote && process.env + .UNI_CLOUD_PROVIDER ? De.call(this, t) : s.call(this, t)) + })).call(this, t) + } +} +const Le = Symbol("CLIENT_DB_INTERNAL"); + +function Ne(e, t) { + return e.then = "DoNotReturnProxyWithAFunctionNamedThen", e._internalType = Le, new Proxy(e, { + get: (e, s, n) => function(e, t) { + return Object.prototype.hasOwnProperty.call(e, t) + }(e, s) || e[s] || "string" != typeof s ? e[s] : t.get(e, s, n) + }) +} +class Me extends Error { + constructor(e, t) { + super(e), this.code = t + } +} + +function $e(e) { + switch (t = e, Object.prototype.toString.call(t).slice(8, -1).toLowerCase()) { + case "array": + return e.map(e => $e(e)); + case "object": + return e._internalType === Le || Object.keys(e).forEach(t => { + e[t] = $e(e[t]) + }), e; + case "regexp": + return { + $regexp: { + source: e.source, + flags: e.flags + } + }; + case "date": + return { + $date: e.toISOString() + }; + default: + return e + } + var t +} + +function Ke() { + const e = y.getStorageSync("uni_id_token") || "", + t = e.split("."); + if (!e || 3 !== t.length) return { + uid: null, + role: [], + permission: [] + }; + let s; + try { + s = JSON.parse((n = t[1], decodeURIComponent(atob(n).split("").map((function(e) { + return "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2) + })).join("")))) + } catch (e) { + throw new Error("获取当前用户信息出错,详细错误信息为:" + e.message) + } + var n; + return s +} +var Be = t(s((function(e, t) { + Object.defineProperty(t, "__esModule", { + value: !0 + }); + const s = "chooseAndUploadFile:fail"; + + function n(e, t) { + return e.tempFiles.forEach((e, s) => { + e.name || (e.name = e.path.substring(e.path.lastIndexOf("/") + 1)), t && (e + .fileType = t), e.cloudPath = Date.now() + "_" + s + e.name.substring(e.name + .lastIndexOf(".")) + }), e.tempFilePaths || (e.tempFilePaths = e.tempFiles.map(e => e.path)), e + } + + function r(e, t, { + onChooseFile: s, + onUploadProgress: n + }) { + return t.then(e => { + if (s) { + const t = s(e); + if (void 0 !== t) return Promise.resolve(t).then(t => void 0 === t ? e : t) + } + return e + }).then(t => !1 === t ? { + errMsg: "chooseAndUploadFile:ok", + tempFilePaths: [], + tempFiles: [] + } : function(e, t, s = 5, n) { + (t = Object.assign({}, t)).errMsg = "chooseAndUploadFile:ok"; + const r = t.tempFiles, + o = r.length; + let i = 0; + return new Promise(a => { + for (; i < s;) c(); + + function c() { + const s = i++; + if (s >= o) return void(!r.find(e => !e.url && !e.errMsg) && a(t)); + const u = r[s]; + e.uploadFile({ + filePath: u.path, + cloudPath: u.cloudPath, + fileType: u.fileType, + onUploadProgress(e) { + e.index = s, e.tempFile = u, e.tempFilePath = u + .path, n && n(e) + } + }).then(e => { + u.url = e.fileID, s < o && c() + }).catch(e => { + u.errMsg = e.errMsg || e.message, s < o && c() + }) + } + }) + }(e, t, 5, n)) + } + t.initChooseAndUploadFile = function(e) { + return function(t = { + type: "all" + }) { + return "image" === t.type ? r(e, function(e) { + const { + count: t, + sizeType: r, + sourceType: o = ["album", "camera"], + extension: i + } = e; + return new Promise((e, a) => { + uni.chooseImage({ + count: t, + sizeType: r, + sourceType: o, + extension: i, + success(t) { + e(n(t, "image")) + }, + fail(e) { + a({ + errMsg: e.errMsg.replace( + "chooseImage:fail", s) + }) + } + }) + }) + }(t), t) : "video" === t.type ? r(e, function(e) { + const { + camera: t, + compressed: r, + maxDuration: o, + sourceType: i, + extension: a + } = e; + return new Promise((e, c) => { + uni.chooseVideo({ + camera: t, + compressed: r, + maxDuration: o, + sourceType: i, + extension: a, + success(t) { + const { + tempFilePath: s, + duration: r, + size: o, + height: i, + width: a + } = t; + e(n({ + errMsg: "chooseVideo:ok", + tempFilePaths: [s], + tempFiles: [{ + name: t + .tempFile && + t.tempFile + .name || "", + path: s, + size: o, + type: t + .tempFile && + t.tempFile + .type || "", + width: a, + height: i, + duration: r, + fileType: "video", + cloudPath: "" + }] + }, "video")) + }, + fail(e) { + c({ + errMsg: e.errMsg.replace( + "chooseVideo:fail", s) + }) + } + }) + }) + }(t), t) : r(e, function(e) { + const { + count: t, + extension: r + } = e; + return new Promise((e, o) => { + let i = uni.chooseFile; + if ("undefined" != typeof wx && "function" == typeof wx + .chooseMessageFile && (i = wx.chooseMessageFile), + "function" != typeof i) return o({ + errMsg: s + + " 请指定 type 类型,该平台仅支持选择 image 或 video。" + }); + i({ + type: "all", + count: t, + extension: r, + success(t) { + e(n(t)) + }, + fail(e) { + o({ + errMsg: e.errMsg.replace( + "chooseFile:fail", s) + }) + } + }) + }) + }(t), t) + } + } +}))); +const je = "manual"; +async function He(e, t) { + const s = `http://${e}:${t}/system/ping`; + try { + const e = await (n = { + url: s, + timeout: 500 + }, new Promise((e, t) => { + y.request({ + ...n, + success(t) { + e(t) + }, + fail(e) { + t(e) + } + }) + })); + return !(!e.data || 0 !== e.data.code) + } catch (e) { + return !1 + } + var n +} +let We = new class { + init(e) { + let t = {}; + const s = !1 !== e.debugFunction && "development" === process.env.NODE_ENV && ("h5" === process.env + .VUE_APP_PLATFORM && navigator.userAgent.indexOf("HBuilderX") > 0 || "app-plus" === process.env + .VUE_APP_PLATFORM); + switch (e.provider) { + case "tencent": + t = Ae.init(Object.assign(e, { + useDebugFunction: s + })); + break; + case "aliyun": + t = v.init(Object.assign(e, { + useDebugFunction: s + })); + break; + case "private": + t = Ee.init(Object.assign(e, { + useDebugFunction: s + })); + break; + default: + throw new Error("未提供正确的provider参数") + } + const n = process.env.UNICLOUD_DEBUG; + "development" === process.env.NODE_ENV && n && !n.code && (t.debugInfo = n), t.isReady = !1; + const r = t.auth(); + return t.initUniCloud = r.getLoginState().then(e => e ? Promise.resolve() : r.signInAnonymously()).then( + () => { + if ("development" === process.env.NODE_ENV && t.debugInfo) { + const { + address: e, + servePort: s + } = t.debugInfo; + return async function(e, t) { + let s; + for (let n = 0; n < e.length; n++) { + const r = e[n]; + if (await He(r, t)) { + s = r; + break + } + } + return { + address: s, + port: t + } + }(e, s) + } + return Promise.resolve() + }).then(({ + address: e, + port: s + } = {}) => { + if (e) t.localAddress = e, t.localPort = s; + else if (t.debugInfo) { + const e = "app-plus" === process.env.VUE_APP_PLATFORM ? "error" : "warn", + s = console[e]; + "remote" === t.debugInfo.initialLaunchType ? (t.debugInfo.forceRemote = !0, s( + "当前客户端和HBuilderX不在同一局域网下(或其他网络原因无法连接HBuilderX),uniCloud本地调试服务不对当前客户端生效。\n- 如果不使用uniCloud本地调试服务,请直接忽略此信息。\n- 如需使用uniCloud本地调试服务,请将客户端与主机连接到同一局域网下并重新运行到客户端。\n- 如果在HBuilderX开启的状态下切换过网络环境,请重启HBuilderX后再试" + )) : s( + "无法连接uniCloud本地调试服务,请检查当前客户端是否与主机在同一局域网下。\n- 如需使用uniCloud本地调试服务,请将客户端与主机连接到同一局域网下并重新运行到客户端。\n- 如果在HBuilderX开启的状态下切换过网络环境,请重启HBuilderX后再试" + ) + } + }).then(() => (function() { + if ("h5" !== process.env.VUE_APP_PLATFORM || "development" !== process.env.NODE_ENV) + return; + if (uni.getStorageSync("__LAST_DCLOUD_APPID") === h.appid) return; + uni.setStorageSync("__LAST_DCLOUD_APPID", h.appid), uni.removeStorageSync( + "uni_id_token") && (console.warn( + "检测到当前项目与上次运行到此端口的项目不一致,自动清理uni-id保存的token信息(仅开发调试时生效)"), uni + .removeStorageSync("uni_id_token"), uni.removeStorageSync( + "uni_id_token_expired")) + }(), new Promise(e => { + "quickapp-native" === process.env.VUE_APP_PLATFORM ? (d = "android", uni + .getStorage({ + key: "__DC_CLOUD_UUID", + success(t) { + l = t.data ? t.data : f(32), e() + } + })) : setTimeout(() => { + d = uni.getSystemInfoSync().platform, l = uni.getStorageSync( + "__DC_CLOUD_UUID") || f(32), e() + }, 0) + }))).then(() => { + t.isReady = !0 + }), Fe(t), + function(e) { + const t = e.uploadFile; + e.uploadFile = function(e) { + let s; + return s = this.isReady ? Promise.resolve() : this.initUniCloud, s.then(() => t.call( + this, e)) + }; + const s = e.uploadFile; + e.uploadFile = function(e) { + return o(s).call(this, e) + } + }(t), + function(e) { + e.database = function() { + if (this._database) return this._database; + const t = {}, + s = {}; + class n { + constructor(e, t, s) { + this.content = e, this.prevStage = t, this.actionName = s + } + toJSON() { + let e = this; + const t = [e.content]; + for (; e.prevStage;) e = e.prevStage, t.push(e.content); + return { + $db: t.reverse().map(e => ({ + $method: e.$method, + $param: e.$param + })) + } + } + get useAggregate() { + let e = this, + t = !1; + for (; e.prevStage;) { + e = e.prevStage; + const s = e.content.$method; + if ("aggregate" === s || "pipeline" === s) { + t = !0; + break + } + } + return t + } + get count() { + if (!this.useAggregate) return function() { + return this._send("count", Array.from(arguments)) + }; + const e = this; + return function() { + return i({ + $method: "count", + $param: $e(Array.from(arguments)) + }, e, e.actionName) + } + } + get() { + return this._send("get", Array.from(arguments)) + } + add() { + return this._send("add", Array.from(arguments)) + } + remove() { + return this._send("remove", Array.from(arguments)) + } + update() { + return this._send("update", Array.from(arguments)) + } + end() { + return this._send("end", Array.from(arguments)) + } + set() { + throw new Error("clientDB禁止使用set方法") + } + _send(n, r) { + const o = this.toJSON(); + return o.$db.push({ + $method: n, + $param: r + }), e.callFunction({ + name: "DCloud-clientDB", + data: { + action: this.actionName, + command: o + } + }).then(e => { + const { + code: n, + message: r, + token: o, + tokenExpired: i, + systemInfo: a = [] + } = e.result; + if (a) + for (let e = 0; e < a.length; e++) { + const { + level: t, + message: s, + detail: n + } = a[e], r = "app-plus" === process.env + .VUE_APP_PLATFORM && "warn" === t ? "error" : t, o = + console[r] || console.log; + let i = "[System Info]" + s; + n && (i = `${i}\n详细信息:${n}`), o(i) + } + return n ? Promise.reject(new Me(r, n)) : (o && i && t + .refreshToken && t.refreshToken.forEach(e => { + e({ + token: o, + tokenExpired: i + }) + }), o && i && s.refreshToken && s.refreshToken.forEach( + e => { + e({ + token: o, + tokenExpired: i + }) + }), Promise.resolve(e)) + }).catch(e => { + const t = new Me(e.message, e.code || "SYSTEM_ERROR"); + return s.error && s.error.forEach(e => { + e(t) + }), /fc_function_not_found|FUNCTION_NOT_FOUND/g.test(e + .message) && console.warn( + "clientDB未初始化,请在web控制台保存一次schema以开启clientDB"), Promise + .reject(e) + }) + } + } + const r = ["db.Geo", "db.command", "command.aggregate"]; + + function o(e, t) { + return r.indexOf(`${e}.${t}`) > -1 + } + + function i(e, t, s) { + return Ne(new n(e, t, s), { + get(e, t) { + let n = "db"; + return e && e.content && (n = e.content.$method), o(n, t) ? i({ + $method: t + }, e, s) : function() { + return i({ + $method: t, + $param: $e(Array.from(arguments)) + }, e, s) + } + } + }) + } + + function a({ + path: e, + method: t + }) { + return class { + constructor() { + this.param = Array.from(arguments) + } + toJSON() { + return { + $newDb: [...e.map(e => ({ + $method: e + })), { + $method: t, + $param: this.param + }] + } + } + } + } + const c = { + auth: { + on: (e, s) => { + t[e] = t[e] || [], t[e].indexOf(s) > -1 || t[e].push(s) + }, + off: (e, s) => { + t[e] = t[e] || []; + const n = t[e].indexOf(s); - 1 !== n && t[e].splice(n, 1) + } + }, + on: (e, t) => { + s[e] = s[e] || [], s[e].indexOf(t) > -1 || s[e].push(t) + }, + off: (e, t) => { + s[e] = s[e] || []; + const n = s[e].indexOf(t); - 1 !== n && s[e].splice(n, 1) + }, + env: Ne({}, { + get: (e, t) => ({ + $env: t + }) + }), + action: e => Ne({}, { + get: (t, s) => o("db", s) ? i({ + $method: s + }, null, e) : function() { + return i({ + $method: s, + $param: $e(Array.from(arguments)) + }, null, e) + } + }), + Geo: Ne({}, { + get: (e, t) => a({ + path: ["Geo"], + method: t + }) + }), + getCloudEnv: function(e) { + if ("string" != typeof e || !e.trim()) throw new Error( + "getCloudEnv参数错误"); + return { + $env: e.replace("$cloudEnv_", "") + } + }, + get serverDate() { + return a({ + path: [], + method: "serverDate" + }) + }, + get RegExp() { + return a({ + path: [], + method: "RegExp" + }) + } + }, + u = Ne(c, { + get: (e, t) => o("db", t) ? i({ + $method: t + }) : function() { + return i({ + $method: t, + $param: $e(Array.from(arguments)) + }) + } + }); + return this._database = u, u + } + }(t), + function(e) { + e.getCurrentUserInfo = Ke, e.chooseAndUploadFile = o(Be.initChooseAndUploadFile(e)) + }(t), t.init = this.init, t + } +}; +(() => { + { + let e = {}; + if (1 === process.env.UNI_CLOUD_PROVIDER.length) e = process.env.UNI_CLOUD_PROVIDER[0], We = We.init(e); + else { + const e = ["auth", "callFunction", "uploadFile", "deleteFile", "getTempFileURL", "downloadFile", + "database", "getCurrentUSerInfo" + ], + t = process.env.UNI_CLOUD_PROVIDER.length > 0 ? "应用有多个服务空间,请通过uniCloud.init方法指定要使用的服务空间" : + "应用未关联服务空间,请在cloudfunctions目录右键关联服务空间"; + e.forEach(e => { + We[e] = function() { + return console.error(t), Promise.reject(new i({ + code: "SYS_ERR", + message: t + })) + } + }) + } + Object.assign(We, { + get mixinDatacom() { + return e = We, { + props: { + localdata: { + type: Array, + default: () => [] + }, + options: { + type: [Object, Array], + default: () => ({}) + }, + collection: { + type: String, + default: "" + }, + action: { + type: String, + default: "" + }, + field: { + type: String, + default: "" + }, + orderby: { + type: String, + default: "" + }, + where: { + type: [String, Object], + default: "" + }, + pageData: { + type: String, + default: "add" + }, + pageCurrent: { + type: Number, + default: 1 + }, + pageSize: { + type: Number, + default: 20 + }, + getcount: { + type: [Boolean, String], + default: !1 + }, + gettree: { + type: [Boolean, String], + default: !1 + }, + gettreepath: { + type: [Boolean, String], + default: !1 + }, + startwith: { + type: String, + default: "" + }, + limitlevel: { + type: Number, + default: 10 + }, + groupby: { + type: String, + default: "" + }, + groupField: { + type: String, + default: "" + }, + distinct: { + type: [Boolean, String], + default: !1 + }, + foreignKey: { + type: String, + default: "" + }, + loadtime: { + type: String, + default: "auto" + }, + manual: { + type: Boolean, + default: !1 + } + }, + data: () => ({ + mixinDatacomLoading: !1, + mixinDatacomHasMore: !1, + mixinDatacomResData: [], + mixinDatacomErrorMessage: "", + mixinDatacomPage: {} + }), + created() { + this.mixinDatacomPage = { + current: this.pageCurrent, + size: this.pageSize, + count: 0 + }, this.$watch(() => { + var e = []; + return ["pageCurrent", "pageSize", "localdata", "collection", + "action", "field", "orderby", "where", "getont", + "getcount", "gettree", "groupby", "groupField", + "distinct" + ].forEach(t => { + e.push(this[t]) + }), e + }, (e, t) => { + if (this.loadtime === je) return; + let s = !1; + const n = []; + for (let r = 2; r < e.length; r++) e[r] !== t[r] && (n.push(e[ + r]), s = !0); + e[0] !== t[0] && (this.mixinDatacomPage.current = this + .pageCurrent), this.mixinDatacomPage.size = this + .pageSize, this.onMixinDatacomPropsChange(s, n) + }) + }, + methods: { + onMixinDatacomPropsChange(e, t) {}, + mixinDatacomEasyGet({ + getone: e = !1, + success: t, + fail: s + } = {}) { + this.mixinDatacomLoading || (this.mixinDatacomLoading = !0, this + .mixinDatacomErrorMessage = "", this.mixinDatacomGet().then( + s => { + this.mixinDatacomLoading = !1; + const { + data: n, + count: r + } = s.result; + this.getcount && (this.mixinDatacomPage.count = r), this + .mixinDatacomHasMore = n.length < this.pageSize; + const o = e ? n.length ? n[0] : void 0 : n; + this.mixinDatacomResData = o, t && t(o) + }).catch(e => { + this.mixinDatacomLoading = !1, this + .mixinDatacomErrorMessage = e, s && s(e) + })) + }, + mixinDatacomGet(t = {}) { + let s = e.database(); + const n = t.action || this.action; + n && (s = s.action(n)); + const r = t.collection || this.collection; + s = s.collection(r); + const o = t.where || this.where; + o && Object.keys(o).length && (s = s.where(o)); + const i = t.field || this.field; + i && (s = s.field(i)); + const a = t.foreignKey || this.foreignKey; + a && (s = s.foreignKey(a)); + const c = t.groupby || this.groupby; + c && (s = s.groupBy(c)); + const u = t.groupField || this.groupField; + u && (s = s.groupField(u)), !0 === (void 0 !== t.distinct ? t.distinct : + this.distinct) && (s = s.distinct()); + const h = t.orderby || this.orderby; + h && (s = s.orderBy(h)); + const l = void 0 !== t.pageCurrent ? t.pageCurrent : this + .mixinDatacomPage.current, + d = void 0 !== t.pageSize ? t.pageSize : this.mixinDatacomPage.size, + f = void 0 !== t.getcount ? t.getcount : this.getcount, + p = void 0 !== t.gettree ? t.gettree : this.gettree, + g = void 0 !== t.gettreepath ? t.gettreepath : this.gettreepath, + m = { + getCount: f + }, + y = { + limitLevel: void 0 !== t.limitlevel ? t.limitlevel : this + .limitlevel, + startWith: void 0 !== t.startwith ? t.startwith : this.startwith + }; + return p && (m.getTree = y), g && (m.getTreePath = y), s = s.skip(d * ( + l - 1)).limit(d).get(m), s + } + } + }; + var e + } + }) + } +})(); +var Ve = We; +export default Ve; diff --git a/packages/uni-cloud/lib/uni.config.js b/packages/uni-cloud/lib/uni.config.js new file mode 100644 index 000000000..ff8261fed --- /dev/null +++ b/packages/uni-cloud/lib/uni.config.js @@ -0,0 +1,81 @@ +const { once } = require('@dcloudio/uni-shared') + +module.exports = { + init, + define, + inject, + done: once(done), +} + +function init() { + process.UNI_CLOUD = false + process.UNI_CLOUD_TCB = false + process.UNI_CLOUD_ALIYUN = false + process.env.UNI_CLOUD_PROVIDER = JSON.stringify([]) + + if (!process.env.UNI_CLOUD_SPACES) { + return + } + try { + const spaces = JSON.parse(process.env.UNI_CLOUD_SPACES) + if (Array.isArray(spaces)) { + process.UNI_CLOUD = spaces.length > 0 + process.UNI_CLOUD_TCB = !!spaces.find((space) => !space.clientSecret) + process.UNI_CLOUD_ALIYUN = !!spaces.find((space) => space.clientSecret) + if (spaces.length === 1) { + const space = spaces[0] + console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`) + } + process.env.UNI_CLOUD_PROVIDER = JSON.stringify( + spaces.map((space) => { + if (space.clientSecret) { + return { + provider: 'aliyun', + spaceName: space.name, + spaceId: space.id, + clientSecret: space.clientSecret, + endpoint: space.apiEndpoint, + } + } else { + return { + provider: 'tencent', + spaceName: space.name, + spaceId: space.id, + } + } + }) + ) + } + } catch (e) {} + if ( + process.UNI_CLOUD && + !process.env.UNI_SUB_PLATFORM && + process.env.UNI_PLATFORM === 'h5' && + process.env.NODE_ENV === 'production' + ) { + console.warn( + '发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5' + ) + } +} + +function define() { + return { + 'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER, + 'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG, + } +} + +function inject() { + return { + uniCloud: ['@dcloudio/uni-cloud', 'default'], + } +} + +function done() { + if (process.UNI_CLOUD) { + console.warn( + '当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5' + ) + } +} diff --git a/packages/uni-cloud/package.json b/packages/uni-cloud/package.json new file mode 100644 index 000000000..4b00f4793 --- /dev/null +++ b/packages/uni-cloud/package.json @@ -0,0 +1,23 @@ +{ + "name": "@dcloudio/uni-cloud", + "version": "3.0.0", + "description": "@dcloudio/uni-cloud", + "main": "dist/uni-cloud.esm.js", + "module": "dist/uni-cloud.esm.js", + "files": [ + "dist" + ], + "sideEffects": false, + "repository": { + "type": "git", + "url": "git+https://github.com/dcloudio/uni-app.git", + "directory": "packages/uni-cloud" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/dcloudio/uni-app/issues" + }, + "uni-app": { + "name": "uniCloud" + } +} diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index d4aede06b..d2dc6d4b8 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -1,6 +1,7 @@ -import {isFunction, extend, hyphenate, isPlainObject, isString, isArray, hasOwn as hasOwn$1, isObject as isObject$1, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1} from "@vue/shared"; +import {isFunction, extend, hyphenate, isPlainObject, isString, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1} from "@vue/shared"; import {injectHook, withModifiers, createVNode, getCurrentInstance, inject, provide, reactive, computed, nextTick, onBeforeMount, onMounted, onBeforeActivate, onBeforeDeactivate, openBlock, createBlock, mergeProps, toDisplayString, ref, defineComponent, resolveComponent, toHandlers, renderSlot, watch, onUnmounted, onBeforeUnmount, onActivated, withDirectives, vShow, createTextVNode, createCommentVNode, renderList, onDeactivated, Fragment, Teleport, createApp, watchEffect, Transition, withCtx, KeepAlive, resolveDynamicComponent} from "vue"; import {once, passive, normalizeTarget, isBuiltInComponent, invokeArrayFns, NAVBAR_HEIGHT, parseQuery, PRIMARY_COLOR, removeLeadingSlash, getLen, ON_REACH_BOTTOM_DISTANCE, decodedQuery, debounce, updateElementStyle, addFont, scrollTo} from "@dcloudio/uni-shared"; +import {initVueI18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT} from "@dcloudio/uni-i18n"; import {useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView} from "vue-router"; function applyOptions(options, instance2, publicThis) { Object.keys(options).forEach((name) => { @@ -15,238 +16,6 @@ function applyOptions(options, instance2, publicThis) { function set(target, key, val) { return target[key] = val; } -const isObject = (val) => val !== null && typeof val === "object"; -class BaseFormatter { - constructor() { - this._caches = Object.create(null); - } - interpolate(message, values) { - if (!values) { - return [message]; - } - let tokens = this._caches[message]; - if (!tokens) { - tokens = parse(message); - this._caches[message] = tokens; - } - return compile(tokens, values); - } -} -const RE_TOKEN_LIST_VALUE = /^(?:\d)+/; -const RE_TOKEN_NAMED_VALUE = /^(?:\w)+/; -function parse(format) { - const tokens = []; - let position = 0; - let text2 = ""; - while (position < format.length) { - let char = format[position++]; - if (char === "{") { - if (text2) { - tokens.push({type: "text", value: text2}); - } - text2 = ""; - let sub = ""; - char = format[position++]; - while (char !== void 0 && char !== "}") { - sub += char; - char = format[position++]; - } - const isClosed = char === "}"; - const type = RE_TOKEN_LIST_VALUE.test(sub) ? "list" : isClosed && RE_TOKEN_NAMED_VALUE.test(sub) ? "named" : "unknown"; - tokens.push({value: sub, type}); - } else if (char === "%") { - if (format[position] !== "{") { - text2 += char; - } - } else { - text2 += char; - } - } - text2 && tokens.push({type: "text", value: text2}); - return tokens; -} -function compile(tokens, values) { - const compiled = []; - let index2 = 0; - const mode = Array.isArray(values) ? "list" : isObject(values) ? "named" : "unknown"; - if (mode === "unknown") { - return compiled; - } - while (index2 < tokens.length) { - const token = tokens[index2]; - switch (token.type) { - case "text": - compiled.push(token.value); - break; - case "list": - compiled.push(values[parseInt(token.value, 10)]); - break; - case "named": - if (mode === "named") { - compiled.push(values[token.value]); - } - break; - } - index2++; - } - return compiled; -} -const LOCALE_ZH_HANS = "zh-Hans"; -const LOCALE_ZH_HANT = "zh-Hant"; -const LOCALE_EN = "en"; -const LOCALE_FR = "fr"; -const LOCALE_ES = "es"; -const hasOwnProperty = Object.prototype.hasOwnProperty; -const hasOwn = (val, key) => hasOwnProperty.call(val, key); -const defaultFormatter = new BaseFormatter(); -function include(str, parts) { - return !!parts.find((part) => str.indexOf(part) !== -1); -} -function startsWith(str, parts) { - return parts.find((part) => str.indexOf(part) === 0); -} -function normalizeLocale(locale, messages) { - if (!locale) { - return; - } - locale = locale.trim().replace(/_/g, "-"); - if (messages[locale]) { - return locale; - } - locale = locale.toLowerCase(); - if (locale.indexOf("zh") === 0) { - if (locale.indexOf("-hans") !== -1) { - return LOCALE_ZH_HANS; - } - if (locale.indexOf("-hant") !== -1) { - return LOCALE_ZH_HANT; - } - if (include(locale, ["-tw", "-hk", "-mo", "-cht"])) { - return LOCALE_ZH_HANT; - } - return LOCALE_ZH_HANS; - } - const lang = startsWith(locale, [LOCALE_EN, LOCALE_FR, LOCALE_ES]); - if (lang) { - return lang; - } -} -class I18n { - constructor({locale, fallbackLocale, messages, watcher, formater}) { - this.locale = LOCALE_EN; - this.fallbackLocale = LOCALE_EN; - this.message = {}; - this.messages = {}; - this.watchers = []; - if (fallbackLocale) { - this.fallbackLocale = fallbackLocale; - } - this.formater = formater || defaultFormatter; - this.messages = messages || {}; - this.setLocale(locale); - if (watcher) { - this.watchLocale(watcher); - } - } - setLocale(locale) { - const oldLocale = this.locale; - this.locale = normalizeLocale(locale, this.messages) || this.fallbackLocale; - if (!this.messages[this.locale]) { - this.messages[this.locale] = {}; - } - this.message = this.messages[this.locale]; - this.watchers.forEach((watcher) => { - watcher(this.locale, oldLocale); - }); - } - getLocale() { - return this.locale; - } - watchLocale(fn) { - const index2 = this.watchers.push(fn) - 1; - return () => { - this.watchers.splice(index2, 1); - }; - } - add(locale, message) { - if (this.messages[locale]) { - Object.assign(this.messages[locale], message); - } else { - this.messages[locale] = message; - } - } - t(key, locale, values) { - let message = this.message; - if (typeof locale === "string") { - locale = normalizeLocale(locale, this.messages); - locale && (message = this.messages[locale]); - } else { - values = locale; - } - if (!hasOwn(message, key)) { - console.warn(`Cannot translate the value of keypath ${key}. Use the value of keypath as default.`); - return key; - } - return this.formater.interpolate(message[key], values).join(""); - } -} -function initLocaleWatcher(appVm2, i18n2) { - appVm2.$i18n && appVm2.$i18n.vm.$watch("locale", (newLocale) => { - i18n2.setLocale(newLocale); - }, { - immediate: true - }); -} -function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_EN) { - const i18n2 = new I18n({ - locale: locale || fallbackLocale, - fallbackLocale, - messages - }); - let t2 = (key, values) => { - if (typeof getApp !== "function") { - t2 = function(key2, values2) { - return i18n2.t(key2, values2); - }; - } else { - const appVm2 = getApp().$vm; - if (!appVm2.$t || !appVm2.$i18n) { - t2 = function(key2, values2) { - return i18n2.t(key2, values2); - }; - } else { - initLocaleWatcher(appVm2, i18n2); - t2 = function(key2, values2) { - const $i18n = appVm2.$i18n; - const silentTranslationWarn = $i18n.silentTranslationWarn; - $i18n.silentTranslationWarn = true; - const msg = appVm2.$t(key2, values2); - $i18n.silentTranslationWarn = silentTranslationWarn; - if (msg !== key2) { - return msg; - } - return i18n2.t(key2, $i18n.locale, values2); - }; - } - } - return t2(key, values); - }; - return { - i18n: i18n2, - t(key, values) { - return t2(key, values); - }, - add(locale2, message) { - return i18n2.add(locale2, message); - }, - getLocale() { - return i18n2.getLocale(); - }, - setLocale(newLocale) { - return i18n2.setLocale(newLocale); - } - }; -} let i18n$1; function useI18n() { if (!i18n$1) { @@ -678,7 +447,7 @@ var safeAreaInsets = { onChange, offChange }; -var D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out = safeAreaInsets; +var out = safeAreaInsets; const onEventPrevent = /* @__PURE__ */ withModifiers(() => { }, ["prevent"]); const onEventStop = /* @__PURE__ */ withModifiers(() => { @@ -690,10 +459,10 @@ function getWindowOffset() { const left = parseInt(style2.getPropertyValue("--window-left")); const right = parseInt(style2.getPropertyValue("--window-right")); return { - top: top ? top + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top : 0, - bottom: bottom ? bottom + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom : 0, - left: left ? left + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left : 0, - right: right ? right + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right : 0 + top: top ? top + out.top : 0, + bottom: bottom ? bottom + out.bottom : 0, + left: left ? left + out.left : 0, + right: right ? right + out.right : 0 }; } const style = document.documentElement.style; @@ -1344,7 +1113,7 @@ function normalizePageMeta(pageMeta) { let offset = rpx2px(refreshOptions.offset); const {type} = navigationBar; if (type !== "transparent" && type !== "none") { - offset += NAVBAR_HEIGHT + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top; + offset += NAVBAR_HEIGHT + out.top; } refreshOptions.offset = offset; refreshOptions.height = rpx2px(refreshOptions.height); @@ -1468,7 +1237,7 @@ function validateProtocolFail(name, msg) { } function validateProtocol(name, data, protocol) { for (const key in protocol) { - const errMsg = validateProp(key, data[key], protocol[key], !hasOwn$1(data, key)); + const errMsg = validateProp(key, data[key], protocol[key], !hasOwn(data, key)); if (isString(errMsg)) { validateProtocolFail(name, errMsg); } @@ -1531,7 +1300,7 @@ function assertType(value, type) { valid = value instanceof type; } } else if (expectedType === "Object") { - valid = isObject$1(value); + valid = isObject(value); } else if (expectedType === "Array") { valid = isArray(value); } else { @@ -1726,7 +1495,7 @@ function formatApiArgs(args, options) { return errMsg; } } else { - if (!hasOwn$1(params, name)) { + if (!hasOwn(params, name)) { params[name] = formatterOrDefaultValue; } } @@ -2420,7 +2189,7 @@ function stringifyQuery(url, data) { params[part[0]] = part[1]; }); for (const key in data) { - if (hasOwn$1(data, key)) { + if (hasOwn(data, key)) { let v2 = data[key]; if (typeof v2 === "undefined" || v2 === null) { v2 = ""; @@ -2807,14 +2576,14 @@ const ShowModalOptions = { content: "", showCancel: true, cancelText(_value, params) { - if (!hasOwn$1(params, "cancelText")) { + if (!hasOwn(params, "cancelText")) { const {t: t2} = useI18n(); params.cancelText = t2("uni.showModal.cancel"); } }, cancelColor: "#000", confirmText(_value, params) { - if (!hasOwn$1(params, "confirmText")) { + if (!hasOwn(params, "confirmText")) { const {t: t2} = useI18n(); params.confirmText = t2("uni.showModal.confirm"); } @@ -3536,7 +3305,7 @@ const SCHEMA_CSS = { "css.backdrop-filter": cssBackdropFilter }; const canIUse = defineSyncApi(API_CAN_I_USE, (schema) => { - if (hasOwn$1(SCHEMA_CSS, schema)) { + if (hasOwn(SCHEMA_CSS, schema)) { return SCHEMA_CSS[schema]; } return true; @@ -8527,7 +8296,7 @@ const CHARS = { }; function decodeEntities(htmlString) { return htmlString.replace(/&(([a-zA-Z]+)|(#x{0,1}[\da-zA-Z]+));/gi, function(match, stage) { - if (hasOwn$1(CHARS, stage) && CHARS[stage]) { + if (hasOwn(CHARS, stage) && CHARS[stage]) { return CHARS[stage]; } if (/^#[0-9]{1,4}$/.test(stage)) { @@ -8546,12 +8315,12 @@ function parseNodes(nodes, parentNode) { if (!isPlainObject(node)) { return; } - if (!hasOwn$1(node, "type") || node.type === "node") { + if (!hasOwn(node, "type") || node.type === "node") { if (!(typeof node.name === "string" && node.name)) { return; } const tagName = node.name.toLowerCase(); - if (!hasOwn$1(TAGS, tagName)) { + if (!hasOwn(TAGS, tagName)) { return; } const elem = document.createElement(tagName); @@ -11450,7 +11219,7 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { const windowWidth = getWindowWidth(screenWidth); let windowHeight = window.innerHeight; const language = navigator.language; - const statusBarHeight = D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top; + const statusBarHeight = out.top; let osname; let osversion; let model; @@ -11563,12 +11332,12 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { const system = `${osname} ${osversion}`; const platform = osname.toLocaleLowerCase(); const safeArea = { - left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left, - right: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, - top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top, - bottom: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom, - width: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, - height: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom + left: out.left, + right: windowWidth - out.right, + top: out.top, + bottom: windowHeight - out.bottom, + width: windowWidth - out.left - out.right, + height: windowHeight - out.top - out.bottom }; const {top: windowTop, bottom: windowBottom} = getWindowOffset(); windowHeight -= windowTop; @@ -11588,10 +11357,10 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { model, safeArea, safeAreaInsets: { - top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top, - right: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, - bottom: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom, - left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left + top: out.top, + right: out.right, + bottom: out.bottom, + left: out.left } }; }); @@ -11925,7 +11694,7 @@ function blobToFile(blob, type) { } function fileToUrl(file) { for (const key in files) { - if (hasOwn$1(files, key)) { + if (hasOwn(files, key)) { const oldFile = files[key]; if (oldFile === file) { return key; @@ -12271,7 +12040,7 @@ const request = defineTaskApi(API_REQUEST, ({ } else if (contentType === "urlencoded") { const bodyArray = []; for (const key in data) { - if (hasOwn$1(data, key)) { + if (hasOwn(data, key)) { bodyArray.push(encodeURIComponent(key) + "=" + encodeURIComponent(data[key])); } } @@ -12285,7 +12054,7 @@ const request = defineTaskApi(API_REQUEST, ({ const requestTask = new RequestTask(xhr); xhr.open(method, url); for (const key in header) { - if (hasOwn$1(header, key)) { + if (hasOwn(header, key)) { xhr.setRequestHeader(key, header[key]); } } @@ -13307,7 +13076,7 @@ const setTabBarStyleProps = [ const setTabBarBadgeProps = ["badge", "redDot"]; function setProperties(item, props2, propsData) { props2.forEach(function(name) { - if (hasOwn$1(propsData, name)) { + if (hasOwn(propsData, name)) { item[name] = propsData[name]; } }); diff --git a/packages/uni-h5/vite.config.ts b/packages/uni-h5/vite.config.ts index d4e1a0068..11f4216d0 100644 --- a/packages/uni-h5/vite.config.ts +++ b/packages/uni-h5/vite.config.ts @@ -66,9 +66,13 @@ export default defineConfig({ input: path.resolve(__dirname, 'src/index.ts'), external(source) { if ( - ['vue', 'vue-router', '@vue/shared', '@dcloudio/uni-shared'].includes( - source - ) + [ + 'vue', + 'vue-router', + '@vue/shared', + '@dcloudio/uni-i18n', + '@dcloudio/uni-shared', + ].includes(source) ) { return true } diff --git a/packages/vite-plugin-uni/src/config/index.ts b/packages/vite-plugin-uni/src/config/index.ts index 16ca8c689..4ab0a9409 100644 --- a/packages/vite-plugin-uni/src/config/index.ts +++ b/packages/vite-plugin-uni/src/config/index.ts @@ -1,4 +1,5 @@ import path from 'path' +import { extend } from '@vue/shared' import { Plugin, UserConfig } from 'vite' import { normalizePath } from '@dcloudio/uni-cli-shared' @@ -26,9 +27,10 @@ export function createConfig( options.command = env.command options.platform = (process.env.UNI_PLATFORM as UniApp.PLATFORM) || 'h5' options.inputDir = normalizeInputDir(config) + options.compiler.init() const define = createDefine(options, env) return { - define, + define: extend(define, options.compiler.define()), resolve: createResolve(options), optimizeDeps: createOptimizeDeps(options), server: createServer(options), diff --git a/packages/vite-plugin-uni/src/config/optimizeDeps.ts b/packages/vite-plugin-uni/src/config/optimizeDeps.ts index fc36b1958..42371f0df 100644 --- a/packages/vite-plugin-uni/src/config/optimizeDeps.ts +++ b/packages/vite-plugin-uni/src/config/optimizeDeps.ts @@ -12,6 +12,7 @@ export function createOptimizeDeps( '@dcloudio/uni-components', '@dcloudio/uni-h5', '@dcloudio/uni-h5-vue', + '@dcloudio/uni-i18n', '@dcloudio/uni-shared', ], } diff --git a/packages/vite-plugin-uni/src/config/resolve.ts b/packages/vite-plugin-uni/src/config/resolve.ts index 08e49ce0d..22a0d7491 100644 --- a/packages/vite-plugin-uni/src/config/resolve.ts +++ b/packages/vite-plugin-uni/src/config/resolve.ts @@ -8,7 +8,9 @@ export function createResolve( alias: { '@': options.inputDir, '~@': options.inputDir, // src: url('~@/static/uni.ttf') format('truetype'); - vue: '@dcloudio/uni-h5-vue', + vue: require.resolve('@dcloudio/uni-h5-vue', { + paths: [process.env.UNI_CLI_CONTEXT || process.cwd()], + }), }, } } diff --git a/packages/vite-plugin-uni/src/configResolved/plugins/index.ts b/packages/vite-plugin-uni/src/configResolved/plugins/index.ts index 04692ad2b..37aab6a53 100644 --- a/packages/vite-plugin-uni/src/configResolved/plugins/index.ts +++ b/packages/vite-plugin-uni/src/configResolved/plugins/index.ts @@ -1,4 +1,5 @@ import debug from 'debug' +import { extend } from '@vue/shared' import { Plugin, ResolvedConfig } from 'vite' import { FilterPattern } from '@rollup/pluginutils' import { VitePluginUniResolvedOptions } from '../..' @@ -116,13 +117,28 @@ export function initPlugins( addPlugin(plugins, uniPreVuePlugin(), 'vite:vue', 'pre') addPlugin(plugins, uniRenderjsPlugin(), 'vite:vue') + const injectOptions = options.compiler.inject() + // 可以考虑使用apply:'build' if (command === 'build') { addPlugin( plugins, - uniInjectPlugin(Object.assign(uniInjectPluginOptions, options)), + uniInjectPlugin( + Object.assign(uniInjectPluginOptions, options, injectOptions) + ), 'vite:vue' ) + } else { + if (injectOptions && Object.keys(injectOptions).length) { + addPlugin( + plugins, + uniInjectPlugin( + extend({ exclude: [...COMMON_EXCLUDE] }, options, injectOptions) + ), + 'vite:vue' + ) + } } + addPlugin( plugins, uniEasycomPlugin(Object.assign(uniEasycomPluginOptions, options)), diff --git a/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts b/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts index f2293d24e..a8da3e36a 100644 --- a/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts +++ b/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts @@ -69,17 +69,18 @@ function parsePagesJson( const cssCode = generateCssCode(config, options) return ` -import { extend } from '@vue/shared/dist/shared.esm-bundler.js' import { ${ config.define!.__UNI_FEATURE_PAGES__ ? 'defineAsyncComponent, ' : '' }resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue' import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5' import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '${manifestJsonPath}' +const extend = Object.assign ${cssCode} ${uniConfigCode} ${definePagesCode} ${uniRoutesCode} ${options.command === 'serve' ? hmrCode : ''} +export {} ` } diff --git a/packages/vite-plugin-uni/src/configureServer/index.ts b/packages/vite-plugin-uni/src/configureServer/index.ts index 31c6cb7de..0a04ca52a 100644 --- a/packages/vite-plugin-uni/src/configureServer/index.ts +++ b/packages/vite-plugin-uni/src/configureServer/index.ts @@ -9,6 +9,9 @@ export function createConfigureServer( return function (server) { options.devServer = server serveEasycom(server, options) + server.httpServer!.on('listening', () => { + process.nextTick(() => options.compiler.done()) + }) return () => { serveStatic(server, options) } diff --git a/packages/vite-plugin-uni/src/index.ts b/packages/vite-plugin-uni/src/index.ts index 7ab45b097..298f2cba1 100644 --- a/packages/vite-plugin-uni/src/index.ts +++ b/packages/vite-plugin-uni/src/index.ts @@ -1,4 +1,5 @@ import { Plugin, ResolvedConfig, ViteDevServer } from 'vite' +import { UniCompiler, initUniCompiler } from '@dcloudio/uni-cli-shared' import { createConfig } from './config' import { createResolveId } from './resolveId' @@ -17,6 +18,7 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions { outputDir: string assetsDir: string devServer?: ViteDevServer + compiler: UniCompiler } export * from './vue' @@ -32,6 +34,9 @@ export default function uniPlugin( outputDir: '', command: 'serve', platform: 'h5', + compiler: initUniCompiler({ + root: process.env.UNI_CLI_CONTEXT || process.cwd(), + }), } return { name: 'vite:uni', diff --git a/packages/vite-plugin-uni/src/resolveId/index.ts b/packages/vite-plugin-uni/src/resolveId/index.ts index d4be57906..4235a3750 100644 --- a/packages/vite-plugin-uni/src/resolveId/index.ts +++ b/packages/vite-plugin-uni/src/resolveId/index.ts @@ -3,21 +3,22 @@ import { Plugin } from 'vite' import { VitePluginUniResolvedOptions } from '..' const debugResolve = debug('uni:resolve') - -const VUES = ['vue', 'vue.js', './vue.js', 'dist/vue.runtime.esm-bundler.js'] +const BUILT_IN_MODULES = ['vue-router', 'vuex'] export function createResolveId( _options: VitePluginUniResolvedOptions ): Plugin['resolveId'] { return function (id) { - if (id.startsWith('@dcloudio/') || id.startsWith('@vue/')) { - return require.resolve(id, { + if ( + id.startsWith('@dcloudio/') || + id.startsWith('@vue/') || + BUILT_IN_MODULES.includes(id) + ) { + const path = require.resolve(id, { paths: [process.env.UNI_CLI_CONTEXT!], }) - } - if (VUES.includes(id)) { - debugResolve(id) - return '@dcloudio/uni-h5-vue' + debugResolve(path) + return path } } } diff --git a/yarn.lock b/yarn.lock index f54973bc6..6d13960a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5814,6 +5814,11 @@ table@^6.0.4: string-width "^4.2.0" strip-ansi "^6.0.0" +tapable@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.0.tgz#5c373d281d9c672848213d0e037d1c4165ab426b" + integrity sha512-FBk4IesMV1rBxX2tfiK8RAmogtWn53puLOQlvO8XuwlgxcYbP4mVPS9Ph4aeamSyyVjOl24aYWAuc8U5kCVwMw== + tar-fs@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784" -- GitLab