提交 7c0ad0d9 编写于 作者: D DCloud_LXH

feat(harmony): build api

上级 465a2b61
......@@ -11659,8 +11659,38 @@
var pako = {};
assign(pako, deflate, inflate, constants);
var pako_1 = pako;
var index$1 = 0;
function saveImage(dataURL, dirname, callback) {
throw new Error("TODO: Implement");
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);
}
function getSameOriginUrl(url) {
var a2 = document.createElement("a");
......@@ -14054,9 +14084,9 @@
if (image) {
c2d.drawImage.apply(
c2d,
// @ts-ignore
// @ts-expect-error
[image].concat(
// @ts-ignore
// @ts-expect-error
[...otherData.slice(4, 8)],
[...otherData.slice(0, 4)]
)
......@@ -14289,7 +14319,16 @@
});
return;
}
saveImage(res.data);
saveImage(res.data, dirname, (error, tempFilePath) => {
var errMsg = "toTempFilePath:".concat(error ? "fail" : "ok");
if (error) {
errMsg += " ".concat(error.message);
}
resolve({
errMsg,
tempFilePath
});
});
}
var methods = {
actionsChanged,
......
......@@ -20,14 +20,11 @@ import { UTSHarmony as UTSHarmony1 } from "../../../resources/rawfile/uni-app/un
import { UTSHarmony as UTSHarmony2 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UTSHarmony as UTSHarmony3, getCurrentPage } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UTSHarmony as UTSHarmony4 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UTSHarmony as UTSHarmony5, getCurrentPage as getCurrentPage2 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UTSHarmony as UTSHarmony6 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UTSHarmony as UTSHarmony5 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UTSHarmony } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { UniServiceJSBridge, getCurrentPageVm as getCurrentPageVm2, getPageIdByVm as getPageIdByVm2 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import dataPreferences from '@ohos.data.preferences';
import deviceInfo1 from '@ohos.deviceInfo';
import fs1 from '@ohos.file.fs';
import { getCurrentPageVm as getCurrentPageVm1, getPageIdByVm as getPageIdByVm1, isFunction as isFunction1, requestComponentInfo, resolveComponentInstance as resolveComponentInstance1 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { getEnv, Emitter as Emitter2 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { getOSRuntime, getCurrentPage as getCurrentPage1 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
import { getRealPath as getRealPath1 } from "../../../resources/rawfile/uni-app/uni-app-harmony-framework-dev";
......@@ -244,142 +241,6 @@ export function initUniExtApi(APP_ID: string) {
}
return new ServiceIntersectionObserver(getCurrentPageVm()!, _options as CreateIntersectionObserverOptions);
});
type CreateSelectorQuery = () => SelectorQuery;
type SelectorQueryNodeInfoCallback = (result: Object) => void;
class NodeField extends UTSObject {
id: boolean | null = null;
dataset: boolean | null = null;
rect: boolean | null = null;
size: boolean | null = null;
scrollOffset: boolean | null = null;
properties: string[] | null = null;
computedStyle: string[] | null = null;
context: boolean | null = null;
node: boolean | null = null;
}
interface NodesRef {
boundingClientRect(callback: SelectorQueryNodeInfoCallback | null): SelectorQuery;
boundingClientRect(): SelectorQuery;
scrollOffset(callback: SelectorQueryNodeInfoCallback): SelectorQuery;
fields(fields: NodeField, callback: SelectorQueryNodeInfoCallback): SelectorQuery;
context(callback: SelectorQueryNodeInfoCallback): SelectorQuery;
node(callback: (result: Object) => void): SelectorQuery;
}
interface SelectorQuery {
in(component: Object | null): SelectorQuery;
select(selector: string): NodesRef;
selectAll(selector: string): NodesRef;
selectViewport(): NodesRef;
exec(callback: (result: Array<Object>) => void | null): NodesRef | null;
exec(): NodesRef | null;
}
interface SelectorQueryRequest {
component: ComponentPublicInstance | undefined | null;
selector: string;
single: boolean;
fields: NodeField;
}
class NodesRefImpl implements NodesRef {
private _selectorQuery: SelectorQueryImpl;
private _component: ComponentPublicInstance | null | undefined;
private _selector: string;
private _single: boolean;
constructor(selectorQuery: SelectorQueryImpl, component: ComponentPublicInstance | null | undefined, selector: string, single: boolean){
this._selectorQuery = selectorQuery;
this._component = component;
this._selector = selector;
this._single = single;
}
boundingClientRect(callback: SelectorQueryNodeInfoCallback | null = null): SelectorQuery {
this._selectorQuery._push(this._selector, this._component, this._single, {
id: true,
dataset: true,
rect: true,
size: true
} as NodeField, callback);
return this._selectorQuery;
}
fields(fields: NodeField, callback: SelectorQueryNodeInfoCallback): SelectorQuery {
this._selectorQuery._push(this._selector, this._component, this._single, fields, callback);
return this._selectorQuery;
}
scrollOffset(callback: SelectorQueryNodeInfoCallback): SelectorQuery {
this._selectorQuery._push(this._selector, this._component, this._single, {
id: true,
dataset: true,
scrollOffset: true
} as NodeField, callback);
return this._selectorQuery;
}
context(callback: SelectorQueryNodeInfoCallback): SelectorQuery {
this._selectorQuery._push(this._selector, this._component, this._single, {
context: true
} as NodeField, callback);
return this._selectorQuery;
}
node(callback: (result: Object) => void): SelectorQuery {
this._selectorQuery._push(this._selector, this._component, this._single, {
node: true
} as NodeField, callback);
return this._selectorQuery;
}
}
class SelectorQueryImpl implements SelectorQuery {
private _page: ComponentPublicInstance;
private _queue: Array<SelectorQueryRequest>;
private _component?: ComponentPublicInstance = undefined;
private _queueCb: Array<SelectorQueryNodeInfoCallback>;
private _nodesRef?: NodesRef;
constructor(page: ComponentPublicInstance){
this._page = page;
this._queue = [];
this._queueCb = [];
}
exec(callback: ((result: Array<Object>) => void | null) | null = null): NodesRef | null {
requestComponentInfo(this._page, this._queue, (res: Array<Object>)=>{
const queueCbs = this._queueCb;
res.forEach((result: Object, index: number)=>{
const queueCb = queueCbs[index];
if (isFunction1(queueCb)) {
queueCb(result);
}
});
if (isFunction1(callback)) {
callback!(res);
}
});
return this._nodesRef as NodesRef;
}
in(component: ComponentPublicInstance | ComponentInternalInstance | null = null): SelectorQuery {
this._component = resolveComponentInstance1(component);
return this;
}
select(selector: string): NodesRef {
return this._nodesRef = new NodesRefImpl(this, this._component, selector, true) as NodesRef;
}
selectAll(selector: string): NodesRef {
return this._nodesRef = new NodesRefImpl(this, this._component, selector, false) as NodesRef;
}
selectViewport(): NodesRef {
return this._nodesRef = new NodesRefImpl(this, null, '', true) as NodesRef;
}
_push(selector: string, component: ComponentPublicInstance | undefined | null, single: boolean, fields: NodeField, callback: SelectorQueryNodeInfoCallback | null = null) {
this._queue.push({
component,
selector,
single,
fields
} as SelectorQueryRequest);
callback && this._queueCb.push(callback);
}
}
const createSelectorQuery = defineSyncApi<CreateSelectorQuery>('createSelectorQuery', (context: ComponentInternalInstance | ComponentPublicInstance | null = null)=>{
context = resolveComponentInstance1(context);
if (context && !getPageIdByVm1(context)) {
context = null;
}
return new SelectorQueryImpl(context || getCurrentPageVm1()!) as SelectorQuery;
});
class GetAppBaseInfoOptions extends UTSObject {
filter!: Array<string>;
}
......@@ -1377,156 +1238,6 @@ export function initUniExtApi(APP_ID: string) {
errMsg: ''
} as ClosePreviewImageSuccess);
}) as ClosePreviewImage;
type SetNavigationBarColorErrorCode = 4;
interface SetNavigationBarColorFail extends IUniError {
errCode: SetNavigationBarColorErrorCode;
}
class SetNavigationBarColorOptions extends UTSObject {
frontColor!: '#ffffff' | '#000000';
backgroundColor!: string.ColorString;
success: SetNavigationBarColorSuccessCallback | null = null;
fail: SetNavigationBarColorFailCallback | null = null;
complete: SetNavigationBarColorCompleteCallback | null = null;
}
type SetNavigationBarColorSuccess = AsyncApiSuccessResult;
type SetNavigationBarColorSuccessCallback = (result: SetNavigationBarColorSuccess) => void;
type SetNavigationBarColorFailCallback = (error: SetNavigationBarColorFail) => void;
type SetNavigationBarColorComplete = AsyncApiResult;
type SetNavigationBarColorCompleteCallback = (res: SetNavigationBarColorComplete) => void;
type SetNavigationBarColor = (options: SetNavigationBarColorOptions) => void;
type SetNavigationBarTitleErrorCode = 4;
interface SetNavigationBarTitleFail extends IUniError {
errCode: SetNavigationBarTitleErrorCode;
}
class SetNavigationBarTitleOptions extends UTSObject {
title!: string;
success: SetNavigationBarTitleSuccessCallback | null = null;
fail: SetNavigationBarTitleFailCallback | null = null;
complete: SetNavigationBarTitleCompleteCallback | null = null;
}
type SetNavigationBarTitleSuccess = AsyncApiSuccessResult;
type SetNavigationBarTitleSuccessCallback = (result: SetNavigationBarTitleSuccess) => void;
type SetNavigationBarTitleFailCallback = (error: SetNavigationBarTitleFail) => void;
type SetNavigationBarTitleComplete = AsyncApiResult;
type SetNavigationBarTitleCompleteCallback = (res: SetNavigationBarTitleComplete) => void;
type SetNavigationBarTitle = (options: SetNavigationBarTitleOptions) => void;
const FRONT_COLORS = [
'#ffffff',
'#000000'
];
const API_SET_NAVIGATION_BAR_COLOR = 'setNavigationBarColor';
const SetNavigationBarColorProtocol = new Map<string, ProtocolOptions>([
[
'frontColor',
{
type: 'string',
required: true,
validator (frontColor: Object) {
if (FRONT_COLORS.indexOf(frontColor as string) === -1) {
return `invalid frontColor "${frontColor}"`;
}
return;
}
}
],
[
'backgroundColor',
{
type: 'string',
required: true
}
]
]);
const API_SET_NAVIGATION_BAR_TITLE = 'setNavigationBarTitle';
const SetNavigationBarTitleProtocol = new Map<string, ProtocolOptions>([
[
'title',
{
type: 'string',
required: true
}
]
]);
interface TitleNView {
titleText: string;
autoBackButton?: boolean;
}
interface BackButton {
color?: string;
}
interface PlusWebviewWebviewTitleNViewStyles {
backgroundColor?: string;
titleColor?: string;
titleNView?: TitleNView;
backButton?: BackButton;
}
interface Webview {
getStyle: () => PlusWebviewWebviewTitleNViewStyles | null;
setStyle: (style: PlusWebviewWebviewTitleNViewStyles) => void;
}
interface $page {
statusBarStyle: 'dark' | 'light';
}
interface Page {
$getAppWebview: () => Webview | null;
$page: $page;
}
const getWebview = (page: Page): Webview | null =>{
const webview = page.$getAppWebview();
return webview;
};
const setNavigationBarColor: SetNavigationBarColor = defineAsyncApi<SetNavigationBarColorOptions, SetNavigationBarColorSuccess>(API_SET_NAVIGATION_BAR_COLOR, (options: SetNavigationBarColorOptions, res: ApiExcutor<SetNavigationBarColorSuccess>)=>{
const page = getCurrentPage2() as Page;
if (!page) {
return res.reject(`getCurrentPages is empty`);
}
const webview = getWebview(page);
if (webview) {
const styles: PlusWebviewWebviewTitleNViewStyles = {};
if (options.frontColor) {
styles.titleColor = options.frontColor;
}
if (options.backgroundColor) {
styles.backgroundColor = options.backgroundColor;
}
const statusBarStyle = options.frontColor === '#000000' ? 'dark' : 'light';
UTSHarmony5.navigator.setStatusBarStyle(statusBarStyle, styles.backgroundColor ? styles.backgroundColor : undefined);
page.$page.statusBarStyle = statusBarStyle;
const style = webview.getStyle();
if (style && style.titleNView) {
if (style.titleNView.autoBackButton) {
styles.backButton = styles.backButton || {};
styles.backButton.color = options.frontColor;
}
webview.setStyle({
titleNView: styles as TitleNView
} as PlusWebviewWebviewTitleNViewStyles);
}
res.resolve();
} else {
res.reject();
}
}, SetNavigationBarColorProtocol) as SetNavigationBarColor;
const setNavigationBarTitle: SetNavigationBarTitle = defineAsyncApi<SetNavigationBarTitleOptions, SetNavigationBarTitleSuccess>(API_SET_NAVIGATION_BAR_TITLE, (options: SetNavigationBarTitleOptions, res: ApiExcutor<SetNavigationBarTitleSuccess>)=>{
const page = getCurrentPage2() as Page;
if (!page) {
return res.reject(`getCurrentPages is empty`);
}
const webview = getWebview(page);
if (webview) {
const style = webview.getStyle();
if (style && style.titleNView) {
webview.setStyle({
titleNView: {
titleText: options.title
} as TitleNView
} as PlusWebviewWebviewTitleNViewStyles);
}
res.resolve();
} else {
res.reject();
}
}, SetNavigationBarTitleProtocol) as SetNavigationBarTitle;
type Request<T> = (param: RequestOptions<T>) => RequestTask;
class RequestOptions<T> extends UTSObject {
url!: string;
......@@ -2211,58 +1922,6 @@ export function initUniExtApi(APP_ID: string) {
});
return new DownloadTask1(downloadTask);
}, DownloadFileApiProtocol, DownloadFileApiOptions) as DownloadFile;
type PageScrollToErrorCode = 4;
interface PageScrollToFail extends IUniError {
errCode: PageScrollToErrorCode;
}
type PageScrollToSuccess = AsyncApiSuccessResult;
type PageScrollToSuccessCallback = (result: PageScrollToSuccess) => void;
type PageScrollToFailCallback = (result: PageScrollToFail) => void;
type PageScrollToComplete = AsyncApiResult;
type PageScrollToCompleteCallback = (result: PageScrollToComplete) => void;
class PageScrollToOptions extends UTSObject {
scrollTop: number | null = null;
selector: string | null = null;
offsetTop: number | null = null;
duration: number | null = null;
success: PageScrollToSuccessCallback | null = null;
fail: PageScrollToFailCallback | null = null;
complete: PageScrollToCompleteCallback | null = null;
}
type PageScrollTo = (options: PageScrollToOptions) => Promise<PageScrollToSuccess> | null;
const API_PAGE_SCROLL_TO = 'pageScrollTo';
const PageScrollToProtocol = new Map<string, ProtocolOptions>([
[
'scrollTo',
{
type: 'number'
}
],
[
'selector',
{
type: 'string'
}
],
[
'duration',
{
type: 'number'
}
]
]);
const PageScrollToApiOptions: ApiOptions<PageScrollToOptions> = {
formatArgs: new Map<string, number>([
[
'duration',
300
]
])
};
const pageScrollTo: PageScrollTo = defineAsyncApi<PageScrollToOptions, PageScrollToSuccess>(API_PAGE_SCROLL_TO, (options: PageScrollToOptions, res: ApiExcutor<PageScrollToSuccess>)=>{
const pageId = getPageIdByVm2(getCurrentPageVm2()!)! as number;
UniServiceJSBridge.invokeViewMethod(API_PAGE_SCROLL_TO, options, pageId, res.resolve);
}, PageScrollToProtocol, PageScrollToApiOptions) as PageScrollTo;
type PromptErrorCode = 1 | 1001;
interface IPromptError extends IUniError {
errCode: PromptErrorCode;
......@@ -2619,7 +2278,7 @@ export function initUniExtApi(APP_ID: string) {
const API_RPX2PX = 'rpx2px';
const EPS = 1e-4;
const rpx2px: Rpx2px = defineSyncApi<number>(API_RPX2PX, (number: number): number =>{
const windowStage: harmonyWindow1.WindowStage = UTSHarmony6.getWindowStage();
const windowStage: harmonyWindow1.WindowStage = UTSHarmony5.getWindowStage();
let windowWidthInVp: number = 384;
let windowWidthInPx: number = 1344;
if (windowStage) {
......@@ -2823,7 +2482,6 @@ export function initUniExtApi(APP_ID: string) {
getClipboardData: GetClipboardData;
setClipboardData: SetClipboardData;
createIntersectionObserver: CreateIntersectionObserver;
createSelectorQuery: CreateSelectorQuery;
getAppBaseInfo: GetAppBaseInfo;
getDeviceInfo: GetDeviceInfo;
getSystemInfo: GetSystemInfo;
......@@ -2836,12 +2494,9 @@ export function initUniExtApi(APP_ID: string) {
getImageInfo: GetImageInfo;
chooseVideo: ChooseVideo;
getVideoInfo: GetVideoInfo;
setNavigationBarColor: SetNavigationBarColor;
setNavigationBarTitle: SetNavigationBarTitle;
request: Request<Object>;
uploadFile: UploadFile;
downloadFile: DownloadFile;
pageScrollTo: PageScrollTo;
showToast: ShowToast;
hideToast: HideToast;
showLoading: ShowLoading;
......@@ -2864,7 +2519,6 @@ export function initUniExtApi(APP_ID: string) {
getClipboardData,
setClipboardData,
createIntersectionObserver,
createSelectorQuery,
getAppBaseInfo,
getDeviceInfo,
getSystemInfo,
......@@ -2877,12 +2531,9 @@ export function initUniExtApi(APP_ID: string) {
getImageInfo,
chooseVideo,
getVideoInfo,
setNavigationBarColor,
setNavigationBarTitle,
request,
uploadFile,
downloadFile,
pageScrollTo,
showToast,
hideToast,
showLoading,
......
......@@ -8081,6 +8081,27 @@ function once(fn, ctx = null) {
return res;
});
}
function callOptions(options, data) {
options = options || {};
if (isString(data)) {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (isFunction(options.success)) {
options.success(data);
}
}
else {
if (isFunction(options.fail)) {
options.fail(data);
}
}
if (isFunction(options.complete)) {
options.complete(data);
}
}
const encode$1 = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode$1) {
......@@ -9748,6 +9769,9 @@ function initLaunchOptions({ path, query, referrerInfo, }) {
return extend({}, launchOptions$1);
}
function operateVideoPlayer(videoId, pageId, type, data) {
// TODO: Implement
}
const TEMP_PATH = ''; // TODO 需要从applicationContext获取
const enterOptions = /*#__PURE__*/ createLaunchOptions();
const launchOptions = /*#__PURE__*/ createLaunchOptions();
......@@ -9760,6 +9784,19 @@ function getEnterOptions() {
return extend({}, enterOptions);
}
const validator = [
{
name: 'id',
type: String,
required: true,
},
];
/* export const API_CREATE_AUDIO_CONTEXT = 'createAudioContext'
export type API_TYPE_CREATE_AUDIO_CONTEXT = typeof uni.createAudioContext
export const CreateAudioContextProtocol = validator */
const API_CREATE_VIDEO_CONTEXT = 'createVideoContext';
const API_CREATE_MAP_CONTEXT = 'createMapContext';
const CreateMapContextProtocol = validator;
const API_CREATE_CANVAS_CONTEXT = 'createCanvasContext';
const CreateCanvasContextProtocol = [
{
......@@ -9772,6 +9809,131 @@ const CreateCanvasContextProtocol = [
type: Object,
},
];
validator.concat({
name: 'componentInstance',
type: Object,
});
class VideoContext {
id;
pageId;
constructor(id, pageId) {
this.id = id;
this.pageId = pageId;
}
play() {
operateVideoPlayer(this.id, this.pageId);
}
pause() {
operateVideoPlayer(this.id, this.pageId);
}
stop() {
operateVideoPlayer(this.id, this.pageId);
}
seek(position) {
operateVideoPlayer(this.id, this.pageId);
}
sendDanmu(args) {
operateVideoPlayer(this.id, this.pageId);
}
playbackRate(rate) {
operateVideoPlayer(this.id, this.pageId);
}
requestFullScreen(args = {}) {
operateVideoPlayer(this.id, this.pageId);
}
exitFullScreen() {
operateVideoPlayer(this.id, this.pageId);
}
showStatusBar() {
operateVideoPlayer(this.id, this.pageId);
}
hideStatusBar() {
operateVideoPlayer(this.id, this.pageId);
}
}
defineSyncApi(API_CREATE_VIDEO_CONTEXT, (id, context) => {
if (context) {
return new VideoContext(id, getPageIdByVm(context));
}
return new VideoContext(id, getPageIdByVm(getCurrentPageVm()));
});
const operateMapWrap = (id, pageId, type, options) => {
};
class MapContext {
id;
pageId;
constructor(id, pageId) {
this.id = id;
this.pageId = pageId;
}
getCenterLocation(options) {
operateMapWrap(this.id, this.pageId);
}
moveToLocation(options) {
operateMapWrap(this.id, this.pageId);
}
getScale(options) {
operateMapWrap(this.id, this.pageId);
}
getRegion(options) {
operateMapWrap(this.id, this.pageId);
}
includePoints(options) {
operateMapWrap(this.id, this.pageId);
}
translateMarker(options) {
operateMapWrap(this.id, this.pageId);
}
$getAppMap() {
{
return plus.maps.getMapById(this.pageId + '-map-' + this.id);
}
}
addCustomLayer(options) {
operateMapWrap(this.id, this.pageId);
}
removeCustomLayer(options) {
operateMapWrap(this.id, this.pageId);
}
addGroundOverlay(options) {
operateMapWrap(this.id, this.pageId);
}
removeGroundOverlay(options) {
operateMapWrap(this.id, this.pageId);
}
updateGroundOverlay(options) {
operateMapWrap(this.id, this.pageId);
}
initMarkerCluster(options) {
operateMapWrap(this.id, this.pageId);
}
addMarkers(options) {
operateMapWrap(this.id, this.pageId);
}
removeMarkers(options) {
operateMapWrap(this.id, this.pageId);
}
moveAlong(options) {
operateMapWrap(this.id, this.pageId);
}
setLocMarkerIcon(options) {
operateMapWrap(this.id, this.pageId);
}
openMapApp(options) {
operateMapWrap(this.id, this.pageId);
}
on(name, callback) {
operateMapWrap(this.id, this.pageId);
}
}
defineSyncApi(API_CREATE_MAP_CONTEXT, (id, context) => {
if (context) {
return new MapContext(id, getPageIdByVm(context));
}
return new MapContext(id, getPageIdByVm(getCurrentPageVm()));
}, CreateMapContextProtocol);
function getInt(name, defaultValue) {
return function (value, params) {
......@@ -10853,6 +11015,206 @@ defineAsyncApi(API_CANVAS_TO_TEMP_FILE_PATH, ({ x = 0, y = 0, width, height, des
});
}, CanvasToTempFilePathProtocol, CanvasToTempFilePathOptions);
// let eventReady = false
let index$1 = 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$1++);
data.callbackId = callbackId;
optionsCache[callbackId] = options;
}
UniServiceJSBridge.invokeViewMethod(`editor.${componentId}`, {
type,
data,
}, pageId, ({ callbackId, data }) => {
if (needCallOptions) {
callOptions(optionsCache[callbackId], data);
delete optionsCache[callbackId];
}
});
}
class EditorContext {
id;
pageId;
constructor(id, pageId) {
this.id = id;
this.pageId = pageId;
}
format(name, value) {
this._exec('format', {
name,
value,
});
}
insertDivider() {
this._exec('insertDivider');
}
insertImage(options) {
this._exec('insertImage', options);
}
insertText(options) {
this._exec('insertText', options);
}
setContents(options) {
this._exec('setContents', options);
}
getContents(options) {
this._exec('getContents', options);
}
clear(options) {
this._exec('clear', options);
}
removeFormat(options) {
this._exec('removeFormat', options);
}
undo(options) {
this._exec('undo', options);
}
redo(options) {
this._exec('redo', options);
}
blur(options) {
this._exec('blur', options);
}
getSelectionText(options) {
this._exec('getSelectionText', options);
}
scrollIntoView(options) {
this._exec('scrollIntoView', options);
}
_exec(method, options) {
operateEditor(this.id, this.pageId, method, options);
}
}
const ContextClasss = {
canvas: CanvasContext,
map: MapContext,
video: VideoContext,
editor: EditorContext,
};
function convertContext(result) {
if (result && result.contextInfo) {
const { id, type, page } = result.contextInfo;
const ContextClass = ContextClasss[type];
result.context = new ContextClass(id, page);
delete result.contextInfo;
}
}
class NodesRef {
_selectorQuery;
_component;
_selector;
_single;
constructor(selectorQuery, component, selector, single) {
this._selectorQuery = selectorQuery;
this._component = component;
this._selector = selector;
this._single = single;
}
boundingClientRect(callback) {
this._selectorQuery._push(this._selector, this._component, this._single, {
id: true,
dataset: true,
rect: true,
size: true,
}, callback);
return this._selectorQuery;
}
fields(fields, callback) {
this._selectorQuery._push(this._selector, this._component, this._single, fields, callback);
return this._selectorQuery;
}
scrollOffset(callback) {
this._selectorQuery._push(this._selector, this._component, this._single, {
id: true,
dataset: true,
scrollOffset: true,
}, callback);
return this._selectorQuery;
}
context(callback) {
this._selectorQuery._push(this._selector, this._component, this._single, {
context: true,
}, callback);
return this._selectorQuery;
}
node(callback) {
this._selectorQuery._push(this._selector, this._component, this._single, {
node: true,
}, callback);
return this._selectorQuery;
}
}
class SelectorQuery {
_page;
_queue;
_component = undefined;
_queueCb;
_nodesRef;
constructor(page) {
this._page = page;
this._queue = [];
this._queueCb = [];
}
exec(callback) {
requestComponentInfo(this._page, this._queue, (res) => {
const queueCbs = this._queueCb;
res.forEach((result, index) => {
if (isArray(result)) {
result.forEach(convertContext);
}
else {
convertContext(result);
}
const queueCb = queueCbs[index];
if (isFunction(queueCb)) {
queueCb.call(this, result);
}
});
// isFn(callback) &&
if (isFunction(callback)) {
callback.call(this, res);
}
});
// TODO
return this._nodesRef;
}
in(component) {
this._component = resolveComponentInstance(component);
return this;
}
select(selector) {
return (this._nodesRef = new NodesRef(this, this._component, selector, true));
}
selectAll(selector) {
return (this._nodesRef = new NodesRef(this, this._component, selector, false));
}
selectViewport() {
return (this._nodesRef = new NodesRef(this, null, '', true));
}
_push(selector, component, single, fields, callback) {
this._queue.push({
component,
selector,
single,
fields,
});
this._queueCb.push(callback);
}
}
const createSelectorQuery = defineSyncApi('createSelectorQuery', (context) => {
context = resolveComponentInstance(context);
if (context && !getPageIdByVm(context)) {
context = null;
}
return new SelectorQuery(context || getCurrentPageVm());
});
const API_ON_TAB_BAR_MID_BUTTON_TAP = 'onTabBarMidButtonTap';
const API_SET_LOCALE = 'setLocale';
......@@ -11106,6 +11468,59 @@ function createNormalizeUrl(type) {
};
}
const FRONT_COLORS = ['#ffffff', '#000000'];
const API_SET_NAVIGATION_BAR_COLOR = 'setNavigationBarColor';
const SetNavigationBarColorOptions = {
formatArgs: {
animation(animation, params) {
if (!animation) {
animation = { duration: 0, timingFunc: 'linear' };
}
params.animation = {
duration: animation.duration || 0,
timingFunc: animation.timingFunc || 'linear',
};
},
},
};
const SetNavigationBarColorProtocol = {
frontColor: {
type: String,
required: true,
validator(frontColor) {
if (FRONT_COLORS.indexOf(frontColor) === -1) {
return `invalid frontColor "${frontColor}"`;
}
},
},
backgroundColor: {
type: String,
required: true,
},
animation: Object,
};
const API_SET_NAVIGATION_BAR_TITLE = 'setNavigationBarTitle';
const SetNavigationBarTitleProtocol = {
title: {
type: String,
required: true,
},
};
const API_SHOW_NAVIGATION_BAR_LOADING = 'showNavigationBarLoading';
const API_HIDE_NAVIGATION_BAR_LOADING = 'hideNavigationBarLoading';
const API_PAGE_SCROLL_TO = 'pageScrollTo';
const PageScrollToProtocol = {
scrollTop: Number,
selector: String,
duration: Number,
};
const PageScrollToOptions = {
formatArgs: {
duration: 300,
},
};
const IndexProtocol = {
index: {
type: Number,
......@@ -11776,6 +12191,20 @@ function initDebugRefresh(isTab, path, query) {
};
}
function getCurrentWebview() {
const page = getCurrentPage();
if (page) {
return page.$getAppWebview();
}
return null;
}
function getWebview(page) {
if (page) {
return page.$getAppWebview();
}
return getCurrentWebview();
}
const downgrade = 'Harmony' === 'Android' ;
const ANI_SHOW = 'pop-in';
const ANI_DURATION = 300;
......@@ -12755,6 +13184,77 @@ function _switchTab({ url, path, query, }) {
});
}
const pageScrollTo = defineAsyncApi(API_PAGE_SCROLL_TO, (options, { resolve }) => {
const pageId = getPageIdByVm(getCurrentPageVm());
UniServiceJSBridge.invokeViewMethod(API_PAGE_SCROLL_TO, options, pageId, resolve);
}, PageScrollToProtocol, PageScrollToOptions);
const setNavigationBarTitle = defineAsyncApi(API_SET_NAVIGATION_BAR_TITLE, ({ __page__, title }, { resolve, reject }) => {
const webview = getWebview(__page__);
if (webview) {
const style = webview.getStyle();
if (style && style.titleNView) {
webview.setStyle({
titleNView: {
titleText: title,
},
});
}
resolve();
}
else {
reject();
}
}, SetNavigationBarTitleProtocol);
defineAsyncApi(API_SHOW_NAVIGATION_BAR_LOADING, (_, { resolve }) => {
plus.nativeUI.showWaiting('', {
modal: false,
});
resolve();
});
defineAsyncApi(API_HIDE_NAVIGATION_BAR_LOADING, (_, { resolve }) => {
plus.nativeUI.closeWaiting();
resolve();
});
function setPageStatusBarStyle(statusBarStyle) {
const pages = getCurrentPages();
if (!pages.length) {
return;
}
// 框架内部页面跳转会从这里获取style配置
pages[pages.length - 1].$page.statusBarStyle = statusBarStyle;
}
const setNavigationBarColor = defineAsyncApi(API_SET_NAVIGATION_BAR_COLOR, ({ __page__, frontColor, backgroundColor }, { resolve, reject }) => {
const webview = getWebview(__page__);
if (webview) {
const styles = {};
if (frontColor) {
styles.titleColor = frontColor;
}
if (backgroundColor) {
styles.backgroundColor = backgroundColor;
}
const statusBarStyle = frontColor === '#000000' ? 'dark' : 'light';
plus.navigator.setStatusBarStyle(statusBarStyle);
// 用户调用api时同时改变当前页配置,这样在系统调用设置时,可以避免覆盖用户设置
setPageStatusBarStyle(statusBarStyle);
const style = webview.getStyle();
if (style && style.titleNView) {
if (style.titleNView.autoBackButton) {
styles.backButton = styles.backButton || {};
styles.backButton.color = frontColor;
}
webview.setStyle({
titleNView: styles,
});
}
resolve();
}
else {
reject();
}
}, SetNavigationBarColorProtocol, SetNavigationBarColorOptions);
const pluginDefines = {};
function registerUTSPlugin(name, define) {
pluginDefines[name] = define;
......@@ -12779,18 +13279,22 @@ var uni$1 = {
__proto__: null,
canIUse: canIUse,
createCanvasContext: createCanvasContext,
createSelectorQuery: createSelectorQuery,
getLocale: getLocale,
hideTabBar: hideTabBar,
hideTabBarRedDot: hideTabBarRedDot,
navigateBack: navigateBack,
navigateTo: navigateTo,
onLocaleChange: onLocaleChange,
pageScrollTo: pageScrollTo,
reLaunch: reLaunch,
redirectTo: redirectTo,
registerUTSPlugin: registerUTSPlugin,
removeTabBarBadge: removeTabBarBadge,
requireUTSPlugin: requireUTSPlugin,
setLocale: setLocale,
setNavigationBarColor: setNavigationBarColor,
setNavigationBarTitle: setNavigationBarTitle,
setTabBarBadge: setTabBarBadge,
setTabBarItem: setTabBarItem,
setTabBarStyle: setTabBarStyle,
......
......@@ -18,5 +18,14 @@ export {
getLocale,
onLocaleChange,
createCanvasContext,
createSelectorQuery,
canvasGetImageData,
canvasPutImageData,
canvasToTempFilePath,
} from '@dcloudio/uni-api'
export {
pageScrollTo,
setNavigationBarColor,
setNavigationBarTitle,
} from '@dcloudio/uni-app-plus/service/api'
export { requireUTSPlugin, registerUTSPlugin } from './plugin/uts'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册