Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
24b82e82
U
uni-app
项目概览
DCloud
/
uni-app
通知
699
Star
38703
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
24b82e82
编写于
1月 18, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(uni-app-x web): 暴露UTSJSONObject、UniError到全局
上级
55251d36
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
301 addition
and
262 deletion
+301
-262
packages/uni-h5/src/helpers/utils.ts
packages/uni-h5/src/helpers/utils.ts
+12
-0
packages/uni-h5/src/index.ts
packages/uni-h5/src/index.ts
+36
-0
packages/uni-h5/src/platform/uts/UTSJSONObject.ts
packages/uni-h5/src/platform/uts/UTSJSONObject.ts
+193
-0
packages/uni-h5/src/platform/uts/UniError.ts
packages/uni-h5/src/platform/uts/UniError.ts
+31
-0
packages/uni-uts-v1/lib/javascript/dist/index.js
packages/uni-uts-v1/lib/javascript/dist/index.js
+1
-1
packages/uni-uts-v1/lib/javascript/lib/runtime/index.js
packages/uni-uts-v1/lib/javascript/lib/runtime/index.js
+27
-260
packages/uni-uts-v1/lib/kotlin/dist/index.js
packages/uni-uts-v1/lib/kotlin/dist/index.js
+1
-1
未找到文件。
packages/uni-h5/src/helpers/utils.ts
浏览文件 @
24b82e82
...
...
@@ -12,3 +12,15 @@ export function isInWindows(vm: ComponentPublicInstance) {
}
return
false
}
export
function
getType
(
val
:
any
):
string
{
return
Object
.
prototype
.
toString
.
call
(
val
).
slice
(
8
,
-
1
).
toLowerCase
()
}
export
function
isPlainObject
(
val
:
any
):
boolean
{
if
(
val
==
null
||
typeof
val
!==
'
object
'
)
{
return
false
}
const
proto
=
Object
.
getPrototypeOf
(
val
)
return
proto
===
Object
.
prototype
||
proto
===
null
}
packages/uni-h5/src/index.ts
浏览文件 @
24b82e82
//#if _X_
import
{
UniError
}
from
'
./platform/uts/UniError
'
import
{
UTSJSONObject
}
from
'
./platform/uts/UTSJSONObject
'
function
getGlobal
()
{
// cross-platform
if
(
typeof
globalThis
!==
'
undefined
'
)
{
return
globalThis
}
// worker
if
(
typeof
self
!==
'
undefined
'
)
{
return
self
}
// browser
if
(
typeof
window
!==
'
undefined
'
)
{
return
window
}
// nodejs
if
(
typeof
global
!==
'
undefined
'
)
{
return
global
}
throw
new
Error
(
'
unable to locate global object
'
)
}
const
realGlobal
=
getGlobal
()
if
(
!
realGlobal
.
globalThis
)
{
// @ts-ignore
realGlobal
.
globalThis
=
realGlobal
}
// @ts-ignore
globalThis
.
UTSJSONObject
=
UTSJSONObject
// @ts-ignore
globalThis
.
UniError
=
UniError
//#endif
export
{
Button
,
Canvas
,
...
...
packages/uni-h5/src/platform/uts/UTSJSONObject.ts
0 → 100644
浏览文件 @
24b82e82
import
{
getType
,
isPlainObject
}
from
'
../../helpers/utils
'
function
initUTSJSONObjectProperties
(
obj
:
UTSJSONObject
)
{
const
propertyList
=
[
'
_resolveKeyPath
'
,
'
_getValue
'
,
'
toJSON
'
,
'
get
'
,
'
set
'
,
'
getAny
'
,
'
getString
'
,
'
getNumber
'
,
'
getBoolean
'
,
'
getJSON
'
,
'
getArray
'
,
'
toMap
'
,
'
forEach
'
,
]
const
propertyDescriptorMap
:
PropertyDescriptorMap
=
{}
for
(
let
i
=
0
;
i
<
propertyList
.
length
;
i
++
)
{
const
property
=
propertyList
[
i
]
propertyDescriptorMap
[
property
]
=
{
enumerable
:
false
,
value
:
obj
[
property
as
keyof
UTSJSONObject
],
}
}
Object
.
defineProperties
(
obj
,
propertyDescriptorMap
)
}
export
class
UTSJSONObject
{
[
key
:
string
]:
any
constructor
(
content
:
Record
<
string
,
any
>
=
{})
{
for
(
const
key
in
content
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
content
,
key
))
{
const
value
=
content
[
key
]
if
(
isPlainObject
(
value
))
{
this
[
key
]
=
new
UTSJSONObject
(
value
)
}
else
if
(
getType
(
value
)
===
'
array
'
)
{
this
[
key
]
=
value
.
map
((
item
:
any
)
=>
{
if
(
isPlainObject
(
item
))
{
return
new
UTSJSONObject
(
item
)
}
else
{
return
item
}
})
}
else
{
this
[
key
]
=
value
}
}
}
initUTSJSONObjectProperties
(
this
)
}
private
_resolveKeyPath
(
keyPath
:
string
):
string
[]
{
// 非法keyPath不抛出错误,直接返回空数组
let
token
=
''
const
keyPathArr
:
string
[]
=
[]
let
inOpenParentheses
=
false
for
(
let
i
=
0
;
i
<
keyPath
.
length
;
i
++
)
{
const
word
=
keyPath
[
i
]
switch
(
word
)
{
case
'
.
'
:
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
)
token
=
''
}
break
case
'
[
'
:
{
inOpenParentheses
=
true
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
)
token
=
''
}
break
}
case
'
]
'
:
if
(
inOpenParentheses
)
{
if
(
token
.
length
>
0
)
{
const
tokenFirstChar
=
token
[
0
]
const
tokenLastChar
=
token
[
token
.
length
-
1
]
if
(
(
tokenFirstChar
===
'
"
'
&&
tokenLastChar
===
'
"
'
)
||
(
tokenFirstChar
===
"
'
"
&&
tokenLastChar
===
"
'
"
)
||
(
tokenFirstChar
===
'
`
'
&&
tokenLastChar
===
'
`
'
)
)
{
if
(
token
.
length
>
2
)
{
token
=
token
.
slice
(
1
,
-
1
)
}
else
{
return
[]
}
}
else
if
(
!
/^
\d
+$/
.
test
(
token
))
{
return
[]
}
keyPathArr
.
push
(
token
)
token
=
''
}
else
{
return
[]
}
inOpenParentheses
=
false
}
else
{
return
[]
}
break
default
:
token
+=
word
break
}
if
(
i
===
keyPath
.
length
-
1
)
{
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
)
token
=
''
}
}
}
return
keyPathArr
}
private
_getValue
(
keyPath
:
string
):
any
|
null
{
const
keyPathArr
=
this
.
_resolveKeyPath
(
keyPath
)
if
(
keyPathArr
.
length
===
0
)
{
return
null
}
let
value
=
this
for
(
let
key
of
keyPathArr
)
{
if
(
value
instanceof
Object
)
{
value
=
value
[
key
]
}
else
{
return
null
}
}
return
value
}
get
(
key
:
string
):
any
|
null
{
return
this
.
_getValue
(
key
)
}
set
(
key
:
string
,
value
:
any
)
{
this
[
key
]
=
value
}
getAny
(
key
:
string
):
any
|
null
{
return
this
.
_getValue
(
key
)
}
getString
(
key
:
string
):
string
|
null
{
const
value
=
this
.
_getValue
(
key
)
if
(
typeof
value
===
'
string
'
)
{
return
value
}
else
{
return
null
}
}
getNumber
(
key
:
string
):
number
|
null
{
const
value
=
this
.
_getValue
(
key
)
if
(
typeof
value
===
'
number
'
)
{
return
value
}
else
{
return
null
}
}
getBoolean
(
key
:
string
):
boolean
|
null
{
const
boolean
=
this
.
_getValue
(
key
)
if
(
typeof
boolean
===
'
boolean
'
)
{
return
boolean
}
else
{
return
null
}
}
getJSON
(
key
:
string
):
UTSJSONObject
|
null
{
let
value
=
this
.
_getValue
(
key
)
if
(
value
instanceof
Object
)
{
return
new
UTSJSONObject
(
value
)
}
else
{
return
null
}
}
getArray
<
T
=
any
>
(
key
:
string
):
Array
<
T
>
|
null
{
let
value
=
this
.
_getValue
(
key
)
if
(
value
instanceof
Array
)
{
return
value
as
Array
<
T
>
}
else
{
return
null
}
}
toMap
():
Map
<
string
,
any
>
{
let
map
=
new
Map
<
string
,
any
>
()
for
(
let
key
in
this
)
{
map
.
set
(
key
,
this
[
key
]
as
any
)
}
return
map
}
forEach
(
callback
:
(
value
:
any
,
key
:
string
)
=>
void
)
{
for
(
let
key
in
this
)
{
callback
(
this
[
key
]
as
any
,
key
)
}
}
}
packages/uni-h5/src/platform/uts/UniError.ts
0 → 100644
浏览文件 @
24b82e82
export
class
UniError
extends
Error
{
errSubject
:
string
errCode
:
number
errMsg
:
string
cause
?:
Error
data
?:
any
constructor
(
errSubject
:
string
,
errCode
:
number
,
errMsg
:
string
)
{
super
(
errMsg
)
this
.
name
=
'
UniError
'
this
.
errSubject
=
errSubject
this
.
errCode
=
errCode
this
.
errMsg
=
errMsg
}
toString
():
string
{
return
this
.
errMsg
}
toJSON
():
Record
<
string
,
any
>
{
return
{
errSubject
:
this
.
errSubject
,
errCode
:
this
.
errCode
,
errMsg
:
this
.
errMsg
,
data
:
this
.
data
,
cause
:
this
.
cause
&&
typeof
(
this
.
cause
as
UniError
).
toJSON
===
'
function
'
?
(
this
.
cause
as
UniError
).
toJSON
()
:
this
.
cause
,
}
}
}
packages/uni-uts-v1/lib/javascript/dist/index.js
浏览文件 @
24b82e82
此差异已折叠。
点击以展开。
packages/uni-uts-v1/lib/javascript/lib/runtime/index.js
浏览文件 @
24b82e82
/**
* copy from @uts/shared
*/
var
IDENTIFIER
;
(
function
(
IDENTIFIER
)
{
IDENTIFIER
[
"
UTSJSONObject
"
]
=
"
UTSJSONObject
"
;
IDENTIFIER
[
"
JSON
"
]
=
"
JSON
"
;
IDENTIFIER
[
"
UTS
"
]
=
"
UTS
"
;
IDENTIFIER
[
"
DEFINE_COMPONENT
"
]
=
"
defineComponent
"
;
IDENTIFIER
[
"
VUE
"
]
=
"
vue
"
;
IDENTIFIER
[
"
GLOBAL_THIS
"
]
=
"
globalThis
"
;
IDENTIFIER
[
"
UTS_TYPE
"
]
=
"
UTSType
"
;
IDENTIFIER
[
"
UTS_METADATA
"
]
=
"
$UTSMetadata$
"
;
IDENTIFIER
[
"
TEMP_UTS_METADATA
"
]
=
"
$TempUTSMetadata$
"
;
IDENTIFIER
[
"
JSON_FIELD
"
]
=
"
JSON_FIELD
"
;
})(
IDENTIFIER
||
(
IDENTIFIER
=
{}));
var
UTS_CLASS_METADATA_KIND
;
(
function
(
UTS_CLASS_METADATA_KIND
)
{
UTS_CLASS_METADATA_KIND
[
UTS_CLASS_METADATA_KIND
[
"
CLASS
"
]
=
0
]
=
"
CLASS
"
;
UTS_CLASS_METADATA_KIND
[
UTS_CLASS_METADATA_KIND
[
"
INTERFACE
"
]
=
1
]
=
"
INTERFACE
"
;
UTS_CLASS_METADATA_KIND
[
UTS_CLASS_METADATA_KIND
[
"
TYPE
"
]
=
2
]
=
"
TYPE
"
;
})(
UTS_CLASS_METADATA_KIND
||
(
UTS_CLASS_METADATA_KIND
=
{}));
function
getType
(
val
)
{
return
Object
.
prototype
.
toString
.
call
(
val
).
slice
(
8
,
-
1
).
toLowerCase
();
}
function
isPlainObject
(
val
)
{
if
(
val
==
null
||
typeof
val
!==
'
object
'
)
{
return
false
;
}
const
proto
=
Object
.
getPrototypeOf
(
val
);
return
proto
===
Object
.
prototype
||
proto
===
null
;
}
function
initUTSJSONObjectProperties
(
obj
)
{
const
propertyDescriptor
=
{
enumerable
:
false
,
};
const
propertyList
=
[
'
_resolveKeyPath
'
,
'
_getValue
'
,
'
toJSON
'
,
'
get
'
,
'
set
'
,
'
getAny
'
,
'
getString
'
,
'
getNumber
'
,
'
getBoolean
'
,
'
getJSON
'
,
'
getArray
'
,
'
toMap
'
,
'
forEach
'
,
];
const
propertyDescriptorMap
=
{};
for
(
let
i
=
0
;
i
<
propertyList
.
length
;
i
++
)
{
const
property
=
propertyList
[
i
];
propertyDescriptorMap
[
property
]
=
Object
.
assign
(
Object
.
assign
({},
propertyDescriptor
),
{
value
:
obj
[
property
]
});
}
Object
.
defineProperties
(
obj
,
propertyDescriptorMap
);
}
class
UTSJSONObject
{
constructor
(
content
=
{})
{
for
(
const
key
in
content
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
content
,
key
))
{
const
value
=
content
[
key
];
if
(
isPlainObject
(
value
))
{
this
[
key
]
=
new
UTSJSONObject
(
value
);
}
else
if
(
getType
(
value
)
===
'
array
'
)
{
this
[
key
]
=
value
.
map
((
item
)
=>
{
if
(
isPlainObject
(
item
))
{
return
new
UTSJSONObject
(
item
);
}
else
{
return
item
;
}
});
}
else
{
this
[
key
]
=
value
;
}
}
}
initUTSJSONObjectProperties
(
this
);
}
_resolveKeyPath
(
keyPath
)
{
// 非法keyPath不抛出错误,直接返回空数组
let
token
=
''
;
const
keyPathArr
=
[];
let
inOpenParentheses
=
false
;
for
(
let
i
=
0
;
i
<
keyPath
.
length
;
i
++
)
{
const
word
=
keyPath
[
i
];
switch
(
word
)
{
case
'
.
'
:
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
break
;
case
'
[
'
:
{
inOpenParentheses
=
true
;
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
break
;
}
case
'
]
'
:
if
(
inOpenParentheses
)
{
if
(
token
.
length
>
0
)
{
const
tokenFirstChar
=
token
[
0
];
const
tokenLastChar
=
token
[
token
.
length
-
1
];
if
((
tokenFirstChar
===
'
"
'
&&
tokenLastChar
===
'
"
'
)
||
(
tokenFirstChar
===
"
'
"
&&
tokenLastChar
===
"
'
"
)
||
(
tokenFirstChar
===
'
`
'
&&
tokenLastChar
===
'
`
'
))
{
if
(
token
.
length
>
2
)
{
token
=
token
.
slice
(
1
,
-
1
);
}
else
{
return
[];
}
}
else
if
(
!
/^
\d
+$/
.
test
(
token
))
{
return
[];
}
keyPathArr
.
push
(
token
);
token
=
''
;
}
else
{
return
[];
}
inOpenParentheses
=
false
;
}
else
{
return
[];
}
break
;
default
:
token
+=
word
;
break
;
}
if
(
i
===
keyPath
.
length
-
1
)
{
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
}
}
return
keyPathArr
;
}
_getValue
(
keyPath
)
{
const
keyPathArr
=
this
.
_resolveKeyPath
(
keyPath
);
if
(
keyPathArr
.
length
===
0
)
{
return
null
;
}
let
value
=
this
;
for
(
let
key
of
keyPathArr
)
{
if
(
value
instanceof
Object
)
{
value
=
value
[
key
];
}
else
{
return
null
;
}
}
return
value
;
}
get
(
key
)
{
return
this
.
_getValue
(
key
);
}
set
(
key
,
value
)
{
this
[
key
]
=
value
;
}
getAny
(
key
)
{
return
this
.
_getValue
(
key
);
}
getString
(
key
)
{
const
value
=
this
.
_getValue
(
key
);
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
else
{
return
null
;
}
}
getNumber
(
key
)
{
const
value
=
this
.
_getValue
(
key
);
if
(
typeof
value
===
'
number
'
)
{
return
value
;
}
else
{
return
null
;
}
}
getBoolean
(
key
)
{
const
boolean
=
this
.
_getValue
(
key
);
if
(
typeof
boolean
===
'
boolean
'
)
{
return
boolean
;
}
else
{
return
null
;
}
}
getJSON
(
key
)
{
let
value
=
this
.
_getValue
(
key
);
if
(
value
instanceof
Object
)
{
return
new
UTSJSONObject
(
value
);
}
else
{
return
null
;
}
}
getArray
(
key
)
{
let
value
=
this
.
_getValue
(
key
);
if
(
value
instanceof
Array
)
{
return
value
;
}
else
{
return
null
;
}
}
toMap
()
{
let
map
=
new
Map
();
for
(
let
key
in
this
)
{
map
.
set
(
key
,
this
[
key
]);
}
return
map
;
}
forEach
(
callback
)
{
for
(
let
key
in
this
)
{
callback
(
this
[
key
],
key
);
}
}
}
// @ts-nocheck
function
getGlobal
()
{
// cross-platform
if
(
typeof
globalThis
!==
'
undefined
'
)
{
return
globalThis
;
}
// worker
if
(
typeof
self
!==
'
undefined
'
)
{
return
self
;
}
// browser
if
(
typeof
window
!==
'
undefined
'
)
{
return
window
;
}
// nodejs
if
(
typeof
global
!==
'
undefined
'
)
{
return
global
;
}
throw
new
Error
(
'
unable to locate global object
'
);
}
const
realGlobal
=
getGlobal
();
if
(
!
realGlobal
.
globalThis
)
{
realGlobal
.
globalThis
=
realGlobal
;
}
globalThis
.
UTSJSONObject
=
UTSJSONObject
;
function
arrayPop
(
array
)
{
if
(
array
.
length
===
0
)
{
return
null
;
...
...
@@ -291,6 +31,33 @@ function arrayAt(array, index) {
return
array
.
at
(
index
);
}
/**
* copy from @uts/shared
*/
var
IDENTIFIER
;
(
function
(
IDENTIFIER
)
{
IDENTIFIER
[
"
UTSJSONObject
"
]
=
"
UTSJSONObject
"
;
IDENTIFIER
[
"
JSON
"
]
=
"
JSON
"
;
IDENTIFIER
[
"
UTS
"
]
=
"
UTS
"
;
IDENTIFIER
[
"
DEFINE_COMPONENT
"
]
=
"
defineComponent
"
;
IDENTIFIER
[
"
VUE
"
]
=
"
vue
"
;
IDENTIFIER
[
"
GLOBAL_THIS
"
]
=
"
globalThis
"
;
IDENTIFIER
[
"
UTS_TYPE
"
]
=
"
UTSType
"
;
IDENTIFIER
[
"
UTS_METADATA
"
]
=
"
$UTSMetadata$
"
;
IDENTIFIER
[
"
TEMP_UTS_METADATA
"
]
=
"
$TempUTSMetadata$
"
;
IDENTIFIER
[
"
JSON_FIELD
"
]
=
"
JSON_FIELD
"
;
})(
IDENTIFIER
||
(
IDENTIFIER
=
{}));
var
UTS_CLASS_METADATA_KIND
;
(
function
(
UTS_CLASS_METADATA_KIND
)
{
UTS_CLASS_METADATA_KIND
[
UTS_CLASS_METADATA_KIND
[
"
CLASS
"
]
=
0
]
=
"
CLASS
"
;
UTS_CLASS_METADATA_KIND
[
UTS_CLASS_METADATA_KIND
[
"
INTERFACE
"
]
=
1
]
=
"
INTERFACE
"
;
UTS_CLASS_METADATA_KIND
[
UTS_CLASS_METADATA_KIND
[
"
TYPE
"
]
=
2
]
=
"
TYPE
"
;
})(
UTS_CLASS_METADATA_KIND
||
(
UTS_CLASS_METADATA_KIND
=
{}));
function
getType
(
val
)
{
return
Object
.
prototype
.
toString
.
call
(
val
).
slice
(
8
,
-
1
).
toLowerCase
();
}
// TODO 实现UTSError
class
UTSError
extends
Error
{
constructor
(
message
)
{
...
...
packages/uni-uts-v1/lib/kotlin/dist/index.js
浏览文件 @
24b82e82
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录