feat: 响应体组件封装

This commit is contained in:
duanshuwen
2025-07-14 16:10:10 +08:00
parent 8766bb3720
commit e5d908701f
55 changed files with 290 additions and 155 deletions

View File

@@ -2582,21 +2582,21 @@ function injectHook(type, hook, target = currentInstance, prepend = false) {
);
}
}
const createHook = (lifecycle) => (hook, target = currentInstance) => (
const createHook$1 = (lifecycle) => (hook, target = currentInstance) => (
// post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
(!isInSSRComponentSetup || lifecycle === "sp") && injectHook(lifecycle, (...args) => hook(...args), target)
);
const onBeforeMount = createHook("bm");
const onMounted = createHook("m");
const onBeforeUpdate = createHook("bu");
const onUpdated = createHook("u");
const onBeforeUnmount = createHook("bum");
const onUnmounted = createHook("um");
const onServerPrefetch = createHook("sp");
const onRenderTriggered = createHook(
const onBeforeMount = createHook$1("bm");
const onMounted = createHook$1("m");
const onBeforeUpdate = createHook$1("bu");
const onUpdated = createHook$1("u");
const onBeforeUnmount = createHook$1("bum");
const onUnmounted = createHook$1("um");
const onServerPrefetch = createHook$1("sp");
const onRenderTriggered = createHook$1(
"rtg"
);
const onRenderTracked = createHook(
const onRenderTracked = createHook$1(
"rtc"
);
function onErrorCaptured(hook, target = currentInstance) {
@@ -2609,15 +2609,11 @@ const getPublicInstance = (i) => {
return getExposeProxy(i) || i.proxy;
return getPublicInstance(i.parent);
};
function getComponentInternalInstance(i) {
return i;
}
const publicPropertiesMap = (
// Move PURE marker to new line to workaround compiler discarding it
// due to type annotation
/* @__PURE__ */ extend(/* @__PURE__ */ Object.create(null), {
// fixed by xxxxxx
$: getComponentInternalInstance,
$: (i) => i,
// fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el故模拟一个假的
// $el: i => i.vnode.el,
$el: (i) => i.__$el || (i.__$el = {}),
@@ -4488,7 +4484,6 @@ function warnRef(ref2) {
const queuePostRenderEffect = queuePostFlushCb;
function mountComponent(initialVNode, options) {
const instance = initialVNode.component = createComponentInstance(initialVNode, options.parentComponent, null);
instance.renderer = options.mpType ? options.mpType : "component";
{
instance.ctx.$onApplyOptions = onApplyOptions;
instance.ctx.$children = [];
@@ -4827,8 +4822,7 @@ function injectLifecycleHook(name, hook, publicThis, instance) {
}
function initHooks$1(options, instance, publicThis) {
const mpType = options.mpType || publicThis.$mpType;
if (!mpType || mpType === "component" || // instance.renderer 标识页面是否作为组件渲染
mpType === "page" && instance.renderer === "component") {
if (!mpType || mpType === "component") {
return;
}
Object.keys(options).forEach((name) => {
@@ -5467,10 +5461,10 @@ function handlePromise(promise) {
function promisify$1(name, fn) {
return (args = {}, ...rest) => {
if (hasCallback(args)) {
return wrapperReturnValue(name, invokeApi(name, fn, extend({}, args), rest));
return wrapperReturnValue(name, invokeApi(name, fn, args, rest));
}
return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
invokeApi(name, fn, extend({}, args, { success: resolve, fail: reject }), rest);
invokeApi(name, fn, extend(args, { success: resolve, fail: reject }), rest);
})));
};
}
@@ -5867,7 +5861,7 @@ function promisify(name, api) {
}
return function promiseApi(options = {}, ...rest) {
if (isFunction(options.success) || isFunction(options.fail) || isFunction(options.complete)) {
return wrapperReturnValue(name, invokeApi(name, api, extend({}, options), rest));
return wrapperReturnValue(name, invokeApi(name, api, options, rest));
}
return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
invokeApi(name, api, extend({}, options, {
@@ -6034,7 +6028,7 @@ function getOSInfo(system, platform) {
osName = system.split(" ")[0] || platform;
osVersion = system.split(" ")[1] || "";
}
osName = osName.toLowerCase();
osName = osName.toLocaleLowerCase();
switch (osName) {
case "harmony":
case "ohos":
@@ -6074,9 +6068,9 @@ function populateParameters(fromRes, toRes) {
appVersion: "1.0.0",
appVersionCode: "100",
appLanguage: getAppLanguage(hostLanguage),
uniCompileVersion: "4.75",
uniCompilerVersion: "4.75",
uniRuntimeVersion: "4.75",
uniCompileVersion: "4.66",
uniCompilerVersion: "4.66",
uniRuntimeVersion: "4.66",
uniPlatform: "mp-weixin",
deviceBrand,
deviceModel: model,
@@ -6113,7 +6107,7 @@ function getGetDeviceType(fromRes, model) {
mac: "pc"
};
const deviceTypeMapsKeys = Object.keys(deviceTypeMaps);
const _model = model.toLowerCase();
const _model = model.toLocaleLowerCase();
for (let index2 = 0; index2 < deviceTypeMapsKeys.length; index2++) {
const _m = deviceTypeMapsKeys[index2];
if (_model.indexOf(_m) !== -1) {
@@ -6127,7 +6121,7 @@ function getGetDeviceType(fromRes, model) {
function getDeviceBrand(brand) {
let deviceBrand = brand;
if (deviceBrand) {
deviceBrand = deviceBrand.toLowerCase();
deviceBrand = deviceBrand.toLocaleLowerCase();
}
return deviceBrand;
}
@@ -6225,9 +6219,9 @@ const getAppBaseInfo = {
appLanguage: getAppLanguage(hostLanguage),
isUniAppX: false,
uniPlatform: "mp-weixin",
uniCompileVersion: "4.75",
uniCompilerVersion: "4.75",
uniRuntimeVersion: "4.75"
uniCompileVersion: "4.66",
uniCompilerVersion: "4.66",
uniRuntimeVersion: "4.66"
};
extend(toRes, parameters);
}
@@ -6900,14 +6894,14 @@ const atFileRegex = /^\s*at\s+[\w/./-]+:\d+$/;
function rewriteConsole() {
function wrapConsole(type) {
return function(...args) {
{
const originalArgs = [...args];
if (originalArgs.length) {
const maybeAtFile = originalArgs[originalArgs.length - 1];
if (typeof maybeAtFile === "string" && atFileRegex.test(maybeAtFile)) {
originalArgs.pop();
}
const originalArgs = [...args];
if (originalArgs.length) {
const maybeAtFile = originalArgs[originalArgs.length - 1];
if (typeof maybeAtFile === "string" && atFileRegex.test(maybeAtFile)) {
originalArgs.pop();
}
}
{
originalConsole[type](...originalArgs);
}
if (type === "error" && args.length === 1) {
@@ -6967,9 +6961,9 @@ function isConsoleWritable() {
return isWritable;
}
function initRuntimeSocketService() {
const hosts = "192.168.1.23,127.0.0.1";
const hosts = "10.10.3.1,192.168.56.1,127.0.0.1";
const port = "8090";
const id = "mp-weixin_6ijytV";
const id = "mp-weixin_BW9LnK";
const lazy = typeof swan !== "undefined";
let restoreError = lazy ? () => {
} : initOnError();
@@ -7915,29 +7909,13 @@ const createSubpackageApp = initCreateSubpackageApp();
wx.createPluginApp = global.createPluginApp = createPluginApp;
wx.createSubpackageApp = global.createSubpackageApp = createSubpackageApp;
}
const createLifeCycleHook = (lifecycle, flag = 0) => (hook, target = getCurrentInstance()) => {
const createHook = (lifecycle) => (hook, target = getCurrentInstance()) => {
!isInSSRComponentSetup && injectHook(lifecycle, hook, target);
};
const onShow = /* @__PURE__ */ createLifeCycleHook(
ON_SHOW,
1 | 2
/* HookFlags.PAGE */
);
const onHide = /* @__PURE__ */ createLifeCycleHook(
ON_HIDE,
1 | 2
/* HookFlags.PAGE */
);
const onLaunch = /* @__PURE__ */ createLifeCycleHook(
ON_LAUNCH,
1
/* HookFlags.APP */
);
const onLoad = /* @__PURE__ */ createLifeCycleHook(
ON_LOAD,
2
/* HookFlags.PAGE */
);
const onShow = /* @__PURE__ */ createHook(ON_SHOW);
const onHide = /* @__PURE__ */ createHook(ON_HIDE);
const onLaunch = /* @__PURE__ */ createHook(ON_LAUNCH);
const onLoad = /* @__PURE__ */ createHook(ON_LOAD);
exports._export_sfc = _export_sfc;
exports.createSSRApp = createSSRApp;
exports.defineComponent = defineComponent;