@netang/quasar 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/$form.js +67 -56
- package/utils/$power.js +38 -29
package/package.json
CHANGED
package/utils/$form.js
CHANGED
|
@@ -1,56 +1,67 @@
|
|
|
1
|
-
import { ref, provide, inject } from 'vue'
|
|
2
|
-
|
|
3
|
-
import $n_has from 'lodash/has'
|
|
4
|
-
|
|
5
|
-
import { NPowerKey, NFormKey } from './symbols'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 创建表单
|
|
9
|
-
*/
|
|
10
|
-
function create(params) {
|
|
11
|
-
|
|
12
|
-
// ==========【数据】=================================================================================================
|
|
13
|
-
|
|
14
|
-
// 获取参数
|
|
15
|
-
const o = Object.assign({
|
|
16
|
-
// 初始表单数据
|
|
17
|
-
formData: {},
|
|
18
|
-
// 重置表单方法
|
|
19
|
-
resetForm: null,
|
|
20
|
-
}, params)
|
|
21
|
-
|
|
22
|
-
// 获取权限注入
|
|
23
|
-
const $power = $n_has(params, '$power') ? params.$power : inject(NPowerKey)
|
|
24
|
-
|
|
25
|
-
// ==========【返回】=================================================================================================
|
|
26
|
-
|
|
27
|
-
const resForm = {
|
|
28
|
-
// 表单节点
|
|
29
|
-
formRef: ref(null),
|
|
30
|
-
// 原始表单数据
|
|
31
|
-
rawFormData: o.formData,
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
import { ref, provide, inject } from 'vue'
|
|
2
|
+
|
|
3
|
+
import $n_has from 'lodash/has'
|
|
4
|
+
|
|
5
|
+
import { NPowerKey, NFormKey } from './symbols'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 创建表单
|
|
9
|
+
*/
|
|
10
|
+
function create(params) {
|
|
11
|
+
|
|
12
|
+
// ==========【数据】=================================================================================================
|
|
13
|
+
|
|
14
|
+
// 获取参数
|
|
15
|
+
const o = Object.assign({
|
|
16
|
+
// 初始表单数据
|
|
17
|
+
formData: {},
|
|
18
|
+
// 重置表单方法
|
|
19
|
+
resetForm: null,
|
|
20
|
+
}, params)
|
|
21
|
+
|
|
22
|
+
// 获取权限注入
|
|
23
|
+
const $power = $n_has(params, '$power') ? params.$power : inject(NPowerKey)
|
|
24
|
+
|
|
25
|
+
// ==========【返回】=================================================================================================
|
|
26
|
+
|
|
27
|
+
const resForm = {
|
|
28
|
+
// 表单节点
|
|
29
|
+
formRef: ref(null),
|
|
30
|
+
// 原始表单数据(用于业务使用)
|
|
31
|
+
rawFormData: o.formData,
|
|
32
|
+
// 请求服务器的原始表单数据(只有执行 setRaw 方法才会生成, 用于请求接口使用)
|
|
33
|
+
requestRawFormData: null,
|
|
34
|
+
// 表单数据
|
|
35
|
+
formData: ref(o.formData),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 设置原始数据
|
|
40
|
+
*/
|
|
41
|
+
resForm.setRaw = function (value) {
|
|
42
|
+
resForm.rawFormData = value
|
|
43
|
+
resForm.requestRawFormData = value
|
|
44
|
+
return value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if ($power) {
|
|
48
|
+
$power.update(function(data, _data) {
|
|
49
|
+
_data.$form = resForm
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 提供可以被后代组件注入的值
|
|
54
|
+
provide(NFormKey, resForm)
|
|
55
|
+
|
|
56
|
+
return resForm
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 业务表单
|
|
61
|
+
*/
|
|
62
|
+
const $form = {
|
|
63
|
+
// 创建表单
|
|
64
|
+
create,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default $form
|
package/utils/$power.js
CHANGED
|
@@ -334,6 +334,8 @@ function create(options) {
|
|
|
334
334
|
|
|
335
335
|
// 权限请求
|
|
336
336
|
await request({
|
|
337
|
+
// power
|
|
338
|
+
$power: data,
|
|
337
339
|
// 按钮数据
|
|
338
340
|
powerBtn,
|
|
339
341
|
// 权限路由参数
|
|
@@ -743,15 +745,12 @@ function formatBtns(powerBtns, filterBtns, toObject = false) {
|
|
|
743
745
|
*/
|
|
744
746
|
function getRequestQuery(o) {
|
|
745
747
|
|
|
746
|
-
// 获取按钮数据
|
|
747
|
-
const btnData = o.powerBtn.data
|
|
748
|
-
|
|
749
748
|
// 传参
|
|
750
749
|
const query = {}
|
|
751
750
|
|
|
752
751
|
// 如果有请求传参的传参设置
|
|
753
|
-
if ($n_has(
|
|
754
|
-
const resQuery = parseQuery(o.query,
|
|
752
|
+
if ($n_has(o.powerBtn.data, 'requestQuery.query')) {
|
|
753
|
+
const resQuery = parseQuery(o.query, o.powerBtn.data.requestQuery.query)
|
|
755
754
|
if ($n_isValidObject(resQuery)) {
|
|
756
755
|
Object.assign(query, resQuery)
|
|
757
756
|
}
|
|
@@ -760,18 +759,18 @@ function getRequestQuery(o) {
|
|
|
760
759
|
// 获取列表数据
|
|
761
760
|
if (
|
|
762
761
|
// 如果按钮参数有显示类型
|
|
763
|
-
$n_has(
|
|
762
|
+
$n_has(o.powerBtn.data, 'show')
|
|
764
763
|
// 按钮参数的显示类型必须是单选或多选
|
|
765
|
-
&& $n_indexOf(['single', 'multiple'],
|
|
764
|
+
&& $n_indexOf(['single', 'multiple'], o.powerBtn.data.show) > -1
|
|
766
765
|
// 如果有请求传参的列表设置
|
|
767
|
-
&& $n_has(
|
|
766
|
+
&& $n_has(o.powerBtn.data, 'requestQuery.list')
|
|
768
767
|
// 如果有表格数据
|
|
769
768
|
&& $n_isValidArray(o.tableSelected)
|
|
770
769
|
) {
|
|
771
770
|
let newQuery = {}
|
|
772
771
|
|
|
773
772
|
// 如果是单选
|
|
774
|
-
if (
|
|
773
|
+
if (o.powerBtn.data.show === 'single') {
|
|
775
774
|
// 取表格选中第一条数据
|
|
776
775
|
newQuery = o.tableSelected[0]
|
|
777
776
|
|
|
@@ -789,7 +788,7 @@ function getRequestQuery(o) {
|
|
|
789
788
|
}
|
|
790
789
|
}
|
|
791
790
|
|
|
792
|
-
const resTable = parseQuery(newQuery,
|
|
791
|
+
const resTable = parseQuery(newQuery, o.powerBtn.data.requestQuery.list)
|
|
793
792
|
if ($n_isValidObject(resTable)) {
|
|
794
793
|
Object.assign(query, resTable)
|
|
795
794
|
}
|
|
@@ -922,15 +921,12 @@ async function request(options) {
|
|
|
922
921
|
})
|
|
923
922
|
}
|
|
924
923
|
|
|
925
|
-
// 获取按钮数据
|
|
926
|
-
const btnData = o.powerBtn.data
|
|
927
|
-
|
|
928
924
|
// 获取请求参数
|
|
929
925
|
let query = getRequestQuery(o)
|
|
930
926
|
|
|
931
927
|
// 如果是打开新窗口
|
|
932
928
|
// --------------------------------------------------
|
|
933
|
-
if (
|
|
929
|
+
if (o.powerBtn.data.type === dicts.POWER_DATA_TYPE__OPEN) {
|
|
934
930
|
|
|
935
931
|
query = formatQuery(query, true)
|
|
936
932
|
|
|
@@ -941,13 +937,16 @@ async function request(options) {
|
|
|
941
937
|
}
|
|
942
938
|
|
|
943
939
|
// 如果不是禁止添加来源页面参数
|
|
944
|
-
if ($n_get(
|
|
940
|
+
if ($n_get(o.powerBtn.data, 'noFromPageQuery') !== true) {
|
|
945
941
|
// 来源页面是当前路由的完整路径
|
|
946
942
|
query.n_from_page = encodeURIComponent($currentRoute.fullPath)
|
|
947
943
|
}
|
|
948
944
|
|
|
949
945
|
// 请求前执行
|
|
950
|
-
const resBefore = await $n_runAsync(o.requestBefore)({
|
|
946
|
+
const resBefore = await $n_runAsync(o.requestBefore)({
|
|
947
|
+
options: o,
|
|
948
|
+
requestData: query,
|
|
949
|
+
})
|
|
951
950
|
if (resBefore !== void 0) {
|
|
952
951
|
if (resBefore === false) {
|
|
953
952
|
return
|
|
@@ -956,7 +955,7 @@ async function request(options) {
|
|
|
956
955
|
}
|
|
957
956
|
|
|
958
957
|
$n_router.push({
|
|
959
|
-
path:
|
|
958
|
+
path: o.powerBtn.data.url,
|
|
960
959
|
query,
|
|
961
960
|
})
|
|
962
961
|
return
|
|
@@ -967,7 +966,7 @@ async function request(options) {
|
|
|
967
966
|
|
|
968
967
|
// 如果是提交表单
|
|
969
968
|
// --------------------------------------------------
|
|
970
|
-
if (
|
|
969
|
+
if (o.powerBtn.data.type === dicts.POWER_DATA_TYPE__FORM) {
|
|
971
970
|
|
|
972
971
|
// 获取表单注入
|
|
973
972
|
o.$form = $n_has(options, '$form') ? options.$form : inject(NFormKey)
|
|
@@ -977,7 +976,7 @@ async function request(options) {
|
|
|
977
976
|
}
|
|
978
977
|
|
|
979
978
|
// 如果验证表单
|
|
980
|
-
if ($n_get(
|
|
979
|
+
if ($n_get(o.powerBtn.data, 'validate') !== false) {
|
|
981
980
|
|
|
982
981
|
if (! o.$form.formRef) {
|
|
983
982
|
throw new Error('没有绑定 fromRef')
|
|
@@ -1006,6 +1005,13 @@ async function request(options) {
|
|
|
1006
1005
|
// 获取请求数据
|
|
1007
1006
|
requestData = $n_merge({}, formatQuery(query, false), o.$form.formData.value)
|
|
1008
1007
|
|
|
1008
|
+
// 合并请求原始表单数据
|
|
1009
|
+
if ($n_isValidObject(o.$form.requestRawFormData)) {
|
|
1010
|
+
Object.assign(requestData, {
|
|
1011
|
+
n__raw: o.$form.requestRawFormData
|
|
1012
|
+
})
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1009
1015
|
// 如果是请求数据
|
|
1010
1016
|
// --------------------------------------------------
|
|
1011
1017
|
} else {
|
|
@@ -1017,12 +1023,12 @@ async function request(options) {
|
|
|
1017
1023
|
}
|
|
1018
1024
|
|
|
1019
1025
|
// 判断是否有确认框
|
|
1020
|
-
const isConfirm = $n_get(
|
|
1026
|
+
const isConfirm = $n_get(o.powerBtn.data, 'confirm')
|
|
1021
1027
|
if (
|
|
1022
1028
|
// 如果有确认框
|
|
1023
1029
|
isConfirm
|
|
1024
1030
|
// 如果有密码确认框
|
|
1025
|
-
|| $n_get(
|
|
1031
|
+
|| $n_get(o.powerBtn.data, 'confirmPassword')
|
|
1026
1032
|
) {
|
|
1027
1033
|
// 如果需要先弹出确认框
|
|
1028
1034
|
if (isConfirm) {
|
|
@@ -1048,7 +1054,10 @@ async function request(options) {
|
|
|
1048
1054
|
async function onRequest() {
|
|
1049
1055
|
|
|
1050
1056
|
// 请求前执行
|
|
1051
|
-
const resBefore = await $n_runAsync(o.requestBefore)({
|
|
1057
|
+
const resBefore = await $n_runAsync(o.requestBefore)({
|
|
1058
|
+
options: o,
|
|
1059
|
+
requestData,
|
|
1060
|
+
})
|
|
1052
1061
|
if (resBefore !== void 0) {
|
|
1053
1062
|
if (resBefore === false) {
|
|
1054
1063
|
return
|
|
@@ -1059,7 +1068,7 @@ async function request(options) {
|
|
|
1059
1068
|
// 请求
|
|
1060
1069
|
const res = await $n_http({
|
|
1061
1070
|
// 请求地址
|
|
1062
|
-
url:
|
|
1071
|
+
url: o.powerBtn.data.url,
|
|
1063
1072
|
// 请求数据
|
|
1064
1073
|
data: requestData,
|
|
1065
1074
|
})
|
|
@@ -1092,8 +1101,8 @@ async function request(options) {
|
|
|
1092
1101
|
}
|
|
1093
1102
|
|
|
1094
1103
|
// 判断是否有请求成功后的操作动作
|
|
1095
|
-
if ($n_has(
|
|
1096
|
-
switch (
|
|
1104
|
+
if ($n_has(o.powerBtn.data, 'requestSuccess.type')) {
|
|
1105
|
+
switch (o.powerBtn.data.requestSuccess.type) {
|
|
1097
1106
|
|
|
1098
1107
|
// 关闭当前页面
|
|
1099
1108
|
case 'close':
|
|
@@ -1115,7 +1124,7 @@ async function request(options) {
|
|
|
1115
1124
|
|
|
1116
1125
|
if (
|
|
1117
1126
|
// 如果不是关闭当前页面, 则为关闭窗口并跳转页面
|
|
1118
|
-
|
|
1127
|
+
o.powerBtn.data.requestSuccess.type !== 'close'
|
|
1119
1128
|
// 如果有来源页面
|
|
1120
1129
|
&& $n_has($route.query, 'n_from_page')
|
|
1121
1130
|
&& $n_isValidString($route.query.n_from_page)
|
|
@@ -1124,12 +1133,12 @@ async function request(options) {
|
|
|
1124
1133
|
// 跳转页面地址
|
|
1125
1134
|
pushPage: decodeURIComponent($route.query.n_from_page),
|
|
1126
1135
|
// 是否跳转并刷新页面
|
|
1127
|
-
isPushRefresh:
|
|
1136
|
+
isPushRefresh: o.powerBtn.data.requestSuccess.type === 'closePushRefresh',
|
|
1128
1137
|
})
|
|
1129
1138
|
|
|
1130
1139
|
// 否则如果定义了跳转页面
|
|
1131
|
-
// else if ($n_has(
|
|
1132
|
-
// pushPage =
|
|
1140
|
+
// else if ($n_has(o.powerBtn.data, 'requestSuccess.params') && $n_isValidString(o.powerBtn.data.requestSuccess.params)) {
|
|
1141
|
+
// pushPage = o.powerBtn.data.requestSuccess.params
|
|
1133
1142
|
// }
|
|
1134
1143
|
}
|
|
1135
1144
|
|