Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
9ec2a554
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ec2a554
编写于
7月 25, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(uni-cloud): support validateFunction
上级
cfb9ca61
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
178 addition
and
7 deletion
+178
-7
.prettierignore
.prettierignore
+6
-1
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+47
-0
packages/uni-cloud/lib/uni.plugin.js
packages/uni-cloud/lib/uni.plugin.js
+2
-0
packages/uni-cloud/lib/validateFunction.js
packages/uni-cloud/lib/validateFunction.js
+16
-0
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+42
-0
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+42
-0
packages/vite-plugin-uni/src/config/index.ts
packages/vite-plugin-uni/src/config/index.ts
+1
-2
packages/vite-plugin-uni/src/config/resolve.ts
packages/vite-plugin-uni/src/config/resolve.ts
+4
-4
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+2
-0
packages/vite-plugin-uni/src/resolveId/index.ts
packages/vite-plugin-uni/src/resolveId/index.ts
+16
-0
未找到文件。
.prettierignore
浏览文件 @
9ec2a554
dist
lib
\ No newline at end of file
packages/uni-app-vite/lib
packages/uni-app-vue/lib
packages/uni-cli-nvue/lib
packages/uni-cli-shared/lib
packages/uni-components/lib
packages/uni-mp-vue/lib
\ No newline at end of file
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
9ec2a554
...
...
@@ -8136,12 +8136,59 @@ var serviceContext = (function (vue) {
}
}
function b64DecodeUnicode(str) {
return decodeURIComponent(atob(str)
.split('')
.map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
})
.join(''));
}
function getCurrentUserInfo() {
const token = uni.getStorageSync('uni_id_token') || '';
const tokenArr = token.split('.');
if (!token || tokenArr.length !== 3) {
return {
uid: null,
role: [],
permission: [],
tokenExpired: 0,
};
}
let userInfo;
try {
userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]));
}
catch (error) {
throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message);
}
userInfo.tokenExpired = userInfo.exp * 1000;
delete userInfo.exp;
delete userInfo.iat;
return userInfo;
}
function uniIdMixin(globalProperties) {
globalProperties.uniIDHasRole = function (roleId) {
const { role } = getCurrentUserInfo();
return role.indexOf(roleId) > -1;
};
globalProperties.uniIDHasPermission = function (permissionId) {
const { permission } = getCurrentUserInfo();
return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1;
};
globalProperties.uniIDTokenValid = function () {
const { tokenExpired } = getCurrentUserInfo();
return tokenExpired > Date.now();
};
}
function initApp(app) {
const appConfig = app._context.config;
if (isFunction(app._component.onError)) {
appConfig.errorHandler = errorHandler;
}
const globalProperties = appConfig.globalProperties;
uniIdMixin(globalProperties);
{
globalProperties.$set = set;
globalProperties.$applyOptions = applyOptions;
...
...
packages/uni-cloud/lib/uni.plugin.js
浏览文件 @
9ec2a554
...
...
@@ -3,6 +3,7 @@ const {
COMMON_EXCLUDE
,
uniViteInjectPlugin
,
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
uniValidateFunctionPlugin
}
=
require
(
'
./validateFunction
'
)
/**
* @type {import('vite').Plugin}
*/
...
...
@@ -115,4 +116,5 @@ module.exports = [
exclude
:
[...
COMMON_EXCLUDE
],
uniCloud
:
[
'
@dcloudio/uni-cloud
'
,
'
default
'
],
}),
uniValidateFunctionPlugin
(),
]
packages/uni-cloud/lib/validateFunction.js
0 → 100644
浏览文件 @
9ec2a554
function
replaceModuleExports
(
code
)
{
return
code
.
replace
(
/module
\.
exports
\s
*=/
,
'
export default
'
)
}
module
.
exports
=
{
uniValidateFunctionPlugin
()
{
return
{
name
:
'
vite:uni-cloud-vf
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
)
{
if
(
id
.
includes
(
'
validator/validateFunction
'
))
{
return
replaceModuleExports
(
code
)
}
},
}
},
}
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
9ec2a554
...
...
@@ -6560,12 +6560,54 @@ function errorHandler(err, instance, info) {
invokeHook
(
app
.
$vm
,
uniShared
.
ON_ERROR
,
err
);
}
}
function
b64DecodeUnicode
(
str
)
{
return
decodeURIComponent
(
atob
(
str
).
split
(
""
).
map
(
function
(
c
)
{
return
"
%
"
+
(
"
00
"
+
c
.
charCodeAt
(
0
).
toString
(
16
)).
slice
(
-
2
);
}).
join
(
""
));
}
function
getCurrentUserInfo
()
{
const
token
=
uni
.
getStorageSync
(
"
uni_id_token
"
)
||
""
;
const
tokenArr
=
token
.
split
(
"
.
"
);
if
(
!
token
||
tokenArr
.
length
!==
3
)
{
return
{
uid
:
null
,
role
:
[],
permission
:
[],
tokenExpired
:
0
};
}
let
userInfo
;
try
{
userInfo
=
JSON
.
parse
(
b64DecodeUnicode
(
tokenArr
[
1
]));
}
catch
(
error
)
{
throw
new
Error
(
"
\
u83B7
\
u53D6
\
u5F53
\
u524D
\
u7528
\
u6237
\
u4FE1
\
u606F
\
u51FA
\
u9519
\
uFF0C
\
u8BE6
\
u7EC6
\
u9519
\
u8BEF
\
u4FE1
\
u606F
\
u4E3A
\
uFF1A
"
+
error
.
message
);
}
userInfo
.
tokenExpired
=
userInfo
.
exp
*
1
e3
;
delete
userInfo
.
exp
;
delete
userInfo
.
iat
;
return
userInfo
;
}
function
uniIdMixin
(
globalProperties
)
{
globalProperties
.
uniIDHasRole
=
function
(
roleId
)
{
const
{
role
}
=
getCurrentUserInfo
();
return
role
.
indexOf
(
roleId
)
>
-
1
;
};
globalProperties
.
uniIDHasPermission
=
function
(
permissionId
)
{
const
{
permission
}
=
getCurrentUserInfo
();
return
this
.
uniIDHasRole
(
"
admin
"
)
||
permission
.
indexOf
(
permissionId
)
>
-
1
;
};
globalProperties
.
uniIDTokenValid
=
function
()
{
const
{
tokenExpired
}
=
getCurrentUserInfo
();
return
tokenExpired
>
Date
.
now
();
};
}
function
initApp$1
(
app
)
{
const
appConfig
=
app
.
_context
.
config
;
if
(
shared
.
isFunction
(
app
.
_component
.
onError
))
{
appConfig
.
errorHandler
=
errorHandler
;
}
const
globalProperties
=
appConfig
.
globalProperties
;
uniIdMixin
(
globalProperties
);
{
globalProperties
.
$set
=
set
;
globalProperties
.
$applyOptions
=
applyOptions
;
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
9ec2a554
...
...
@@ -13113,12 +13113,54 @@ function errorHandler(err, instance2, info) {
invokeHook(app.$vm, ON_ERROR, err);
}
}
function b64DecodeUnicode(str) {
return decodeURIComponent(atob(str).split("").map(function(c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
}).join(""));
}
function getCurrentUserInfo() {
const token = uni.getStorageSync("uni_id_token") || "";
const tokenArr = token.split(".");
if (!token || tokenArr.length !== 3) {
return {
uid: null,
role: [],
permission: [],
tokenExpired: 0
};
}
let userInfo;
try {
userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]));
} catch (error) {
throw new Error("\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u51FA\u9519\uFF0C\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F\u4E3A\uFF1A" + error.message);
}
userInfo.tokenExpired = userInfo.exp * 1e3;
delete userInfo.exp;
delete userInfo.iat;
return userInfo;
}
function uniIdMixin(globalProperties) {
globalProperties.uniIDHasRole = function(roleId) {
const { role } = getCurrentUserInfo();
return role.indexOf(roleId) > -1;
};
globalProperties.uniIDHasPermission = function(permissionId) {
const { permission } = getCurrentUserInfo();
return this.uniIDHasRole("admin") || permission.indexOf(permissionId) > -1;
};
globalProperties.uniIDTokenValid = function() {
const { tokenExpired } = getCurrentUserInfo();
return tokenExpired > Date.now();
};
}
function initApp$1(app) {
const appConfig = app._context.config;
if (isFunction(app._component.onError)) {
appConfig.errorHandler = errorHandler;
}
const globalProperties = appConfig.globalProperties;
uniIdMixin(globalProperties);
{
globalProperties.$set = set;
globalProperties.$applyOptions = applyOptions;
...
...
packages/vite-plugin-uni/src/config/index.ts
浏览文件 @
9ec2a554
import
path
from
'
path
'
import
{
Plugin
,
UserConfig
}
from
'
vite
'
import
{
Plugin
}
from
'
vite
'
import
{
// initPreContext,
...
...
packages/vite-plugin-uni/src/config/resolve.ts
浏览文件 @
9ec2a554
...
...
@@ -7,10 +7,10 @@ export function createResolve(
_config
:
UserConfig
):
UserConfig
[
'
resolve
'
]
{
return
{
alias
:
{
'
@
'
:
''
,
'
~@
'
:
''
,
// src: url('~@/static/uni.ttf') format('truetype');
},
//
alias: {
//
'@': '',
//
'~@': '', // src: url('~@/static/uni.ttf') format('truetype');
//
},
extensions
:
[
'
.mjs
'
,
'
.js
'
,
'
.ts
'
,
'
.jsx
'
,
'
.tsx
'
,
'
.json
'
].
concat
(
EXTNAME_VUE
),
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
9ec2a554
...
...
@@ -14,6 +14,7 @@ import { createConfigResolved } from './configResolved'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
initExtraPlugins
}
from
'
./utils
'
import
{
initPluginVueOptions
}
from
'
./vue
'
import
{
createResolveId
}
from
'
./resolveId
'
const
debugUni
=
debug
(
'
vite:uni:plugin
'
)
...
...
@@ -92,6 +93,7 @@ export default function uniPlugin(
plugins
.
push
({
name
:
'
vite:uni
'
,
config
:
createConfig
(
options
,
uniPlugins
),
resolveId
:
createResolveId
(
options
),
configResolved
:
createConfigResolved
(
options
),
configureServer
:
createConfigureServer
(
options
),
})
...
...
packages/vite-plugin-uni/src/resolveId/index.ts
0 → 100644
浏览文件 @
9ec2a554
import
slash
from
'
slash
'
import
{
Plugin
}
from
'
vite
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
export
function
createResolveId
(
options
:
VitePluginUniResolvedOptions
):
Plugin
[
'
resolveId
'
]
{
const
inputDir
=
slash
(
options
.
inputDir
)
return
function
(
id
)
{
if
(
id
.
startsWith
(
'
@/
'
))
{
return
inputDir
+
id
.
substr
(
1
)
}
else
if
(
id
.
startsWith
(
'
~@/
'
))
{
return
inputDir
+
id
.
substr
(
2
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录