提交 f96cfa22 编写于 作者: fxy060608's avatar fxy060608

feat(h5): add unsupported components

上级 11908c9f
import { ComponentOptions, defineComponent } from 'vue'
import {
ComponentOptions,
createElementBlock,
defineComponent,
openBlock,
} from 'vue'
import { camelize, capitalize } from '@vue/shared'
import animation from './animation'
/**
* 内置组件(对外,比如view)
......@@ -27,3 +33,19 @@ export const defineSystemComponent: typeof defineComponent = (options: any) => {
}
return defineComponent(options)
}
/**
* 暂未支持的组件
* @param name
* @returns
*/
export const defineUnsupportedComponent = (name: string) => {
return defineBuiltInComponent({
name: capitalize(camelize(name)),
setup() {
return () => (
openBlock(),
createElementBlock('uni-' + name, null, name + ' is unsupported')
)
},
})
}
......@@ -20,6 +20,7 @@ export { useTouchtrack } from './helpers/useTouchtrack'
export {
defineBuiltInComponent,
defineSystemComponent,
defineUnsupportedComponent,
} from './helpers/component'
export { flatVNode } from './helpers/flatVNode'
export { uniFormKey } from './components/form'
......
import fs from 'fs'
import path from 'path'
import { Loader, Plugin } from 'esbuild'
import { preJs } from '@dcloudio/uni-cli-shared'
export const JS_TYPES_RE = /\.(?:j|t)sx?$|\.mjs$/
export function esbuildPrePlugin(): Plugin {
return {
name: 'vite:dep-scan',
setup(build) {
build.onLoad({ filter: JS_TYPES_RE }, ({ path: id }) => {
let ext = path.extname(id).slice(1)
if (ext === 'mjs') ext = 'js'
let contents = fs.readFileSync(id, 'utf-8')
if (contents.includes('#endif')) {
contents = preJs(contents)
}
return {
loader: ext as Loader,
contents,
}
})
},
}
}
import fs from 'fs'
import path from 'path'
import { isInHBuilderX, UniVitePlugin } from '@dcloudio/uni-cli-shared'
import {
isInHBuilderX,
resolveMainPathOnce,
UniVitePlugin,
} from '@dcloudio/uni-cli-shared'
import { createHandleHotUpdate } from './handleHotUpdate'
import { createTransformIndexHtml } from './transformIndexHtml'
import { createDefine } from '../utils/features'
import { isSsr } from '../utils'
import { ViteDevServer } from 'vite'
import { esbuildPrePlugin } from './esbuild/esbuildPrePlugin'
const external = [
'@dcloudio/uni-app',
......@@ -43,7 +48,11 @@ export const UniH5Plugin: UniVitePlugin = {
}
return {
optimizeDeps: {
exclude: ['@dcloudio/uni-h5', '@dcloudio/uni-h5-vue'],
entries: resolveMainPathOnce(process.env.UNI_INPUT_DIR),
exclude: external,
esbuildOptions: {
plugins: [esbuildPrePlugin()],
},
},
define: createDefine(env.command, config),
server: {
......
......@@ -605,6 +605,14 @@ const defineSystemComponent = (options) => {
};
return vue.defineComponent(options);
};
const defineUnsupportedComponent = (name) => {
return defineBuiltInComponent({
name: shared.capitalize(shared.camelize(name)),
setup() {
return () => (vue.openBlock(), vue.createElementBlock("uni-" + name, null, name + " is unsupported"));
}
});
};
const hoverProps = {
hoverClass: {
type: String,
......@@ -714,7 +722,7 @@ function normalizeCustomEvent(name, domEvt, el, detail) {
};
}
const uniFormKey = PolySymbol(process.env.NODE_ENV !== "production" ? "uniForm" : "uf");
var index$y = /* @__PURE__ */ defineBuiltInComponent({
var index$E = /* @__PURE__ */ defineBuiltInComponent({
name: "Form",
emits: ["submit", "reset"],
setup(_props, {
......@@ -762,7 +770,7 @@ const props$v = {
default: ""
}
};
var index$x = /* @__PURE__ */ defineBuiltInComponent({
var index$D = /* @__PURE__ */ defineBuiltInComponent({
name: "Label",
props: props$v,
setup(props2, {
......@@ -806,7 +814,7 @@ function useProvideLabel() {
});
return handlers;
}
var index$w = /* @__PURE__ */ defineBuiltInComponent({
var index$C = /* @__PURE__ */ defineBuiltInComponent({
name: "Button",
props: {
id: {
......@@ -1652,7 +1660,7 @@ const props$u = {
default: false
}
};
var index$v = /* @__PURE__ */ defineBuiltInComponent({
var index$B = /* @__PURE__ */ defineBuiltInComponent({
inheritAttrs: false,
name: "Canvas",
compatConfig: {
......@@ -2118,7 +2126,7 @@ const props$t = {
default: ""
}
};
var index$u = /* @__PURE__ */ defineBuiltInComponent({
var index$A = /* @__PURE__ */ defineBuiltInComponent({
name: "CheckboxGroup",
props: props$t,
emits: ["change"],
......@@ -2194,7 +2202,7 @@ const props$s = {
default: ""
}
};
var index$t = /* @__PURE__ */ defineBuiltInComponent({
var index$z = /* @__PURE__ */ defineBuiltInComponent({
name: "Checkbox",
props: props$s,
setup(props2, {
......@@ -2463,7 +2471,7 @@ const props$q = /* @__PURE__ */ shared.extend({}, props$r, {
default: false
}
});
var index$s = /* @__PURE__ */ defineBuiltInComponent({
var index$y = /* @__PURE__ */ defineBuiltInComponent({
name: "Editor",
props: props$q,
emit: ["ready", "focus", "blur", "input", "statuschange", ...emit$1],
......@@ -2524,7 +2532,7 @@ const ICONS = {
c: GREY_COLOR
}
};
var index$r = /* @__PURE__ */ defineBuiltInComponent({
var index$x = /* @__PURE__ */ defineBuiltInComponent({
name: "Icon",
props: {
type: {
......@@ -2588,7 +2596,7 @@ const IMAGE_MODES = {
"bottom left": ["left bottom"],
"bottom right": ["right bottom"]
};
var index$q = /* @__PURE__ */ defineBuiltInComponent({
var index$w = /* @__PURE__ */ defineBuiltInComponent({
name: "Image",
props: props$p,
setup(props2, {
......@@ -3291,7 +3299,7 @@ const props$m = {
default: false
}
};
var index$p = /* @__PURE__ */ defineBuiltInComponent({
var index$v = /* @__PURE__ */ defineBuiltInComponent({
inheritAttrs: false,
name: "MovableArea",
props: props$m,
......@@ -3836,7 +3844,7 @@ const props$l = {
default: true
}
};
var index$o = /* @__PURE__ */ defineBuiltInComponent({
var index$u = /* @__PURE__ */ defineBuiltInComponent({
name: "MovableView",
props: props$l,
emits: ["change", "scale"],
......@@ -4247,7 +4255,7 @@ const props$k = {
default: false
}
};
var index$n = /* @__PURE__ */ defineBuiltInComponent({
var index$t = /* @__PURE__ */ defineBuiltInComponent({
name: "Navigator",
compatConfig: {
MODE: 3
......@@ -4576,7 +4584,7 @@ const props$i = {
}
}
};
var index$m = /* @__PURE__ */ defineBuiltInComponent({
var index$s = /* @__PURE__ */ defineBuiltInComponent({
name: "Progress",
props: props$i,
setup(props2) {
......@@ -4655,7 +4663,7 @@ const props$h = {
default: ""
}
};
var index$l = /* @__PURE__ */ defineBuiltInComponent({
var index$r = /* @__PURE__ */ defineBuiltInComponent({
name: "RadioGroup",
props: props$h,
setup(props2, {
......@@ -4756,7 +4764,7 @@ const props$g = {
default: ""
}
};
var index$k = /* @__PURE__ */ defineBuiltInComponent({
var index$q = /* @__PURE__ */ defineBuiltInComponent({
name: "Radio",
props: props$g,
setup(props2, {
......@@ -5050,7 +5058,7 @@ const props$f = {
}
}
};
var index$j = /* @__PURE__ */ defineBuiltInComponent({
var index$p = /* @__PURE__ */ defineBuiltInComponent({
name: "RichText",
compatConfig: {
MODE: 3
......@@ -5135,7 +5143,7 @@ const props$e = {
default: false
}
};
var index$i = /* @__PURE__ */ defineBuiltInComponent({
var index$o = /* @__PURE__ */ defineBuiltInComponent({
name: "ScrollView",
compatConfig: {
MODE: 3
......@@ -5462,7 +5470,7 @@ const props$d = {
default: false
}
};
var index$h = /* @__PURE__ */ defineBuiltInComponent({
var index$n = /* @__PURE__ */ defineBuiltInComponent({
name: "Slider",
props: props$d,
emits: ["changing", "change"],
......@@ -5999,7 +6007,7 @@ function useLayout(props2, state, swiperContexts, slideFrameRef, emit2, trigger)
onSwiperDotClick
};
}
var index$g = /* @__PURE__ */ defineBuiltInComponent({
var index$m = /* @__PURE__ */ defineBuiltInComponent({
name: "Swiper",
props: props$c,
emits: ["change", "transition", "animationfinish", "update:current", "update:currentItemId"],
......@@ -6105,7 +6113,7 @@ const props$b = {
default: ""
}
};
var index$f = /* @__PURE__ */ defineBuiltInComponent({
var index$l = /* @__PURE__ */ defineBuiltInComponent({
name: "SwiperItem",
props: props$b,
setup(props2, {
......@@ -6150,7 +6158,7 @@ const props$a = {
default: "#007aff"
}
};
var index$e = /* @__PURE__ */ defineBuiltInComponent({
var index$k = /* @__PURE__ */ defineBuiltInComponent({
name: "Switch",
props: props$a,
emits: ["change"],
......@@ -6245,7 +6253,7 @@ function normalizeText(text, { space, decode }) {
}
return text.replace(/&nbsp;/g, SPACE_UNICODE.nbsp).replace(/&ensp;/g, SPACE_UNICODE.ensp).replace(/&emsp;/g, SPACE_UNICODE.emsp).replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
}
var index$d = /* @__PURE__ */ defineBuiltInComponent({
var index$j = /* @__PURE__ */ defineBuiltInComponent({
name: "Text",
props: {
selectable: {
......@@ -6313,7 +6321,7 @@ const props$9 = /* @__PURE__ */ shared.extend({}, props$o, {
}
});
let fixMargin = false;
var index$c = /* @__PURE__ */ defineBuiltInComponent({
var index$i = /* @__PURE__ */ defineBuiltInComponent({
name: "Textarea",
props: props$9,
emit: ["confirm", "linechange", ...emit],
......@@ -6431,7 +6439,7 @@ var index$c = /* @__PURE__ */ defineBuiltInComponent({
};
}
});
var index$b = /* @__PURE__ */ defineBuiltInComponent({
var index$h = /* @__PURE__ */ defineBuiltInComponent({
name: "View",
props: shared.extend({}, hoverProps),
setup(props2, {
......@@ -6456,13 +6464,13 @@ function useSubscribe(callback, name, multiple, pageId) {
const instance = vue.getCurrentInstance();
instance.proxy;
}
let index$a = 0;
let index$g = 0;
function useContextInfo(_id) {
useCurrentPageId();
const instance = vue.getCurrentInstance();
const vm = instance.proxy;
const type = vm.$options.name.toLowerCase();
const id = _id || vm.id || `context${index$a++}`;
const id = _id || vm.id || `context${index$g++}`;
return `${type}.${id}`;
}
function injectLifecycleHook(name, hook, publicThis, instance) {
......@@ -6760,7 +6768,7 @@ function initHistory() {
return vueRouter.createMemoryHistory(base);
}
}
var index$9 = {
var index$f = {
install(app) {
initApp$1(app);
if (__UNI_FEATURE_PAGES__) {
......@@ -7388,7 +7396,7 @@ const props$8 = {
default: true
}
};
var index$8 = /* @__PURE__ */ defineBuiltInComponent({
var index$e = /* @__PURE__ */ defineBuiltInComponent({
name: "Video",
props: props$8,
emits: ["fullscreenchange", "progress", "loadedmetadata", "waiting", "error", "play", "pause", "ended", "timeupdate"],
......@@ -7617,7 +7625,7 @@ const props$7 = {
default: ""
}
};
var index$7 = /* @__PURE__ */ defineBuiltInComponent({
var index$d = /* @__PURE__ */ defineBuiltInComponent({
inheritAttrs: false,
name: "WebView",
props: props$7,
......@@ -8384,7 +8392,7 @@ function useMap(props2, rootRef, emit2) {
mapRef
};
}
var index$6 = /* @__PURE__ */ defineBuiltInComponent({
var index$c = /* @__PURE__ */ defineBuiltInComponent({
name: "Map",
props: props$2,
emits: ["markertap", "labeltap", "callouttap", "controltap", "regionchange", "tap", "click", "updated", "update:scale", "update:latitude", "update:longitude"],
......@@ -8417,7 +8425,7 @@ const props$1 = {
default: 0
}
};
var index$5 = /* @__PURE__ */ defineBuiltInComponent({
var index$b = /* @__PURE__ */ defineBuiltInComponent({
name: "CoverView",
compatConfig: {
MODE: 3
......@@ -8455,7 +8463,7 @@ var index$5 = /* @__PURE__ */ defineBuiltInComponent({
};
}
});
var index$4 = /* @__PURE__ */ defineBuiltInComponent({
var index$a = /* @__PURE__ */ defineBuiltInComponent({
name: "CoverImage",
compatConfig: {
MODE: 3
......@@ -8702,7 +8710,7 @@ const props = {
default: ""
}
};
var index$3 = /* @__PURE__ */ defineBuiltInComponent({
var index$9 = /* @__PURE__ */ defineBuiltInComponent({
name: "Picker",
compatConfig: {
MODE: 3
......@@ -9296,6 +9304,12 @@ function usePickerForm(_resetFormData, _getFormData) {
uniForm.addField(field);
}
}
var index$8 = /* @__PURE__ */ defineUnsupportedComponent("ad");
var index$7 = /* @__PURE__ */ defineUnsupportedComponent("ad-content-page");
var index$6 = /* @__PURE__ */ defineUnsupportedComponent("ad-draw");
var index$5 = /* @__PURE__ */ defineUnsupportedComponent("camera");
var index$4 = /* @__PURE__ */ defineUnsupportedComponent("live-player");
var index$3 = /* @__PURE__ */ defineUnsupportedComponent("live-pusher");
const UniViewJSBridge$1 = /* @__PURE__ */ shared.extend(ViewJSBridge, {
publishHandler(event, args, pageId) {
UniServiceJSBridge.subscribeHandler(event, args, pageId);
......@@ -10661,46 +10675,52 @@ var index = /* @__PURE__ */ defineSystemComponent({
return vue.openBlock(), vue.createBlock("div", clazz, [loadingVNode]);
}
});
exports.Ad = index$8;
exports.AdContentPage = index$7;
exports.AdDraw = index$6;
exports.AsyncErrorComponent = index$1;
exports.AsyncLoadingComponent = index;
exports.Button = index$w;
exports.Canvas = index$v;
exports.Checkbox = index$t;
exports.CheckboxGroup = index$u;
exports.CoverImage = index$4;
exports.CoverView = index$5;
exports.Editor = index$s;
exports.Form = index$y;
exports.Icon = index$r;
exports.Image = index$q;
exports.Button = index$C;
exports.Camera = index$5;
exports.Canvas = index$B;
exports.Checkbox = index$z;
exports.CheckboxGroup = index$A;
exports.CoverImage = index$a;
exports.CoverView = index$b;
exports.Editor = index$y;
exports.Form = index$E;
exports.Icon = index$x;
exports.Image = index$w;
exports.Input = Input;
exports.Label = index$x;
exports.Label = index$D;
exports.LayoutComponent = LayoutComponent;
exports.Map = index$6;
exports.MovableArea = index$p;
exports.MovableView = index$o;
exports.Navigator = index$n;
exports.LivePlayer = index$4;
exports.LivePusher = index$3;
exports.Map = index$c;
exports.MovableArea = index$v;
exports.MovableView = index$u;
exports.Navigator = index$t;
exports.PageComponent = index$2;
exports.Picker = index$3;
exports.Picker = index$9;
exports.PickerView = PickerView;
exports.PickerViewColumn = PickerViewColumn;
exports.Progress = index$m;
exports.Radio = index$k;
exports.RadioGroup = index$l;
exports.Progress = index$s;
exports.Radio = index$q;
exports.RadioGroup = index$r;
exports.ResizeSensor = ResizeSensor;
exports.RichText = index$j;
exports.ScrollView = index$i;
exports.Slider = index$h;
exports.Swiper = index$g;
exports.SwiperItem = index$f;
exports.Switch = index$e;
exports.Text = index$d;
exports.Textarea = index$c;
exports.RichText = index$p;
exports.ScrollView = index$o;
exports.Slider = index$n;
exports.Swiper = index$m;
exports.SwiperItem = index$l;
exports.Switch = index$k;
exports.Text = index$j;
exports.Textarea = index$i;
exports.UniServiceJSBridge = UniServiceJSBridge$1;
exports.UniViewJSBridge = UniViewJSBridge$1;
exports.Video = index$8;
exports.View = index$b;
exports.WebView = index$7;
exports.Video = index$e;
exports.View = index$h;
exports.WebView = index$d;
exports.clearStorage = clearStorage;
exports.clearStorageSync = clearStorageSync;
exports.getApp = getApp$1;
......@@ -10711,7 +10731,7 @@ exports.getStorageInfo = getStorageInfo;
exports.getStorageInfoSync = getStorageInfoSync;
exports.getStorageSync = getStorageSync;
exports.getSystemInfoSync = getSystemInfoSync;
exports.plugin = index$9;
exports.plugin = index$f;
exports.removeStorage = removeStorage;
exports.removeStorageSync = removeStorageSync;
exports.request = request;
......
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, onBeforeActivate, onBeforeDeactivate, openBlock, createBlock, renderList, onDeactivated, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, createElementBlock, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { I18N_JSON_DELIMITERS, once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, 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";
......@@ -1538,6 +1538,14 @@ const defineSystemComponent = (options) => {
};
return defineComponent(options);
};
const defineUnsupportedComponent = (name) => {
return defineBuiltInComponent({
name: capitalize(camelize(name)),
setup() {
return () => (openBlock(), createElementBlock("uni-" + name, null, name + " is unsupported"));
}
});
};
const hoverProps = {
hoverClass: {
type: String,
......@@ -1647,7 +1655,7 @@ function normalizeCustomEvent(name, domEvt, el, detail) {
};
}
const uniFormKey = PolySymbol(process.env.NODE_ENV !== "production" ? "uniForm" : "uf");
var index$u = /* @__PURE__ */ defineBuiltInComponent({
var index$A = /* @__PURE__ */ defineBuiltInComponent({
name: "Form",
emits: ["submit", "reset"],
setup(_props, {
......@@ -1695,7 +1703,7 @@ const props$C = {
default: ""
}
};
var index$t = /* @__PURE__ */ defineBuiltInComponent({
var index$z = /* @__PURE__ */ defineBuiltInComponent({
name: "Label",
props: props$C,
setup(props2, {
......@@ -1793,7 +1801,7 @@ function _removeListeners(id2, listeners2, watch2) {
}
});
}
var index$s = /* @__PURE__ */ defineBuiltInComponent({
var index$y = /* @__PURE__ */ defineBuiltInComponent({
name: "Button",
props: {
id: {
......@@ -4031,13 +4039,13 @@ const createMediaQueryObserver = /* @__PURE__ */ defineSyncApi("createMediaQuery
}
return new ServiceMediaQueryObserver(getCurrentPageVm());
});
let index$r = 0;
let index$x = 0;
let optionsCache = {};
function operateEditor(componentId, pageId, type, options) {
const data = { options };
const needCallOptions = options && ("success" in options || "fail" in options || "complete" in options);
if (needCallOptions) {
const callbackId = String(index$r++);
const callbackId = String(index$x++);
data.callbackId = callbackId;
optionsCache[callbackId] = options;
}
......@@ -6197,7 +6205,7 @@ const props$B = {
default: false
}
};
var index$q = /* @__PURE__ */ defineBuiltInComponent({
var index$w = /* @__PURE__ */ defineBuiltInComponent({
inheritAttrs: false,
name: "Canvas",
compatConfig: {
......@@ -6666,7 +6674,7 @@ const props$A = {
default: ""
}
};
var index$p = /* @__PURE__ */ defineBuiltInComponent({
var index$v = /* @__PURE__ */ defineBuiltInComponent({
name: "CheckboxGroup",
props: props$A,
emits: ["change"],
......@@ -6742,7 +6750,7 @@ const props$z = {
default: ""
}
};
var index$o = /* @__PURE__ */ defineBuiltInComponent({
var index$u = /* @__PURE__ */ defineBuiltInComponent({
name: "Checkbox",
props: props$z,
setup(props2, {
......@@ -7605,7 +7613,7 @@ const props$x = /* @__PURE__ */ extend({}, props$y, {
default: false
}
});
var index$n = /* @__PURE__ */ defineBuiltInComponent({
var index$t = /* @__PURE__ */ defineBuiltInComponent({
name: "Editor",
props: props$x,
emit: ["ready", "focus", "blur", "input", "statuschange", ...emit$1],
......@@ -7667,7 +7675,7 @@ const ICONS = {
c: GREY_COLOR
}
};
var index$m = /* @__PURE__ */ defineBuiltInComponent({
var index$s = /* @__PURE__ */ defineBuiltInComponent({
name: "Icon",
props: {
type: {
......@@ -7731,7 +7739,7 @@ const IMAGE_MODES = {
"bottom left": ["left bottom"],
"bottom right": ["right bottom"]
};
var index$l = /* @__PURE__ */ defineBuiltInComponent({
var index$r = /* @__PURE__ */ defineBuiltInComponent({
name: "Image",
props: props$w,
setup(props2, {
......@@ -9795,7 +9803,7 @@ const props$r = {
default: false
}
};
var index$k = /* @__PURE__ */ defineBuiltInComponent({
var index$q = /* @__PURE__ */ defineBuiltInComponent({
name: "Navigator",
compatConfig: {
MODE: 3
......@@ -10897,7 +10905,7 @@ const props$p = {
}
}
};
var index$j = /* @__PURE__ */ defineBuiltInComponent({
var index$p = /* @__PURE__ */ defineBuiltInComponent({
name: "Progress",
props: props$p,
setup(props2) {
......@@ -10976,7 +10984,7 @@ const props$o = {
default: ""
}
};
var index$i = /* @__PURE__ */ defineBuiltInComponent({
var index$o = /* @__PURE__ */ defineBuiltInComponent({
name: "RadioGroup",
props: props$o,
setup(props2, {
......@@ -11083,7 +11091,7 @@ const props$n = {
default: ""
}
};
var index$h = /* @__PURE__ */ defineBuiltInComponent({
var index$n = /* @__PURE__ */ defineBuiltInComponent({
name: "Radio",
props: props$n,
setup(props2, {
......@@ -11387,7 +11395,7 @@ const props$m = {
}
}
};
var index$g = /* @__PURE__ */ defineBuiltInComponent({
var index$m = /* @__PURE__ */ defineBuiltInComponent({
name: "RichText",
compatConfig: {
MODE: 3
......@@ -11951,7 +11959,7 @@ const props$k = {
default: false
}
};
var index$f = /* @__PURE__ */ defineBuiltInComponent({
var index$l = /* @__PURE__ */ defineBuiltInComponent({
name: "Slider",
props: props$k,
emits: ["changing", "change"],
......@@ -12783,7 +12791,7 @@ const props$h = {
default: "#007aff"
}
};
var index$e = /* @__PURE__ */ defineBuiltInComponent({
var index$k = /* @__PURE__ */ defineBuiltInComponent({
name: "Switch",
props: props$h,
emits: ["change"],
......@@ -12887,7 +12895,7 @@ function normalizeText(text2, { space, decode: decode2 }) {
}
return text2.replace(/&nbsp;/g, SPACE_UNICODE.nbsp).replace(/&ensp;/g, SPACE_UNICODE.ensp).replace(/&emsp;/g, SPACE_UNICODE.emsp).replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
}
var index$d = /* @__PURE__ */ defineBuiltInComponent({
var index$j = /* @__PURE__ */ defineBuiltInComponent({
name: "Text",
props: {
selectable: {
......@@ -12959,7 +12967,7 @@ function setFixMargin() {
const DARK_TEST_STRING = "(prefers-color-scheme: dark)";
fixMargin = String(navigator.platform).indexOf("iP") === 0 && String(navigator.vendor).indexOf("Apple") === 0 && window.matchMedia(DARK_TEST_STRING).media !== DARK_TEST_STRING;
}
var index$c = /* @__PURE__ */ defineBuiltInComponent({
var index$i = /* @__PURE__ */ defineBuiltInComponent({
name: "Textarea",
props: props$g,
emit: ["confirm", "linechange", ...emit],
......@@ -13080,7 +13088,7 @@ var index$c = /* @__PURE__ */ defineBuiltInComponent({
};
}
});
var index$b = /* @__PURE__ */ defineBuiltInComponent({
var index$h = /* @__PURE__ */ defineBuiltInComponent({
name: "View",
props: extend({}, hoverProps),
setup(props2, {
......@@ -13144,13 +13152,13 @@ function useOn(name, callback) {
onMounted(() => UniViewJSBridge.on(name, callback));
onBeforeUnmount(() => UniViewJSBridge.off(name));
}
let index$a = 0;
let index$g = 0;
function useContextInfo(_id) {
const page = useCurrentPageId();
const instance2 = getCurrentInstance();
const vm = instance2.proxy;
const type = vm.$options.name.toLowerCase();
const id2 = _id || vm.id || `context${index$a++}`;
const id2 = _id || vm.id || `context${index$g++}`;
onMounted(() => {
const el = vm.$el;
el.__uniContextInfo = {
......@@ -13626,7 +13634,7 @@ function initHistory() {
});
return history2;
}
var index$9 = {
var index$f = {
install(app) {
initApp$1(app);
initViewPlugin(app);
......@@ -14414,7 +14422,7 @@ const props$f = {
default: true
}
};
var index$8 = /* @__PURE__ */ defineBuiltInComponent({
var index$e = /* @__PURE__ */ defineBuiltInComponent({
name: "Video",
props: props$f,
emits: ["fullscreenchange", "progress", "loadedmetadata", "waiting", "error", "play", "pause", "ended", "timeupdate"],
......@@ -14643,7 +14651,7 @@ const props$e = {
default: ""
}
};
var index$7 = /* @__PURE__ */ defineBuiltInComponent({
var index$d = /* @__PURE__ */ defineBuiltInComponent({
inheritAttrs: false,
name: "WebView",
props: props$e,
......@@ -16251,13 +16259,13 @@ function usePopup(props2, {
});
return visible;
}
let index$6 = 0;
let index$c = 0;
let overflow = "";
function preventScroll(prevent) {
let before = index$6;
index$6 += prevent ? 1 : -1;
index$6 = Math.max(0, index$6);
if (index$6 > 0) {
let before = index$c;
index$c += prevent ? 1 : -1;
index$c = Math.max(0, index$c);
if (index$c > 0) {
if (before === 0) {
overflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
......@@ -19623,7 +19631,7 @@ const props$1 = {
default: 0
}
};
var index$5 = /* @__PURE__ */ defineBuiltInComponent({
var index$b = /* @__PURE__ */ defineBuiltInComponent({
name: "CoverView",
compatConfig: {
MODE: 3
......@@ -19664,7 +19672,7 @@ var index$5 = /* @__PURE__ */ defineBuiltInComponent({
};
}
});
var index$4 = /* @__PURE__ */ defineBuiltInComponent({
var index$a = /* @__PURE__ */ defineBuiltInComponent({
name: "CoverImage",
compatConfig: {
MODE: 3
......@@ -19837,7 +19845,7 @@ const props = {
default: ""
}
};
var index$3 = /* @__PURE__ */ defineBuiltInComponent({
var index$9 = /* @__PURE__ */ defineBuiltInComponent({
name: "Picker",
compatConfig: {
MODE: 3
......@@ -20457,6 +20465,12 @@ function usePickerForm(_resetFormData, _getFormData) {
});
}
}
var index$8 = /* @__PURE__ */ defineUnsupportedComponent("ad");
var index$7 = /* @__PURE__ */ defineUnsupportedComponent("ad-content-page");
var index$6 = /* @__PURE__ */ defineUnsupportedComponent("ad-draw");
var index$5 = /* @__PURE__ */ defineUnsupportedComponent("camera");
var index$4 = /* @__PURE__ */ defineUnsupportedComponent("live-player");
var index$3 = /* @__PURE__ */ defineUnsupportedComponent("live-pusher");
const UniViewJSBridge$1 = /* @__PURE__ */ extend(ViewJSBridge, {
publishHandler(event, args, pageId) {
UniServiceJSBridge.subscribeHandler(event, args, pageId);
......@@ -21218,4 +21232,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
import { defineUnsupportedComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineUnsupportedComponent('ad-content-page')
import { defineUnsupportedComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineUnsupportedComponent('ad-draw')
import { ref, Ref, watch, onMounted, onBeforeUnmount } from 'vue'
import {
defineBuiltInComponent,
useAttrs,
useCustomEvent,
EmitEvent,
CustomEventTrigger,
} from '@dcloudio/uni-components'
//#region ad
class AdConfig {
private static _instance: AdConfig
static get instance() {
if (!AdConfig._instance) {
AdConfig._instance = new AdConfig()
AdConfig._instance._init()
}
return AdConfig._instance
}
static IC = 0
static IS = 0
private _adConfig: any | null = null
private _isLoading: Boolean = false
private _callbacks: any[] = []
private static readonly URL: string = 'https://hac1.dcloud.net.cn/ah5'
private static readonly KEY: string = 'uni_app_ad_config'
private static readonly CACHE_TIME: number = 1000 * 60 * 10
private static readonly ERROR_INVALID_ADPID: any = {
'-5002': 'invalid adpid',
}
constructor() {}
get adConfig() {
return this._adConfig
}
get isExpired() {
if (this._adConfig == null) {
return true
}
return Math.abs(Date.now() - this._adConfig.last) > AdConfig.CACHE_TIME
}
_init() {
var config = this._getConfig()
if (config === null || !config.last) {
return
}
if (!this.isExpired) {
this._adConfig = config.data
}
}
get(adpid: string, success: Function, fail: Function) {
AdConfig.IC++
if (this._adConfig != null) {
this._doCallback(adpid, success, fail)
if (this.isExpired) {
this._loadAdConfig(adpid)
}
return
}
this._callbacks.push({
adpid: adpid,
success: success,
fail: fail,
})
this._loadAdConfig(adpid)
}
_doCallback(adpid: string, success: Function, fail: Function) {
AdConfig.IS++
var { a, b } = this._adConfig
if (a[adpid]) {
success(b, a[adpid])
} else {
fail(AdConfig.ERROR_INVALID_ADPID)
}
}
_loadAdConfig(adpid: string) {
if (this._isLoading === true) {
return
}
this._isLoading = true
uni.request({
url: AdConfig.URL,
method: 'GET',
timeout: 8000,
data: {
d: location.hostname,
a: adpid,
},
dataType: 'json',
success: (res: any) => {
const rd = res.data
if (rd.ret === 0) {
const data = rd.data
this._adConfig = data
this._setConfig(data)
this._callbacks.forEach(({ adpid, success, fail }) => {
this._doCallback(adpid, success, fail)
})
} else {
this._callbacks.forEach((i) => {
i.fail({ errCode: rd.ret, errMsg: rd.msg })
})
}
this._callbacks = []
},
fail: (err) => {
this._callbacks.forEach((i) => {
i.fail(err)
})
this._callbacks = []
},
complete: (c) => {
this._isLoading = false
},
})
}
_getConfig() {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
var data = localStorage.getItem(AdConfig.KEY)
return data ? JSON.parse(data) : null
}
_setConfig(data: any) {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
localStorage.setItem(
AdConfig.KEY,
JSON.stringify({
last: Date.now(),
data: data,
})
)
}
}
class AdReport {
private static _instance: AdReport
static get instance() {
if (!AdReport._instance) {
AdReport._instance = new AdReport()
}
return AdReport._instance
}
private static readonly URL: string = 'https://has1.dcloud.net.cn/ahl'
private static readonly KEY: string = 'uni_app_ad_guid'
private _guid: string
constructor() {
var config = this._getConfig()
if (config && config.guid) {
this._guid = config.guid
return
}
this._guid = this._newGUID()
this._setConfig(this._guid)
}
get(data: any) {
this._process(
Object.assign(data, {
d: location.hostname,
i: this._guid,
})
)
}
_process(data: any) {
uni.request({
url: AdReport.URL,
method: 'GET',
data: data,
dataType: 'json',
success: () => {},
})
}
_newGUID() {
let guid = ''
const format = 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'
for (let i = 0; i < format.length; i++) {
if (format[i] === 'x') {
guid += ((Math.random() * 16) | 0).toString(16)
} else {
guid += format[i]
}
}
return guid.toUpperCase()
}
_getConfig() {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
var data = localStorage.getItem(AdReport.KEY)
return data ? JSON.parse(data) : null
}
_setConfig(guid: string) {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
localStorage.setItem(
AdReport.KEY,
JSON.stringify({
last: Date.now(),
guid: guid,
})
)
}
}
class AdScript {
private static _instance: AdScript
static get instance() {
if (!AdScript._instance) {
AdScript._instance = new AdScript()
}
return AdScript._instance
}
private _callback: Record<string, Array<any>>
private _cache: Record<string, any>
constructor() {
this._callback = {}
this._cache = {}
}
load(data: any, success: Function, fail: Function) {
const provider = data.provider
if (this._cache[provider] === undefined) {
this.loadScript(data)
}
if (this._cache[provider] === 1) {
success()
} else {
if (!this._callback[provider]) {
this._callback[provider] = []
}
this._callback[provider].push({
success,
fail,
})
}
}
loadScript(data: any) {
const provider = data.provider
this._cache[provider] = 0
var ads = document.createElement('script')
ads.setAttribute('id', 'uniad_provider' + provider)
const script = data.script
for (const var1 in script) {
ads.setAttribute(var1, script[var1])
}
ads.onload = () => {
this._cache[provider] = 1
this._callback[provider].forEach(({ success }) => {
success()
})
this._callback[provider].length = 0
}
ads.onerror = (err) => {
this._cache[provider] = undefined
this._callback[provider].forEach(({ fail }) => {
fail(err)
})
this._callback[provider].length = 0
}
document.body.append(ads)
}
}
const CHECK_RENDER_DELAY = 1000
const CHECK_RENDER_RETRY = 5
class AdRender {
private _checkTimer: number | null
private _pi: number = 0
private _pl: any[] = []
private _b: any = {}
private _checkTimerCount: number = 0
private _trigger: CustomEventTrigger
private _adpid: string
private _adpidWidescreen: string
private _widescreenWidth: number
private _currentAdpid: string
private _rootRef: any
constructor(
props: { adpid: string; adpidWidescreen: string; widescreenWidth: number },
trigger: CustomEventTrigger,
rootRef: Ref<HTMLElement | null>
) {
this._checkTimer = null
this._adpid = props.adpid
this._adpidWidescreen = props.adpidWidescreen
this._widescreenWidth = props.widescreenWidth
this._trigger = trigger
this._rootRef = rootRef
this._currentAdpid = this._adpid
}
get isWidescreen(): boolean {
return this._rootRef.value.style.clientWidth > this._widescreenWidth
}
load(adpid: string | null) {
this._currentAdpid =
adpid || (this.isWidescreen ? this._adpidWidescreen : this._adpid)
this._reset()
AdConfig.instance.get(
this._currentAdpid,
(b: any, a: Array<any>) => {
this._b = b
this._pl = a
this._renderAd()
},
(err: any) => {
this._trigger('error', {} as Event, err)
}
)
}
dispose() {
this._clearCheckTimer()
this._rootRef.value.innerHTML = ''
}
_renderAd() {
if (this._pi > this._pl.length - 1) {
return
}
const data = this._pl[this._pi]
const providerId = data.a1
this._b[providerId].provider = providerId
AdScript.instance.load(
this._b[providerId],
() => {
this._renderAdView(this._b[providerId], data)
},
(err: any) => {
this._trigger('error', {} as Event, err)
}
)
}
_renderAdView(provider: any, data: any) {
var randomId = this._randomId()
var adView = document.createElement('div')
adView.setAttribute('class', randomId)
this._rootRef.value.innerHTML = ''
this._rootRef.value.append(adView)
let bindThis = window
provider.s
.split('.')
.reduce((total: any, currentValue: any) => {
bindThis = total
return total[currentValue]
}, window)
.bind(bindThis)(data.a2, randomId, 2)
this._startCheckTimer()
}
_renderNext() {
if (this._pi >= this._pl.length - 1) {
return
}
this._pi++
this._renderAd()
}
_checkRender(): boolean {
var hasContent =
this._rootRef.value.children.length > 0 &&
this._rootRef.value.clientHeight > 40
if (hasContent) {
this.report(40)
}
return hasContent
}
_startCheckTimer() {
this._clearCheckTimer()
this._checkTimer = setInterval(() => {
this._checkTimerCount++
if (this._checkTimerCount >= CHECK_RENDER_RETRY) {
this._clearCheckTimer()
this._renderNext()
return
}
if (this._checkRender()) {
this._clearCheckTimer()
}
}, CHECK_RENDER_DELAY)
}
_clearCheckTimer() {
this._checkTimerCount = 0
if (this._checkTimer != null) {
window.clearInterval(this._checkTimer)
this._checkTimer = null
}
}
report(type: number) {
AdReport.instance.get({
h: (__uniConfig as any).compilerVersion, // TODO
a: this._currentAdpid,
at: type,
})
}
_randomId() {
var result = ''
for (let i = 0; i < 4; i++) {
result += ((65536 * (1 + Math.random())) | 0).toString(16).substring(1)
}
return '_u' + result
}
_reset() {
this._b = {}
this._pl = []
this._pi = 0
this._clearCheckTimer()
this._rootRef.value.innerHTML = ''
}
}
//#endregion
const DEFAULT_WIDESCREEN_WIDTH: number = 750
export default /*#__PURE__*/ defineBuiltInComponent({
inheritAttrs: false,
name: 'Ad',
props: {
adpid: {
type: String,
default: '',
},
adpidWidescreen: {
type: String,
default: '',
},
widescreenWidth: {
type: Number,
default: DEFAULT_WIDESCREEN_WIDTH,
},
},
setup(props, { emit }) {
const rootRef = ref(null)
const { $excludeAttrs, $listeners } = useAttrs({
excludeListeners: true,
})
const trigger = useCustomEvent<EmitEvent<typeof emit>>(rootRef, emit)
const ad = new AdRender(props, trigger, rootRef)
watch(
() => props.adpid,
(val) => {
ad.load(val)
}
)
onMounted(() => {
ad.load(null)
})
onBeforeUnmount(() => {
ad.dispose()
})
return () => {
const { adpid, adpidWidescreen, widescreenWidth } = props
return (
<>
<uni-ad
{...$listeners.value}
{...$excludeAttrs.value}
ref={rootRef}
adpid={adpid}
adpidWidescreen={adpidWidescreen}
widescreenWidth={widescreenWidth}
></uni-ad>
</>
)
}
},
})
import { ref, Ref, watch, onMounted, onBeforeUnmount } from 'vue'
import {
defineBuiltInComponent,
useAttrs,
useCustomEvent,
EmitEvent,
CustomEventTrigger,
} from '@dcloudio/uni-components'
import { defineUnsupportedComponent } from '@dcloudio/uni-components'
//#region ad
class AdConfig {
private static _instance: AdConfig
static get instance() {
if (!AdConfig._instance) {
AdConfig._instance = new AdConfig()
AdConfig._instance._init()
}
return AdConfig._instance
}
static IC = 0
static IS = 0
private _adConfig: any | null = null
private _isLoading: Boolean = false
private _callbacks: any[] = []
private static readonly URL: string = 'https://hac1.dcloud.net.cn/ah5'
private static readonly KEY: string = 'uni_app_ad_config'
private static readonly CACHE_TIME: number = 1000 * 60 * 10
private static readonly ERROR_INVALID_ADPID: any = {
'-5002': 'invalid adpid',
}
constructor() {}
get adConfig() {
return this._adConfig
}
get isExpired() {
if (this._adConfig == null) {
return true
}
return Math.abs(Date.now() - this._adConfig.last) > AdConfig.CACHE_TIME
}
_init() {
var config = this._getConfig()
if (config === null || !config.last) {
return
}
if (!this.isExpired) {
this._adConfig = config.data
}
}
get(adpid: string, success: Function, fail: Function) {
AdConfig.IC++
if (this._adConfig != null) {
this._doCallback(adpid, success, fail)
if (this.isExpired) {
this._loadAdConfig(adpid)
}
return
}
this._callbacks.push({
adpid: adpid,
success: success,
fail: fail,
})
this._loadAdConfig(adpid)
}
_doCallback(adpid: string, success: Function, fail: Function) {
AdConfig.IS++
var { a, b } = this._adConfig
if (a[adpid]) {
success(b, a[adpid])
} else {
fail(AdConfig.ERROR_INVALID_ADPID)
}
}
_loadAdConfig(adpid: string) {
if (this._isLoading === true) {
return
}
this._isLoading = true
uni.request({
url: AdConfig.URL,
method: 'GET',
timeout: 8000,
data: {
d: location.hostname,
a: adpid,
},
dataType: 'json',
success: (res: any) => {
const rd = res.data
if (rd.ret === 0) {
const data = rd.data
this._adConfig = data
this._setConfig(data)
this._callbacks.forEach(({ adpid, success, fail }) => {
this._doCallback(adpid, success, fail)
})
} else {
this._callbacks.forEach((i) => {
i.fail({ errCode: rd.ret, errMsg: rd.msg })
})
}
this._callbacks = []
},
fail: (err) => {
this._callbacks.forEach((i) => {
i.fail(err)
})
this._callbacks = []
},
complete: (c) => {
this._isLoading = false
},
})
}
_getConfig() {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
var data = localStorage.getItem(AdConfig.KEY)
return data ? JSON.parse(data) : null
}
_setConfig(data: any) {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
localStorage.setItem(
AdConfig.KEY,
JSON.stringify({
last: Date.now(),
data: data,
})
)
}
}
class AdReport {
private static _instance: AdReport
static get instance() {
if (!AdReport._instance) {
AdReport._instance = new AdReport()
}
return AdReport._instance
}
private static readonly URL: string = 'https://has1.dcloud.net.cn/ahl'
private static readonly KEY: string = 'uni_app_ad_guid'
private _guid: string
constructor() {
var config = this._getConfig()
if (config && config.guid) {
this._guid = config.guid
return
}
this._guid = this._newGUID()
this._setConfig(this._guid)
}
get(data: any) {
this._process(
Object.assign(data, {
d: location.hostname,
i: this._guid,
})
)
}
_process(data: any) {
uni.request({
url: AdReport.URL,
method: 'GET',
data: data,
dataType: 'json',
success: () => {},
})
}
_newGUID() {
let guid = ''
const format = 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'
for (let i = 0; i < format.length; i++) {
if (format[i] === 'x') {
guid += ((Math.random() * 16) | 0).toString(16)
} else {
guid += format[i]
}
}
return guid.toUpperCase()
}
_getConfig() {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
var data = localStorage.getItem(AdReport.KEY)
return data ? JSON.parse(data) : null
}
_setConfig(guid: string) {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
localStorage.setItem(
AdReport.KEY,
JSON.stringify({
last: Date.now(),
guid: guid,
})
)
}
}
class AdScript {
private static _instance: AdScript
static get instance() {
if (!AdScript._instance) {
AdScript._instance = new AdScript()
}
return AdScript._instance
}
private _callback: Record<string, Array<any>>
private _cache: Record<string, any>
constructor() {
this._callback = {}
this._cache = {}
}
load(data: any, success: Function, fail: Function) {
const provider = data.provider
if (this._cache[provider] === undefined) {
this.loadScript(data)
}
if (this._cache[provider] === 1) {
success()
} else {
if (!this._callback[provider]) {
this._callback[provider] = []
}
this._callback[provider].push({
success,
fail,
})
}
}
loadScript(data: any) {
const provider = data.provider
this._cache[provider] = 0
var ads = document.createElement('script')
ads.setAttribute('id', 'uniad_provider' + provider)
const script = data.script
for (const var1 in script) {
ads.setAttribute(var1, script[var1])
}
ads.onload = () => {
this._cache[provider] = 1
this._callback[provider].forEach(({ success }) => {
success()
})
this._callback[provider].length = 0
}
ads.onerror = (err) => {
this._cache[provider] = undefined
this._callback[provider].forEach(({ fail }) => {
fail(err)
})
this._callback[provider].length = 0
}
document.body.append(ads)
}
}
const CHECK_RENDER_DELAY = 1000
const CHECK_RENDER_RETRY = 5
class AdRender {
private _checkTimer: number | null
private _pi: number = 0
private _pl: any[] = []
private _b: any = {}
private _checkTimerCount: number = 0
private _trigger: CustomEventTrigger
private _adpid: string
private _adpidWidescreen: string
private _widescreenWidth: number
private _currentAdpid: string
private _rootRef: any
constructor(
props: { adpid: string; adpidWidescreen: string; widescreenWidth: number },
trigger: CustomEventTrigger,
rootRef: Ref<HTMLElement | null>
) {
this._checkTimer = null
this._adpid = props.adpid
this._adpidWidescreen = props.adpidWidescreen
this._widescreenWidth = props.widescreenWidth
this._trigger = trigger
this._rootRef = rootRef
this._currentAdpid = this._adpid
}
get isWidescreen(): boolean {
return this._rootRef.value.style.clientWidth > this._widescreenWidth
}
load(adpid: string | null) {
this._currentAdpid =
adpid || (this.isWidescreen ? this._adpidWidescreen : this._adpid)
this._reset()
AdConfig.instance.get(
this._currentAdpid,
(b: any, a: Array<any>) => {
this._b = b
this._pl = a
this._renderAd()
},
(err: any) => {
this._trigger('error', {} as Event, err)
}
)
}
dispose() {
this._clearCheckTimer()
this._rootRef.value.innerHTML = ''
}
_renderAd() {
if (this._pi > this._pl.length - 1) {
return
}
const data = this._pl[this._pi]
const providerId = data.a1
this._b[providerId].provider = providerId
AdScript.instance.load(
this._b[providerId],
() => {
this._renderAdView(this._b[providerId], data)
},
(err: any) => {
this._trigger('error', {} as Event, err)
}
)
}
_renderAdView(provider: any, data: any) {
var randomId = this._randomId()
var adView = document.createElement('div')
adView.setAttribute('class', randomId)
this._rootRef.value.innerHTML = ''
this._rootRef.value.append(adView)
let bindThis = window
provider.s
.split('.')
.reduce((total: any, currentValue: any) => {
bindThis = total
return total[currentValue]
}, window)
.bind(bindThis)(data.a2, randomId, 2)
this._startCheckTimer()
}
_renderNext() {
if (this._pi >= this._pl.length - 1) {
return
}
this._pi++
this._renderAd()
}
_checkRender(): boolean {
var hasContent =
this._rootRef.value.children.length > 0 &&
this._rootRef.value.clientHeight > 40
if (hasContent) {
this.report(40)
}
return hasContent
}
_startCheckTimer() {
this._clearCheckTimer()
this._checkTimer = setInterval(() => {
this._checkTimerCount++
if (this._checkTimerCount >= CHECK_RENDER_RETRY) {
this._clearCheckTimer()
this._renderNext()
return
}
if (this._checkRender()) {
this._clearCheckTimer()
}
}, CHECK_RENDER_DELAY)
}
_clearCheckTimer() {
this._checkTimerCount = 0
if (this._checkTimer != null) {
window.clearInterval(this._checkTimer)
this._checkTimer = null
}
}
report(type: number) {
AdReport.instance.get({
h: (__uniConfig as any).compilerVersion, // TODO
a: this._currentAdpid,
at: type,
})
}
_randomId() {
var result = ''
for (let i = 0; i < 4; i++) {
result += ((65536 * (1 + Math.random())) | 0).toString(16).substring(1)
}
return '_u' + result
}
_reset() {
this._b = {}
this._pl = []
this._pi = 0
this._clearCheckTimer()
this._rootRef.value.innerHTML = ''
}
}
//#endregion
const DEFAULT_WIDESCREEN_WIDTH: number = 750
export default /*#__PURE__*/ defineBuiltInComponent({
inheritAttrs: false,
name: 'Ad',
props: {
adpid: {
type: String,
default: '',
},
adpidWidescreen: {
type: String,
default: '',
},
widescreenWidth: {
type: Number,
default: DEFAULT_WIDESCREEN_WIDTH,
},
},
setup(props, { emit }) {
const rootRef = ref(null)
const { $excludeAttrs, $listeners } = useAttrs({
excludeListeners: true,
})
const trigger = useCustomEvent<EmitEvent<typeof emit>>(rootRef, emit)
const ad = new AdRender(props, trigger, rootRef)
watch(
() => props.adpid,
(val) => {
ad.load(val)
}
)
onMounted(() => {
ad.load(null)
})
onBeforeUnmount(() => {
ad.dispose()
})
return () => {
const { adpid, adpidWidescreen, widescreenWidth } = props
return (
<>
<uni-ad
{...$listeners.value}
{...$excludeAttrs.value}
ref={rootRef}
adpid={adpid}
adpidWidescreen={adpidWidescreen}
widescreenWidth={widescreenWidth}
></uni-ad>
</>
)
}
},
})
export default /*#__PURE__*/ defineUnsupportedComponent('ad')
import { defineUnsupportedComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineUnsupportedComponent('camera')
......@@ -5,4 +5,24 @@ import CoverView from './cover-view'
import CoverImage from './cover-image'
import Picker from './picker/index'
export { Video, WebView, Map, CoverView, CoverImage, Picker }
import Ad from './ad/index'
import AdContentPage from './ad-content-page/index'
import AdDraw from './ad-draw/index'
import Camera from './camera/index'
import LivePlayer from './live-player/index'
import LivePusher from './live-pusher/index'
export {
Video,
WebView,
Map,
CoverView,
CoverImage,
Picker,
//Unsupported
Ad,
AdContentPage,
AdDraw,
Camera,
LivePlayer,
LivePusher,
}
import { defineUnsupportedComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineUnsupportedComponent('live-player')
import { defineUnsupportedComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineUnsupportedComponent('live-pusher')
uni-ad-content-page {
display: block;
overflow: hidden;
}
uni-ad-content-page[hidden] {
display: none;
}
uni-ad-draw {
display: block;
overflow: hidden;
}
uni-ad-draw[hidden] {
display: none;
}
uni-camera {
display: block;
overflow: hidden;
}
uni-camera[hidden] {
display: none;
}
uni-live-player {
display: block;
overflow: hidden;
}
uni-live-player[hidden] {
display: none;
}
uni-live-pusher {
display: block;
overflow: hidden;
}
uni-live-pusher[hidden] {
display: none;
}
......@@ -6,6 +6,8 @@ var shared = require('@vue/shared');
const BUILT_IN_TAGS = [
'ad',
'ad-content-page',
'ad-draw',
'audio',
'button',
'camera',
......
......@@ -2,6 +2,8 @@ import { isHTMLTag, isSVGTag, hyphenate, camelize, extend, isString, isPlainObje
const BUILT_IN_TAGS = [
'ad',
'ad-content-page',
'ad-draw',
'audio',
'button',
'camera',
......
......@@ -2,6 +2,8 @@ import { isHTMLTag, isSVGTag } from '@vue/shared'
export const BUILT_IN_TAGS = [
'ad',
'ad-content-page',
'ad-draw',
'audio',
'button',
'camera',
......
......@@ -33,7 +33,8 @@ export function createConfig(
return {
base,
root: process.env.VITE_ROOT_DIR,
publicDir: config.publicDir || false,
// TODO 临时设置为__static__,屏蔽警告:https://github.com/vitejs/vite/blob/824d042535033a5c3d7006978c0d05c201cd1c25/packages/vite/src/node/server/middlewares/transform.ts#L125
publicDir: config.publicDir || '__static__',
define: createDefine(options),
resolve: createResolve(options, config),
logLevel: config.logLevel || 'warn',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册