提交 18dd1b72 编写于 作者: fxy060608's avatar fxy060608 提交者: qiang

wip(harmony): 支持 nvue=> vue

上级 20b25f10
......@@ -250,6 +250,8 @@ declare namespace UniNamespace {
leftWindow?: boolean
rightWindow?: boolean
eventChannel?: any
// 目前 app-harmony 专用
isNVueStyle?: boolean
}
interface PagesJsonPageOptions {
......
......@@ -11659,38 +11659,8 @@
var pako = {};
assign(pako, deflate, inflate, constants);
var pako_1 = pako;
var index$1 = 0;
function saveImage(dataURL, dirname, callback) {
var id2 = "".concat(Date.now()).concat(index$1++);
var array = dataURL.split(",");
var scheme = array[0];
var base64 = array[1];
var format = (scheme.match(/data:image\/(\S+?);/) || ["", "png"])[1].replace("jpeg", "jpg");
var fileName = "".concat(id2, ".").concat(format);
var tempFilePath = "".concat(dirname, "/").concat(fileName);
var i2 = dirname.indexOf("/");
var basePath = dirname.substring(0, i2);
var dirPath = dirname.substring(i2 + 1);
plus.io.resolveLocalFileSystemURL(basePath, function(entry) {
entry.getDirectory(dirPath, {
create: true,
exclusive: false
}, function(entry2) {
entry2.getFile(fileName, {
create: true,
exclusive: false
}, function(entry3) {
entry3.createWriter(function(writer) {
writer.onwrite = function() {
callback(null, tempFilePath);
};
writer.onerror = callback;
writer.seek(0);
writer.writeAsBinary(base64);
}, callback);
}, callback);
}, callback);
}, callback);
throw new Error("TODO: Implement");
}
function getSameOriginUrl(url) {
var a2 = document.createElement("a");
......@@ -14084,9 +14054,9 @@
if (image) {
c2d.drawImage.apply(
c2d,
// @ts-expect-error
// @ts-ignore
[image].concat(
// @ts-expect-error
// @ts-ignore
[...otherData.slice(4, 8)],
[...otherData.slice(0, 4)]
)
......@@ -14319,16 +14289,7 @@
});
return;
}
saveImage(res.data, dirname, (error, tempFilePath) => {
var errMsg = "toTempFilePath:".concat(error ? "fail" : "ok");
if (error) {
errMsg += " ".concat(error.message);
}
resolve({
errMsg,
tempFilePath
});
});
saveImage(res.data);
}
var methods = {
actionsChanged,
......@@ -21741,7 +21702,8 @@
// onReachBottomDistance,
statusbarHeight,
windowTop,
windowBottom
windowBottom,
nvueFlexDirection
} = _ref;
initPageInfo(route);
initSystemInfo(platform, pixelRatio2, windowWidth);
......@@ -21753,6 +21715,10 @@
if (disableScroll) {
document.addEventListener("touchmove", disableScrollListener);
}
if (nvueFlexDirection) {
document.body.setAttribute("nvue", "");
document.body.setAttribute("nvue-dir-".concat(nvueFlexDirection), "");
}
if (css) {
initPageCss(route);
} else {
......
......@@ -10931,7 +10931,7 @@ const createCanvasContext = defineSyncApi(API_CREATE_CANVAS_CONTEXT, (canvasId,
UniServiceJSBridge.emit(ON_ERROR, 'createCanvasContext:fail');
}
}, CreateCanvasContextProtocol);
defineAsyncApi(API_CANVAS_GET_IMAGE_DATA, ({ canvasId, x, y, width, height }, { resolve, reject }) => {
const canvasGetImageData = defineAsyncApi(API_CANVAS_GET_IMAGE_DATA, ({ canvasId, x, y, width, height }, { resolve, reject }) => {
const pageId = getPageIdByVm(getCurrentPageVm());
if (!pageId) {
reject();
......@@ -10959,7 +10959,7 @@ defineAsyncApi(API_CANVAS_GET_IMAGE_DATA, ({ canvasId, x, y, width, height }, {
height,
}, callback);
}, CanvasGetImageDataProtocol, CanvasGetImageDataOptions);
defineAsyncApi(API_CANVAS_PUT_IMAGE_DATA, ({ canvasId, data, x, y, width, height }, { resolve, reject }) => {
const canvasPutImageData = defineAsyncApi(API_CANVAS_PUT_IMAGE_DATA, ({ canvasId, data, x, y, width, height }, { resolve, reject }) => {
var pageId = getPageIdByVm(getCurrentPageVm());
if (!pageId) {
reject();
......@@ -10989,7 +10989,7 @@ defineAsyncApi(API_CANVAS_PUT_IMAGE_DATA, ({ canvasId, data, x, y, width, height
}
operate();
}, CanvasPutImageDataProtocol, CanvasPutImageDataOptions);
defineAsyncApi(API_CANVAS_TO_TEMP_FILE_PATH, ({ x = 0, y = 0, width, height, destWidth, destHeight, canvasId, fileType, quality, }, { resolve, reject }) => {
const canvasToTempFilePath = defineAsyncApi(API_CANVAS_TO_TEMP_FILE_PATH, ({ x = 0, y = 0, width, height, destWidth, destHeight, canvasId, fileType, quality, }, { resolve, reject }) => {
var pageId = getPageIdByVm(getCurrentPageVm());
if (!pageId) {
reject();
......@@ -12871,6 +12871,9 @@ function initPageOptions({ meta }) {
windowTop: 0,
// TODO tabBar.cover
windowBottom: 0,
nvueFlexDirection: meta.isNVueStyle && __uniConfig.nvue
? __uniConfig.nvue['flex-direction']
: undefined,
};
}
......@@ -13278,6 +13281,9 @@ function requireUTSPlugin(name) {
var uni$1 = {
__proto__: null,
canIUse: canIUse,
canvasGetImageData: canvasGetImageData,
canvasPutImageData: canvasPutImageData,
canvasToTempFilePath: canvasToTempFilePath,
createCanvasContext: createCanvasContext,
createSelectorQuery: createSelectorQuery,
getLocale: getLocale,
......
......@@ -89,5 +89,9 @@ function initPageOptions({ meta }: UniApp.UniRoute): PageNodeOptions {
windowTop: 0,
// TODO tabBar.cover
windowBottom: 0,
nvueFlexDirection:
meta.isNVueStyle && __uniConfig.nvue
? __uniConfig.nvue['flex-direction']
: undefined,
}
}
......@@ -93,6 +93,7 @@ export function onPageCreate({
statusbarHeight,
windowTop,
windowBottom,
nvueFlexDirection,
}: PageCreateData) {
initPageInfo(route)
initSystemInfo(platform, pixelRatio, windowWidth)
......@@ -109,6 +110,11 @@ export function onPageCreate({
document.addEventListener('touchmove', disableScrollListener)
}
if (nvueFlexDirection) {
document.body.setAttribute('nvue', '')
document.body.setAttribute(`nvue-dir-${nvueFlexDirection}`, '')
}
if (css) {
initPageCss(route)
} else {
......
......@@ -48,7 +48,7 @@ export function uniPagesJsonPlugin(): Plugin {
return {
code:
`import './${MANIFEST_JSON_JS}'\n` +
normalizeAppPagesJson(pagesJson),
normalizeAppPagesJson(pagesJson, process.env.UNI_PLATFORM),
map: { mappings: '' },
}
},
......
import { normalizeIdentifier, normalizePagePath } from '../../../utils'
export function definePageCode(pagesJson: Record<string, any>) {
export function definePageCode(
pagesJson: Record<string, any>,
platform: UniApp.PLATFORM = 'app'
) {
const importPagesCode: string[] = []
const definePagesCode: string[] = []
pagesJson.pages.forEach((page: UniApp.PagesJsonPageOptions) => {
if (page.style.isNVue) {
if (platform === 'app' && page.style.isNVue) {
return
}
const pagePath = page.path
const pageIdentifier = normalizeIdentifier(pagePath)
const pagePathWithExtname = normalizePagePath(pagePath, 'app')
const pagePathWithExtname = normalizePagePath(pagePath, platform)
if (pagePathWithExtname) {
if (process.env.UNI_APP_CODE_SPLITING) {
// 拆分页面
......
......@@ -3,8 +3,11 @@ import { defineNVuePageCode, definePageCode } from './definePage'
import { normalizeAppUniConfig } from './uniConfig'
import { normalizeAppUniRoutes } from './uniRoutes'
export function normalizeAppPagesJson(pagesJson: Record<string, any>) {
return definePageCode(pagesJson)
export function normalizeAppPagesJson(
pagesJson: Record<string, any>,
platform: UniApp.PLATFORM = 'app'
) {
return definePageCode(pagesJson, platform)
}
export function normalizeAppNVuePagesJson(pagesJson: Record<string, any>) {
......
......@@ -184,6 +184,15 @@ function normalizePages(
) {
pages.forEach((page) => {
page.style = normalizePageStyle(page.path, page.style!, platform)
if (platform === 'app-harmony') {
// 鸿蒙下强制 isNVue 为 false,增加额外的 isNVueStyle 来标记样式处理
// 因为已有的代码里太多根据 isNVue 来处理的逻辑,这些逻辑在鸿蒙都不适用
// 鸿蒙仅需要将 nvue 当做 vue,并补充 css 即可
if (page.style.isNVue) {
page.style.isNVue = false
;(page.style as any).isNVueStyle = true
}
}
})
if (platform !== 'app') {
return
......
......@@ -31,6 +31,8 @@ export interface PageNodeOptions {
statusbarHeight: number
windowTop: number
windowBottom: number
// 仅限 app-harmony 使用
nvueFlexDirection?: string
}
export interface PageCreateData extends PageNodeOptions {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册