提交 5582a287 编写于 作者: DCloud-yyl's avatar DCloud-yyl

同步代码@dev

上级 7d61842c
{
"id": "uni-createSelectorQuery",
"displayName": "uni-createSelectorQuery",
"version": "1.0.0",
"description": "uni-createSelectorQuery",
"keywords": [
"uni-createSelectorQuery"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-createSelectorQuery
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import { getCurrentPage, isFunction } from '@dcloudio/uni-runtime'
import {
CreateSelectorQuery,
NodeField,
NodeInfo,
NodesRef,
SelectorQuery,
SelectorQueryNodeInfoCallback,
} from '../interface.uts'
// TODO
// const ContextClasss = {
// canvas: CanvasContext,
// map: MapContext,
// video: VideoContext,
// editor: EditorContext,
// }
type RequestComponentInfoCallback = (result: Array<any>) => void
type SelectorQueryRequest = {
component: ComponentPublicInstance | null
selector: string
single: boolean
fields: NodeField
}
class NodesRefImpl implements NodesRef {
private _selectorQuery: SelectorQueryImpl
private _component: ComponentPublicInstance | null
private _selector: string
private _single: boolean
constructor(
selectorQuery: SelectorQueryImpl,
component: ComponentPublicInstance | null,
selector: string,
single: boolean,
) {
this._selectorQuery = selectorQuery
this._component = component
this._selector = selector
this._single = single
}
// @ts-expect-error
boundingClientRect(): SelectorQuery {
// @ts-expect-error
return this.boundingClientRect(null)
}
// @ts-expect-error
boundingClientRect(
callback: SelectorQueryNodeInfoCallback | 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: any) => void): SelectorQuery {
return this._selectorQuery
}
}
class SelectorQueryImpl implements SelectorQuery {
private _queue: Array<SelectorQueryRequest>
private _component: ComponentPublicInstance | null = null
private _queueCb: Array<SelectorQueryNodeInfoCallback | null>
private _nodesRef!: NodesRef
constructor(component: ComponentPublicInstance) {
this._component = component
this._queue = []
this._queueCb = []
}
// @ts-expect-error
exec(): NodesRef | null {
this._component?.$?.$waitNativeRender(() => {
requestComponentInfo(
this._component,
this._queue,
(res: Array<any>) => {
const queueCbs = this._queueCb
res.forEach((info: any, _index) => {
const queueCb = queueCbs[_index]
if (isFunction(queueCb)) {
queueCb!(info)
}
})
},
)
})
// TODO
return this._nodesRef
}
// @ts-expect-error
exec(callback: (result: Array<any>) => void | null): NodesRef | null {
this._component?.$?.$waitNativeRender(() => {
requestComponentInfo(
this._component,
this._queue,
(res: Array<any>) => {
const queueCbs = this._queueCb
res.forEach((info: any, _index) => {
const queueCb = queueCbs[_index]
if (isFunction(queueCb)) {
queueCb!(info)
}
})
if (isFunction(callback)) {
callback(res)
}
},
)
})
// TODO
return this._nodesRef
}
in(component: any | null): SelectorQuery {
// @ts-expect-error
if (component instanceof ComponentPublicInstance) {
this._component = component as ComponentPublicInstance
}
return this
}
select(selector: string): NodesRef {
this._nodesRef = new NodesRefImpl(this, this._component, selector, true)
return this._nodesRef
}
selectAll(selector: string): NodesRef {
this._nodesRef = new NodesRefImpl(
this,
this._component,
selector,
false,
)
return this._nodesRef
}
selectViewport(): NodesRef {
this._nodesRef = new NodesRefImpl(this, null, '', true)
return this._nodesRef
}
_push(
selector: string,
component: ComponentPublicInstance | null,
single: boolean,
fields: NodeField,
callback: SelectorQueryNodeInfoCallback | null,
) {
this._queue.push({
component,
selector,
single,
fields,
} as SelectorQueryRequest)
this._queueCb.push(callback)
}
}
function getNodeInfo(node: Element): NodeInfo {
const rect = node.getBoundingClientRect()
const nodeInfo = {
id: node.getAttribute('id')?.toString(),
dataset: null,
left: rect.left,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
width: rect.width,
height: rect.height,
} as NodeInfo
return nodeInfo
}
function querySelf(element: Element | null, selector: string): Element | null {
if (element == null || selector.length < 2) {
return null
}
const selectorType = selector.charAt(0)
const selectorName = selector.slice(1)
if (selectorType == '.' && element!.classList.includes(selectorName)) {
return element
}
if (selectorType == '#' && element!.getAttribute('id') == selectorName) {
return element
}
if (selector.toUpperCase() == element!.nodeName!.toUpperCase()) {
return element
}
return null
}
function requestComponentInfo(
vueComponent: ComponentPublicInstance | null,
queue: Array<SelectorQueryRequest>,
callback: RequestComponentInfoCallback,
) {
const result: Array<any> = []
const el = vueComponent?.$el
if (el != null) {
queue.forEach((item: SelectorQueryRequest) => {
if (item.single) {
let element = querySelf(el, item.selector)
if (element == null) {
element = el.querySelector(item.selector)
}
if (element != null) {
result.push(getNodeInfo(element))
}
} else {
const nodesInfo: Array<NodeInfo> = []
const element = querySelf(el, item.selector)
if (element != null) {
nodesInfo.push(getNodeInfo(element))
}
const findNodes = el.querySelectorAll(item.selector)
findNodes?.forEach((node: Element) => {
nodesInfo.push(getNodeInfo(node))
})
result.push(nodesInfo)
}
})
}
callback(result)
}
export const createSelectorQuery: CreateSelectorQuery =
function (): SelectorQuery {
return new SelectorQueryImpl(getCurrentPage()!)
}
export type CreateSelectorQuery = () => SelectorQuery
export type SelectorQueryNodeInfoCallback = (result: any) => void
export type NodeInfo = {
/**
* 节点的ID
*/
id: string | null
/**
* 节点的dataset
*/
dataset: any | null
/**
* 节点的左边界坐标
*/
left: number | null
/**
* 节点的右边界坐标
*/
right: number | null
/**
* 节点的上边界坐标
*/
top: number | null
/**
* 节点的下边界坐标
*/
bottom: number | null
/**
* 节点的宽度
*/
width: number | null
/**
* 节点的高度
*/
height: number | null
/**
* 节点的水平滚动位置
*/
scrollLeft: number | null
/**
* 节点的垂直滚动位置
*/
scrollTop: number | null
/**
* 节点的内容高度
*/
scrollHeight: number | null
/**
* 节点的内容宽度
*/
scrollWidth: number | null
/**
* 节点对应的 Context 对象
* @type MapContext | CanvasContext | VideoContext | EditorContext
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
context: any | null
}
export type NodeField = {
/**
* 是否返回节点 id
* @type boolean
*/
id: boolean | null
/**
* 是否返回节点 dataset
* @type boolean
*/
dataset: boolean | null
/**
* 是否返回节点布局位置(left right top bottom)
* @type boolean
*/
rect: boolean | null
/**
* 是否返回节点尺寸(width height)
* @type boolean
*/
size: boolean | null
/**
* 是否返回节点的 scrollLeft scrollTop,节点必须是 scroll-view 或者 viewport
* @type boolean
*/
scrollOffset: boolean | null
/**
* 指定属性名列表,返回节点对应属性名的当前属性值(只能获得组件文档中标注的常规属性值,id class style 和事件绑定的属性值不可获取)
*/
properties: string[] | null
/**
* 指定样式名列表,返回节点对应样式名的当前值
*/
computedStyle: string[] | null
/**
* 是否返回节点对应的 Context 对象
* @type boolean
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
context: boolean | null
}
export interface NodesRef {
/**
* 添加节点的布局位置的查询请求,相对于显示区域,以像素为单位
*/
boundingClientRect(
callback: SelectorQueryNodeInfoCallback | null,
): SelectorQuery
boundingClientRect(): SelectorQuery
/**
* 添加节点的滚动位置查询请求,以像素为单位
*/
scrollOffset(callback: SelectorQueryNodeInfoCallback): SelectorQuery
/**
* 获取节点的相关信息,需要获取的字段在fields中指定
*/
fields(
fields: NodeField,
callback: SelectorQueryNodeInfoCallback,
): SelectorQuery
/**
* 添加节点的 Context 对象查询请求
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
context(callback: SelectorQueryNodeInfoCallback): SelectorQuery
/**
* 获取 Node 节点实例。目前支持 Canvas 的获取。
*/
node(callback: (result: any) => void): SelectorQuery
}
export interface SelectorQuery {
/**
* 将选择器的选取范围更改为自定义组件component内
*/
in(component: any | null): SelectorQuery
/**
* 在当前页面下选择第一个匹配选择器selector的节点
*/
select(selector: string): NodesRef
/**
* 在当前页面下选择匹配选择器selector的所有节点
*/
selectAll(selector: string): NodesRef
/**
* 选择显示区域
*/
selectViewport(): NodesRef
/**
* 执行所有的请求
*/
exec(callback: (result: Array<any>) => void | null): NodesRef | null
exec(): NodesRef | null
}
export interface Uni {
/**
* 返回一个SelectorQuery对象实例
*
* @tutorial https://doc.dcloud.net.cn/uni-app-x/api/nodes-info.html
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "3.91"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
createSelectorQuery(): SelectorQuery
}
import { ComponentPublicInstance } from 'vue';
import { CreateWebviewContext, WebviewContext } from '../interface.uts';
export const createWebviewContext : CreateWebviewContext = function (webviewId : string.WebviewIdString, component ?: ComponentPublicInstance | null) : WebviewContext | null {
......
import { CreateWebviewContext, WebviewContext } from '../interface.uts';
export const createWebviewContext : CreateWebviewContext = function (webviewId : string.WebviewIdString, component ?: ComponentPublicInstance | null) : WebviewContext | null {
let webviewElement: UniWebViewElement | null = null;
let element: any | null = null;
if (component == null) {
element = UniSDKEngine.getJSElementById(webviewId)
} else {
element = component?.$el(webviewId)
}
if (element != null && (element instanceof UniWebViewElement)) {
webviewElement = (element as UniWebViewElement)
}
if (webviewElement == null) {
return null
}
return new WebviewContextImpl(webviewElement!)
}
class WebviewContextImpl implements WebviewContext {
@UTSiOS.keyword("weak")
private webviewElement : UniWebViewElement | null = null;
constructor(webviewElement : UniWebViewElement) {
this.webviewElement = webviewElement;
}
back() {
this.webviewElement?.back();
}
forward() {
this.webviewElement?.forward();
}
reload() {
this.webviewElement?.reload();
}
stop() {
this.webviewElement?.stop();
}
evalJS(js : string) {
this.webviewElement?.evalJS(js);
}
}
\ No newline at end of file
import { ComponentPublicInstance } from 'vue';
export type CreateWebviewContext = (webviewId : string.WebviewIdString, component ?: ComponentPublicInstance | null) => WebviewContext | null;
export interface WebviewContext {
......@@ -11,7 +9,12 @@ export interface WebviewContext {
* "osVer": "5.0",
* "uniVer": "x",
* "unixVer": "3.9.0"
* }
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* }
* }
* @uniVueVersion 2,3
......@@ -26,7 +29,12 @@ export interface WebviewContext {
* "osVer": "5.0",
* "uniVer": "x",
* "unixVer": "3.9.0"
* }
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* }
* }
* @uniVueVersion 2,3
......@@ -41,7 +49,12 @@ export interface WebviewContext {
* "osVer": "5.0",
* "uniVer": "x",
* "unixVer": "3.9.0"
* }
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* }
* }
* @uniVueVersion 2,3
......@@ -56,7 +69,12 @@ export interface WebviewContext {
* "osVer": "5.0",
* "uniVer": "x",
* "unixVer": "3.9.0"
* }
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* }
* }
* @uniVueVersion 2,3
......@@ -71,7 +89,12 @@ export interface WebviewContext {
* "osVer": "5.0",
* "uniVer": "x",
* "unixVer": "3.9.0"
* }
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* }
* }
* @uniVueVersion 2,3
......@@ -88,7 +111,12 @@ export interface Uni {
* "osVer": "5.0",
* "uniVer": "x",
* "unixVer": "3.9.0"
* }
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
......
{
"id": "uni-event",
"displayName": "uni-event",
"version": "1.0.0",
"description": "uni-event",
"keywords": [
"uni-event"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-event
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import { callFunction } from '@dcloudio/uni-runtime'
export class Emitter {
private map = new Map<string, Array<Function>>()
private onceMap = new Map<string, Array<boolean>>()
private _on(
eventName: string,
callback: Function,
once: boolean = false,
): void {
if (!this.map.has(eventName)) {
this.map.set(eventName, [])
}
if (!this.onceMap.has(eventName)) {
this.onceMap.set(eventName, [])
}
this.map.get(eventName)!.push(callback)
this.onceMap.get(eventName)!.push(once)
}
on(eventName: string, callback: Function): void {
this._on(eventName, callback)
}
once(eventName: string, callback: Function): void {
this._on(eventName, callback, true)
}
off(eventName: string, callback: Function | null = null): void {
if (callback === null) {
this.map.delete(eventName)
this.onceMap.delete(eventName)
return
}
const fns = this.map.get(eventName)
const onceFns = this.onceMap.get(eventName)
if (fns !== null) {
const index = fns!.lastIndexOf(callback)
if (index !== -1) {
fns!.splice(index, 1)
onceFns!.splice(index, 1)
}
}
}
emit(eventName: string, ...args: Array<any | null>): void {
const fns = this.map.get(eventName)
const onceFns = this.onceMap.get(eventName)
const removeFns: Array<Function> = []
if (fns !== null) {
fns!.forEach((fn, index) => {
try {
// TODO 条件编译
callFunction(fn, args)
} catch (e) {
// console.error(e)
}
if (onceFns![index]) {
removeFns.push(fn)
}
})
removeFns.forEach(fn => {
const index = fns!.indexOf(fn)
if (index !== -1) {
fns!.splice(index, 1)
onceFns!.splice(index, 1)
}
})
}
}
}
import { Emitter } from '../Emitter.uts'
import { $Emit, $Off, $On, $Once } from '../interface.uts'
const emitter = new Emitter()
export const $on = defineSyncApi<$On>('$on', (eventName, callback) => {
// TODO EventStopHandler
emitter.on(eventName, callback)
})
export const $off = defineSyncApi<$Off>('$off', (eventName, callback) => {
emitter.off(eventName, callback)
})
export const $once = defineSyncApi<$Once>('$once', (eventName, callback) => {
emitter.once(eventName, callback)
})
export const $emit = defineSyncApi<$Emit>('$emit', (eventName, arg) => {
// TODO muti args
emitter.emit(eventName, arg)
})
type $OnCallback = Function
export type $On = (eventName: string, callback: $OnCallback) => void
type $OnceCallback = Function
export type $Once = (eventName: string, callback: $OnceCallback) => void
type $OffCallback = Function
export type $Off = (eventName: string, callback?: $OffCallback | null) => void
export type $Emit = (eventName: string, args: any | null) => void
export interface Uni {
/**
* 监听自定义事件。事件可以由 uni.$emit 触发。回调函数会接收 uni.$emit 传递的参数。
*
* @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#on
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "3.91"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
$on(eventName: string, callback: $OnCallback): void
/**
* 移除自定义事件监听器。如果提供了事件名和回调,则只移除这个回调的监听器。
* 4.13+ 开始支持第二个参数为可选,如果仅提供事件名,则移除该事件的所有监听器。
* @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#off
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "3.91"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
$off(eventName: string, callback?: $OffCallback | null): void
/**
* 监听一个自定义事件。事件只触发一次,在第一次触发之后移除事件监听器。
*
* @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#once
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "3.91"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
$once(eventName: string, callback: $OnceCallback): void
/**
* 触发自定义事件,附加的参数会传递给事件监听器。
*
* @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#emit
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "3.91"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
$emit(eventName: string, args: any | null): void
}
......@@ -39,7 +39,7 @@
"app": {
"js": true,
"kotlin": true,
"swift": true
"swift": false
}
}
}
......
import { ExitOptions, ExitSuccess, Exit } from "../interface.uts"
import { ExitFailImpl } from "../unierror.uts"
/**
* 实现uni.exit
*/
export const exit : Exit = function (options: ExitOptions | null) {
let ret : ExitSuccess ={
errMsg: "exit:ok"
}
let err = new ExitFailImpl(12001);
options?.fail?.(err)
options?.success?.(ret)
options?.complete?.(ret)
// UTSAndroid.exit()
}
......@@ -61,12 +61,14 @@ export interface Uni {
* "android": {
* "osVer": "5.0",
* "uniVer": "3.8.15",
* "unixVer": "3.9.0"
* "unixVer": "3.9.0",
* "utsPlugin": "3.9.0"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* "unixVer": "x",
* "utsPlugin": "x"
* }
* },
* "web": {
......
......@@ -39,7 +39,7 @@
"app": {
"js": true,
"kotlin": true,
"swift": true
"swift": false
}
}
}
......
import File from 'java.io.File'
import ParcelFileDescriptor from 'android.os.ParcelFileDescriptor'
import { OpenFileOptions, OpenFileSuccessResult, OpenFileSyncOptions } from '../interface';
import { UniErrorSubject,FileSystemManagerFailImpl,FileSystemManagerUniErrors } from '../unierror';
export class FileDescriptorUtil {
public openMap : Map<string, File> = new Map()
public open(options : OpenFileOptions, file : File) {
let currentDispatcher = UTSAndroid.getDispatcher("main")
UTSAndroid.getDispatcher('io').async(function (_) {
try {
switch (options.flag) {
case 'a': // 打开文件用于追加。 如果文件不存在,则创建该文件
{
let ret = {
fd: this.open_a(file)
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
return
}
case 'ax': //类似于 'a',但如果路径存在,则失败
{
if (file.exists()) {
let err = new FileSystemManagerFailImpl(1301005);
options.fail?.(err)
options.complete?.(err)
} else {
if (file.parentFile?.exists() == false) {
let err = new FileSystemManagerFailImpl(1300002);
options.fail?.(err)
options.complete?.(err)
return
}
file.createNewFile()
let ret = {
fd: this.open_a(file)
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
}
return
}
case 'a+': //打开文件用于读取和追加。 如果文件不存在,则创建该文件
{
let ret = {
fd: this.open_ax(file)
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
return
}
case 'ax+': //类似于 'a+',但如果路径存在,则失败
{
if (file.exists()) {
let err = new FileSystemManagerFailImpl(1301005);
options.fail?.(err)
options.complete?.(err)
} else {
let ret = {
fd: this.open_ax(file)
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
}
return
}
case 'r': //打开文件用于读取。 如果文件不存在,则会发生异常
{
if (!file.exists()) {
let err = new FileSystemManagerFailImpl(1300002);
options.fail?.(err)
options.complete?.(err)
} else {
let mode = ParcelFileDescriptor.MODE_READ_ONLY
let pfd = ParcelFileDescriptor.open(file, mode);
let ret = {
fd: pfd.getFd().toString()
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
}
return
}
case 'r+': //打开文件用于读取和写入。 如果文件不存在,则会发生异常
{
if (!file.exists()) {
let err = new FileSystemManagerFailImpl(1300002);
options.fail?.(err)
options.complete?.(err)
} else {
let mode = ParcelFileDescriptor.MODE_READ_WRITE
let pfd = ParcelFileDescriptor.open(file, mode);
let ret = {
fd: pfd.getFd().toString()
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
}
return
}
case 'w'://打开文件用于写入。 如果文件不存在则创建文件,如果文件存在则截断文件
{
let ret = {
fd: this.open_w(file)
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
return
}
case 'wx'://类似于 'w',但如果路径存在,则失败
{
if (file.exists()) {
let err = new FileSystemManagerFailImpl(1301005);
options.fail?.(err)
options.complete?.(err)
} else {
let ret = {
fd: this.open_w(file)
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
}
return
}
case 'w+': //打开文件用于读取和写入。 如果文件不存在则创建文件,如果文件存在则截断文件
{
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE
let pfd = ParcelFileDescriptor.open(file, mode);
let ret = {
fd: pfd.getFd().toString()
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
return
}
case 'wx+': // 类似于 'w+',但如果路径存在,则失败
{
if (file.exists()) {
let err = new FileSystemManagerFailImpl(1301005);
options.fail?.(err)
options.complete?.(err)
} else {
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE
let pfd = ParcelFileDescriptor.open(file, mode);
let ret = {
fd: pfd.getFd().toString()
} as OpenFileSuccessResult
currentDispatcher.async(function (_) {
options.success?.(ret)
options.complete?.(ret)
}, null)
this.openMap.set(ret.fd, file)
}
return
}
}
} catch (e) {
let err = new FileSystemManagerFailImpl(1300201);
options.fail?.(err)
options.complete?.(err)
}
})
}
public openSync(options : OpenFileSyncOptions, file : File) : string {
let msgPrefix = "openSync:fail "
switch (options.flag) {
case 'a': // 打开文件用于追加。 如果文件不存在,则创建该文件
{
let fd = this.open_a(file)
this.openMap.set(fd, file)
return fd
}
case 'ax': //类似于 'a',但如果路径存在,则失败
{
if (file.exists()) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`)
} else {
if (file.parentFile?.exists() == false) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1300002]}`)
} else {
file.createNewFile()
let fd = this.open_a(file)
this.openMap.set(fd, file)
return fd
}
}
}
case 'a+': //打开文件用于读取和追加。 如果文件不存在,则创建该文件
{
let fd = this.open_ax(file)
this.openMap.set(fd, file)
return fd
}
case 'ax+': //类似于 'a+',但如果路径存在,则失败
{
if (file.exists()) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`)
} else {
let fd = this.open_ax(file)
this.openMap.set(fd, file)
return fd
}
}
case 'r': //打开文件用于读取。 如果文件不存在,则会发生异常
{
if (!file.exists()) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1300002]}`)
} else {
let mode = ParcelFileDescriptor.MODE_READ_ONLY
let pfd = ParcelFileDescriptor.open(file, mode);
let fd = pfd.getFd().toString()
this.openMap.set(fd, file)
return fd
}
}
case 'r+': //打开文件用于读取和写入。 如果文件不存在,则会发生异常
{
if (!file.exists()) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1300002]}`)
} else {
let mode = ParcelFileDescriptor.MODE_READ_WRITE
let pfd = ParcelFileDescriptor.open(file, mode);
let fd = pfd.getFd().toString()
this.openMap.set(fd, file)
return fd
}
}
case 'w'://打开文件用于写入。 如果文件不存在则创建文件,如果文件存在则截断文件
{
let fd = this.open_w(file)
this.openMap.set(fd, file)
return fd
}
case 'wx'://类似于 'w',但如果路径存在,则失败
{
if (file.exists()) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`)
} else {
let fd = this.open_w(file)
this.openMap.set(fd, file)
return fd
}
}
case 'w+': //打开文件用于读取和写入。 如果文件不存在则创建文件,如果文件存在则截断文件
{
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE
let pfd = ParcelFileDescriptor.open(file, mode);
let fd = pfd.getFd().toString()
this.openMap.set(fd, file)
return fd
}
case 'wx+': // 类似于 'w+',但如果路径存在,则失败
{
if (file.exists()) {
throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`)
} else {
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE
let pfd = ParcelFileDescriptor.open(file, mode);
let fd = pfd.getFd().toString()
this.openMap.set(fd, file)
return fd
}
}
}
return ""
}
open_a(file : File) : string {
try {
console.log(file.getPath())
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_APPEND
let pfd = ParcelFileDescriptor.open(file, mode);
return pfd.getFd().toString()
} catch (e : Exception) {
console.log(e)
}
return ""
}
open_ax(file : File) : string {
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_APPEND | ParcelFileDescriptor.MODE_READ_ONLY
let pfd = ParcelFileDescriptor.open(file, mode);
return pfd.getFd().toString()
}
open_w(file : File) : string {
let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE
let pfd = ParcelFileDescriptor.open(file, mode);
return pfd.getFd().toString()
}
}
\ No newline at end of file
{
"dependencies": [
"org.brotli:dec:0.1.2"
]
}
\ No newline at end of file
import { WriteFileOptions, ReadFileOptions, MkDirOptions, RmDirOptions, UnLinkOptions, ReadDirOptions, AccessOptions, RenameOptions, GetFileInfoOptions, CopyFileOptions, StatOptions } from "../interface.uts"
import { ReadFileSuccessResult, FileManagerSuccessResult, ReadDirSuccessResult, GetFileInfoSuccessResult, StatSuccessResult, FileStats, Stats } from "../interface.uts"
import { GetFileSystemManager, FileSystemManager } from "../interface.uts"
import { FileSystemManagerFailImpl, FileSystemManagerUniErrorSubject, FileSystemManagerUniErrors } from "../unierror.uts"
class InnerStats implements Stats {
/**
* 文件的类型和存取的权限,对应 POSIX stat.st_mode
* 注意android中,文件类型只包含是否是目录与文件,
* 另外在android中这里的权限指的是当前进程对文件或者文件夹是否有读,写,执行的权限,
* 这里没有与 POSIX stat.st_mode对应的组,其他人等相关权限的数据返回,只有所有者的相关权限
*/
mode : number = 0;
/**
* 文件大小,单位:B,对应 POSIX stat.st_size
*/
size : number = 0;
/**
* 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime
* 注意:android中由于系统限制无法获取该数据
*/
lastAccessedTime : number = 0;
/**
* 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime
*/
lastModifiedTime : number = 0;
/**
* @internal
*/
mIsFile : boolean = false;
constructor() {
}
/**
* 判断当前文件是否一个目录
*/
isDirectory() : boolean {
return !this.mIsFile
}
/**
* 判断当前文件是否一个普通文件
*/
isFile() : boolean {
return this.mIsFile
}
/**
* @internal
*/
override toLog() : any | null {
return this.toJSON()
}
/**
* @internal
*/
override toJSON() : any | null {
let jsonRet = new UTSJSONObject()
jsonRet.set("mode", this.mode)
jsonRet.set("size", this.size)
jsonRet.set("lastAccessedTime", this.lastAccessedTime)
jsonRet.set("lastModifiedTime", this.lastModifiedTime)
return jsonRet
}
}
function wrapFileStats(nativeStats) : FileStats {
let stats = new InnerStats()
stats.mIsFile = nativeStats.isFile
stats.mode = nativeStats.mode
stats.size = nativeStats.size
stats.lastAccessedTime = nativeStats.lastAccessedTime
stats.lastModifiedTime = nativeStats.lastModifiedTime
return new FileStats({ path: nativeStats.path, stats: stats })
}
function wrapStatsArgument(nativeStats) : FileStats {
// if ( nativeStats.length == 1 ){
// return wrapFileStats(nativeStats[0])
// }
return nativeStats.map( item => {
return wrapFileStats(item)
})
}
class JsFileSystemManager implements FileSystemManager {
public stat(options : StatOptions) {
nativeFileManager.stat(options.path,
options.recursive,
function (res) {
var ret = new StatSuccessResult({ stats: wrapStatsArgument(res), "errMsg": "stat:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code)
options.fail?.(err)
options.complete?.(err)
})
}
public getFileInfo(options : GetFileInfoOptions) {
if(options.digestAlgorithm == null || options.digestAlgorithm == undefined){
options.digestAlgorithm = "md5"
} else if (options.digestAlgorithm!.toLowerCase() != 'md5' && options.digestAlgorithm!.toLowerCase() != 'sha1') {
let err = new FileSystemManagerFailImpl(1300022);
options.fail?.(err)
options.complete?.(err)
return
}
nativeFileManager.getFileInfo(options.filePath,
options.digestAlgorithm,
function (res) {
var ret = new GetFileInfoSuccessResult({ size: res.size, digest: res.digest, errMsg: "getFileInfo:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// public copyFileSync(srcPath:string,destPath:string):number{
// return 0
// }
public copyFile(options : CopyFileOptions) {
nativeFileManager.copyFile(options.srcPath,
options.destPath,
function (res) {
var ret = new FileManagerSuccessResult({ "errMsg": "copyFile:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// public renameSync(oldPath:string,newPath:string):number{
// return 0
// }
public rename(options : RenameOptions) {
nativeFileManager.rename(options.oldPath,
options.newPath,
function (res) {
var ret = new FileManagerSuccessResult({ "errMsg": "rename:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// public accessSync(path: string):number{
// return 0
// }
public access(options : AccessOptions) {
nativeFileManager.access(options.path,
function (res) {
var ret = new FileManagerSuccessResult({ "errMsg": "access:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// readdirSync(dirPath: string): string[]|null{
// return null
// }
public readdir(options : ReadDirOptions) {
nativeFileManager.readdir(options.dirPath,
function (res) {
var ret = new ReadDirSuccessResult(res);
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// public rmdirSync(dirPath: string,recursive:boolean): number {
// return 0
// }
// public mkdirSync(dirPath: string,recursive:boolean): number {
// return 0
// }
public rmdir(options : RmDirOptions) {
nativeFileManager.rmdir(options.dirPath,
options.recursive,
function (res) {
var ret = new FileManagerSuccessResult({ "errMsg": "rmdir:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
public mkdir(options : MkDirOptions) {
nativeFileManager.mkdir(options.dirPath,
options.recursive,
function (res) {
var ret = new FileManagerSuccessResult({ "errMsg": "mkdir:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// unlinkSync(filePath: string): number {
// return 0
// }
public unlink(options : UnLinkOptions) {
nativeFileManager.unlink(
options.filePath,
function (res) {
var ret = new FileManagerSuccessResult({ "errMsg": "unlink:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// public readFileSync(filePath: string,encoding:string): string|null{
// }
public readFile(options : ReadFileOptions) {
nativeFileManager.readFile(options.encoding,
options.filePath,
function (res) {
var ret = new ReadFileSuccessResult(res);
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
// public writeFileSync(filePath: string,data:string): number{
// return 0
// }
public writeFile(options : WriteFileOptions) {
nativeFileManager.writeFile(options.filePath,
options.encoding,
options.data,
function () {
var ret = new FileManagerSuccessResult({ "errMsg": "writeFile:ok" });
options.success?.(ret)
options.complete?.(ret)
},
function (code) {
let err = new FileSystemManagerFailImpl(code);
options.fail?.(err)
options.complete?.(err)
})
}
}
export const getFileSystemManager : GetFileSystemManager = function () : FileSystemManager {
return new JsFileSystemManager()
};
\ No newline at end of file
......@@ -39,7 +39,7 @@
"app": {
"js": false,
"kotlin": true,
"swift": false
"swift": true
}
}
}
......
......@@ -85,7 +85,7 @@ function getBaseInfo(filterArray : Array<string>) : GetAppBaseInfoResult {
result.version = AppBaseInfoDeviceUtil.getAppInnerVersion();
}
if (filterArray.indexOf("appWgtVersion") != -1) {
result.appWgtVersion = AppBaseInfoDeviceUtil.getAppWgtVersion();
result.appWgtVersion = AppBaseInfoDeviceUtil.getAppVersion();
}
if (filterArray.indexOf("bundleId") != -1) {
result.bundleId = AppBaseInfoDeviceUtil.getBundleId();
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册