@netang/quasar 0.2.30 → 0.2.31

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/$table.js +129 -57
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
 
5
5
  "description": "netang-quasar",
6
6
  "scripts": {
package/utils/$table.js CHANGED
@@ -21,6 +21,7 @@ import $n_storage from '@netang/utils/storage'
21
21
 
22
22
  import $n_isRequired from '@netang/utils/isRequired'
23
23
  import $n_forIn from '@netang/utils/forIn'
24
+ import $n_run from '@netang/utils/run'
24
25
  import $n_runAsync from '@netang/utils/runAsync'
25
26
  import $n_isValidObject from '@netang/utils/isValidObject'
26
27
  import $n_isValidValue from '@netang/utils/isValidValue'
@@ -110,6 +111,14 @@ function create(options) {
110
111
  },
111
112
  // 每页显示行数选项
112
113
  rowsPerPageOptions,
114
+ // 请求前执行
115
+ requestBefore: null,
116
+ // 请求成功执行
117
+ requestSuccess: null,
118
+ // 请求失败执行
119
+ requestFail: null,
120
+ // 请求后执行
121
+ requestAfter: null,
113
122
  // 自定义请求方法
114
123
  request: null,
115
124
  // 格式化单条数据
@@ -921,7 +930,7 @@ function create(options) {
921
930
  } = props
922
931
 
923
932
  // http 请求参数
924
- const httpOptions = Object.assign({
933
+ let httpOptions = Object.assign({
925
934
  // 请求数据
926
935
  url: $n_isValidString(o.url) ? o.url : $route.path,
927
936
  // 请求数据
@@ -931,68 +940,131 @@ function create(options) {
931
940
  debounce: false,
932
941
  }, o.httpSettings)
933
942
 
934
- const { status, data: res } = $n_isFunction(o.request)
935
- // 如果有自定义请求方法
936
- ? await $n_runAsync(o.request)({
937
- // http 请求参数
938
- httpOptions,
939
- // 表格声明属性
940
- props,
941
- // 表格行数据
942
- rows: tableRows,
943
- // 表格已选数据
944
- selected: tableSelected,
945
- })
946
- // 否则请求服务器
947
- : await $n_http(httpOptions)
948
-
949
- // 请求成功
950
- if (status) {
951
-
952
- const {
953
- // 返回数据
954
- rows,
955
- // 数据总数
956
- total,
957
- } = res
958
-
959
- // 如果请求表格合计
960
- if (isRequestSummary) {
961
- const summary = $n_get(res, 'summary')
962
- tableSummary.value = $n_isValidObject(summary) ? summary : null
963
- }
964
-
965
- // 更新页码
966
- tablePagination.value.page = page
967
- // 更新每页的数据条数
968
- tablePagination.value.rowsPerPage = rowsPerPage
969
- // 更新数据总数
970
- tablePagination.value.rowsNumber = total
971
- // 更新排序字段
972
- tablePagination.value.sortBy = sortBy
973
- // 更新是否降序排列
974
- tablePagination.value.descending = descending
975
-
976
- // 格式化单条数据
977
- if ($n_isFunction(o.formatRow)) {
978
- $n_forEach(rows, function(row) {
979
- o.formatRow({
980
- row,
981
- rows: tableRows,
982
- selected: tableSelected,
983
- })
943
+ // 下一步
944
+ async function next() {
945
+
946
+ const e = $n_isFunction(o.request)
947
+ // 如果有自定义请求方法
948
+ ? await $n_runAsync(o.request)({
949
+ // http 请求参数
950
+ httpOptions,
951
+ // 表格声明属性
952
+ props,
953
+ // 表格行数据
954
+ rows: tableRows,
955
+ // 表格已选数据
956
+ selected: tableSelected,
984
957
  })
958
+ // 否则请求服务器
959
+ : await $n_http(httpOptions)
960
+
961
+ const { status, data: res } = e
962
+
963
+ // 返回结果数据
964
+ const resultData = Object.assign({
965
+ // 请求地址
966
+ requestUrl: httpOptions.url,
967
+ // 参数
968
+ options: httpOptions,
969
+ // 请求数据
970
+ requestData: httpOptions.data,
971
+ }, e)
972
+
973
+ // 请求后执行
974
+ if (await $n_runAsync(o.requestAfter)(resultData) === false) {
975
+ return
985
976
  }
986
977
 
987
- // 清除现有数据并添加新数据
988
- tableRows.value.splice(0, tableRows.value.length, ...rows)
978
+ // 请求成功
979
+ if (status) {
980
+
981
+ // 下一步
982
+ function nextSuccess() {
983
+
984
+ const {
985
+ // 返回数据
986
+ rows,
987
+ // 数据总数
988
+ total,
989
+ } = res
990
+
991
+ // 如果请求表格合计
992
+ if (isRequestSummary) {
993
+ const summary = $n_get(res, 'summary')
994
+ tableSummary.value = $n_isValidObject(summary) ? summary : null
995
+ }
996
+
997
+ // 更新页码
998
+ tablePagination.value.page = page
999
+ // 更新每页的数据条数
1000
+ tablePagination.value.rowsPerPage = rowsPerPage
1001
+ // 更新数据总数
1002
+ tablePagination.value.rowsNumber = total
1003
+ // 更新排序字段
1004
+ tablePagination.value.sortBy = sortBy
1005
+ // 更新是否降序排列
1006
+ tablePagination.value.descending = descending
1007
+
1008
+ // 格式化单条数据
1009
+ if ($n_isFunction(o.formatRow)) {
1010
+ $n_forEach(rows, function(row) {
1011
+ o.formatRow({
1012
+ row,
1013
+ rows: tableRows,
1014
+ selected: tableSelected,
1015
+ })
1016
+ })
1017
+ }
1018
+
1019
+ // 清除现有数据并添加新数据
1020
+ tableRows.value.splice(0, tableRows.value.length, ...rows)
1021
+
1022
+ // 取消请求表格合计
1023
+ isRequestSummary = false
1024
+
1025
+ // 取消加载
1026
+ tableLoading.value = false
1027
+ }
1028
+
1029
+ // 请求成功执行
1030
+ if (await $n_runAsync(o.requestSuccess)(Object.assign({ next: nextSuccess }, resultData)) === false) {
1031
+ return
1032
+ }
1033
+
1034
+ nextSuccess()
1035
+
1036
+ // 否则请求失败
1037
+ } else {
1038
+
1039
+ // 请求失败执行
1040
+ $n_run(o.requestFail)(resultData)
1041
+
1042
+ // 取消请求表格合计
1043
+ isRequestSummary = false
1044
+
1045
+ // 取消加载
1046
+ tableLoading.value = false
1047
+ }
989
1048
  }
990
1049
 
991
- // 取消请求表格合计
992
- isRequestSummary = false
1050
+ if (o.requestBefore) {
1051
+
1052
+ // 请求前执行
1053
+ const resBefore = await $n_runAsync(o.requestBefore)({
1054
+ options: httpOptions,
1055
+ next,
1056
+ })
1057
+ if (resBefore !== void 0) {
1058
+ if (resBefore === false) {
1059
+ return
1060
+ }
1061
+ httpOptions = resBefore
1062
+ }
1063
+ }
993
1064
 
994
- // 取消加载
995
- tableLoading.value = false
1065
+ // 下一步
1066
+ next()
1067
+ .finally()
996
1068
  }
997
1069
 
998
1070
  /**