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

feat(app): add onPageReady

上级 7cac403c
......@@ -727,8 +727,12 @@ var serviceContext = (function (vue) {
}, page.$page.id, callback);
}
let lastLogTime = 0;
function formatLog(module, ...args) {
return `[${Date.now()}][${module}]:${args
const now = Date.now();
const diff = lastLogTime ? now - lastLogTime : 0;
lastLogTime = now;
return `[${now}][${diff}ms][${module}]:${args
.map((arg) => JSON.stringify(arg))
.join(' ')}`;
}
......
......@@ -153,8 +153,12 @@
const n = parseFloat(val);
return isNaN(n) ? val : n;
};
let lastLogTime = 0;
function formatLog(module, ...args) {
return `[${Date.now()}][${module}]\uFF1A${args.map((arg) => JSON.stringify(arg)).join(" ")}`;
const now = Date.now();
const diff = lastLogTime ? now - lastLogTime : 0;
lastLogTime = now;
return `[${now}][${diff}ms][${module}]\uFF1A${args.map((arg) => JSON.stringify(arg)).join(" ")}`;
}
function getCustomDataset(el) {
return extend({}, el.dataset, el.__uniDataset);
......@@ -15926,6 +15930,22 @@
elements.set(id2, element);
return element;
}
const pageReadyCallbacks = [];
let isPageReady = false;
function onPageReady(callback) {
if (isPageReady) {
return callback();
}
pageReadyCallbacks.push(callback);
}
function setPageReady() {
{
console.log(formatLog("setPageReady", pageReadyCallbacks.length));
}
isPageReady = true;
pageReadyCallbacks.forEach((fn) => fn());
pageReadyCallbacks.length = 0;
}
function onPageCreated() {
}
function onPageCreate({
......@@ -15945,9 +15965,6 @@
initPageInfo(route);
initSystemInfo(platform, pixelRatio2, windowWidth);
initPageElement();
if (css) {
initPageCss(route);
}
const pageId = plus.webview.currentWebview().id;
window.__id__ = pageId;
document.title = `${route}[${pageId}]`;
......@@ -15957,6 +15974,11 @@
} else if (onPageScroll || onPageReachBottom) {
initPageScroll(onPageScroll, onPageReachBottom, onReachBottomDistance);
}
if (css) {
initPageCss(route);
} else {
setPageReady();
}
}
function initPageInfo(route) {
window.__PAGE_INFO__ = {
......@@ -15974,13 +15996,15 @@
createElement(0, "div", -1, -1).$ = document.getElementById("app");
}
function initPageCss(route) {
{
console.log(formatLog("initPageCss", route + ".css"));
}
const element = document.createElement("link");
element.type = "text/css";
element.rel = "stylesheet";
element.href = route + ".css";
element.onload = function() {
window.dispatchEvent(new CustomEvent("updateview"));
};
element.onload = setPageReady;
element.onerror = setPageReady;
document.head.appendChild(element);
}
function initCssVar(statusbarHeight, windowTop, windowBottom) {
......@@ -16018,6 +16042,17 @@
publish();
}
function onVdSync(actions) {
const firstAction = actions[0];
if (firstAction[0] === ACTION_TYPE_PAGE_CREATE) {
onPageCreateSync(firstAction);
} else {
onPageReady(() => onPageUpdateSync(actions));
}
}
function onPageCreateSync(action) {
return onPageCreate(action[1]);
}
function onPageUpdateSync(actions) {
const dictAction = actions[0];
const getDict = createGetDict(dictAction[0] === ACTION_TYPE_DICT ? dictAction[1] : []);
actions.forEach((action) => {
......
......@@ -10,19 +10,39 @@ import {
ACTION_TYPE_ADD_EVENT,
ACTION_TYPE_REMOVE_EVENT,
ACTION_TYPE_SET_TEXT,
PageCreateAction,
} from '@dcloudio/uni-shared'
import { UniNodeJSONMinify } from 'packages/uni-shared/src/vdom/Node'
import { ACTION_TYPE_DICT, DictAction, Dictionary } from '../../../constants'
import { createGetDict, decodeNodeJson } from './decodeActions'
import { $, createElement, onPageCreate, onPageCreated } from './page'
import {
$,
createElement,
onPageCreate,
onPageCreated,
onPageReady,
} from './page'
import { flushPostActionJobs } from './scheduler'
export function onVdSync(actions: (PageAction | DictAction)[]) {
const firstAction = actions[0]
// page create
if (firstAction[0] === ACTION_TYPE_PAGE_CREATE) {
onPageCreateSync(firstAction)
} else {
onPageReady(() => onPageUpdateSync(actions))
}
}
function onPageCreateSync(action: PageCreateAction) {
return onPageCreate(action[1])
}
function onPageUpdateSync(actions: (PageAction | DictAction)[]) {
const dictAction = actions[0]
const getDict = createGetDict(
dictAction[0] === ACTION_TYPE_DICT ? (dictAction[1] as Dictionary) : []
)
actions.forEach((action) => {
switch (action[0]) {
case ACTION_TYPE_PAGE_CREATE:
......
......@@ -64,6 +64,24 @@ export function createElement(
return element
}
const pageReadyCallbacks: (() => void)[] = []
let isPageReady = false
export function onPageReady(callback: () => void) {
if (isPageReady) {
return callback()
}
pageReadyCallbacks.push(callback)
}
function setPageReady() {
if (__DEV__) {
console.log(formatLog('setPageReady', pageReadyCallbacks.length))
}
isPageReady = true
pageReadyCallbacks.forEach((fn) => fn())
pageReadyCallbacks.length = 0
}
export function onPageCreated() {}
export function onPageCreate({
......@@ -85,10 +103,6 @@ export function onPageCreate({
// 初始化页面容器元素
initPageElement()
if (css) {
initPageCss(route)
}
const pageId = plus.webview.currentWebview().id!
;(window as any).__id__ = pageId
document.title = `${route}[${pageId}]`
......@@ -100,6 +114,12 @@ export function onPageCreate({
} else if (onPageScroll || onPageReachBottom) {
initPageScroll(onPageScroll, onPageReachBottom, onReachBottomDistance)
}
if (css) {
initPageCss(route)
} else {
setPageReady()
}
}
function initPageInfo(route: string) {
......@@ -125,13 +145,15 @@ function initPageElement() {
}
function initPageCss(route: string) {
if (__DEV__) {
console.log(formatLog('initPageCss', route + '.css'))
}
const element = document.createElement('link')
element.type = 'text/css'
element.rel = 'stylesheet'
element.href = route + '.css'
element.onload = function () {
window.dispatchEvent(new CustomEvent('updateview'))
}
element.onload = setPageReady
element.onerror = setPageReady
document.head.appendChild(element)
}
......
......@@ -37,9 +37,13 @@ export default function vueFactory(exports) {
*/
var capitalize$1 = cacheStringFunction$1(str => str.charAt(0).toUpperCase() + str.slice(1));
var lastLogTime = 0;
function formatLog(module, ...args) {
return "[".concat(Date.now(), "][").concat(module, "]\uFF1A").concat(args.map(arg => JSON.stringify(arg)).join(' '));
var now = Date.now();
var diff = lastLogTime ? now - lastLogTime : 0;
lastLogTime = now;
return "[".concat(now, "][").concat(diff, "ms][").concat(module, "]\uFF1A").concat(args.map(arg => JSON.stringify(arg)).join(' '));
}
class DOMException extends Error {
......
......@@ -4,8 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@vue/shared');
let lastLogTime = 0;
function formatLog(module, ...args) {
return `[${Date.now()}][${module}]:${args
const now = Date.now();
const diff = lastLogTime ? now - lastLogTime : 0;
lastLogTime = now;
return `[${now}][${diff}ms][${module}]:${args
.map((arg) => JSON.stringify(arg))
.join(' ')}`;
}
......
import { camelize, extend, isString, isPlainObject, isArray, isHTMLTag, isSVGTag, capitalize, hyphenate } from '@vue/shared';
let lastLogTime = 0;
function formatLog(module, ...args) {
return `[${Date.now()}][${module}]:${args
const now = Date.now();
const diff = lastLogTime ? now - lastLogTime : 0;
lastLogTime = now;
return `[${now}][${diff}ms][${module}]:${args
.map((arg) => JSON.stringify(arg))
.join(' ')}`;
}
......
let lastLogTime = 0
export function formatLog(module: string, ...args: any[]) {
return `[${Date.now()}][${module}]:${args
const now = Date.now()
const diff = lastLogTime ? now - lastLogTime : 0
lastLogTime = now
return `[${now}][${diff}ms][${module}]:${args
.map((arg) => JSON.stringify(arg))
.join(' ')}`
}
......@@ -40,7 +40,7 @@
"@types/sass": "^1.16.0"
},
"uni-app": {
"compilerVersion": "3.1.23"
"compilerVersion": "3.2.0"
},
"gitHead": "4dd0e035b52584ff028ee3028c46adc555be0529"
}
import { UserConfig } from 'vite'
import { VitePluginUniResolvedOptions } from '..'
import {
parseManifestJsonOnce,
runByHBuilderX,
} from '../../../uni-cli-shared/dist'
export function createDefine({
platform,
}: VitePluginUniResolvedOptions): UserConfig['define'] {
const manifestJson = parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
return {
__VUE_PROD_DEVTOOLS__: false,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.UNI_APP_ID': JSON.stringify(manifestJson.appid || ''),
'process.env.UNI_APP_NAME': JSON.stringify(manifestJson.name || ''),
'process.env.UNI_PLATFORM': JSON.stringify(platform),
'process.env.RUN_BY_HBUILDERX': runByHBuilderX(),
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册