vue2-client 1.3.24 → 1.4.0

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.
@@ -286,7 +286,7 @@ export default {
286
286
  // 图片列表
287
287
  imageList: [],
288
288
  // 附件列表
289
- fileList:[],
289
+ fileList: [],
290
290
  // 表单数据
291
291
  form: {
292
292
  name: '',
@@ -1,58 +1,123 @@
1
- import { METHOD, request } from '@vue2-client/utils/request'
2
- import { indexedDB } from '@vue2-client/utils/indexedDB'
3
-
4
- const commonApi = {
5
- // 获取表格列配置
6
- getColumnsJson: '/api/af-system/logic/getColumns',
7
- // 通用查询
8
- query: 'logic/commonQuery',
9
- // 表单查询
10
- queryWithResource: 'logic/commonQueryWithResource',
11
- // 通用新增/修改
12
- addOrModify: 'logic/commonAddOrModify',
13
- // 通用删除
14
- delete: 'logic/commonDelete',
15
- // 获取字典键列表
16
- getDictionaryParam: '/api/af-system/logic/getDictionaryParam',
17
- // 获取所有员工及其部门的级联菜单数据
18
- getEmpTree: '/api/af-system/logic/getEmpTree',
19
- }
20
-
21
- /**
22
- * 带缓存查询的表格配置文件查询
23
- * @param queryParamsName 配置名称
24
- * @param callback 回调函数
25
- */
26
- export function getColumnsJson (queryParamsName, callback) {
27
- indexedDB.getByWeb(queryParamsName, commonApi.getColumnsJson, { str: queryParamsName }, callback)
28
- }
29
-
30
- /**
31
- * 通用查询
32
- */
33
- export function query (parameter, api = commonApi.query, serviceName = 'af-system') {
34
- return request('/api/' + serviceName + '/' + api, METHOD.POST, parameter, null)
35
- }
36
-
37
- /**
38
- * 通用表单查询
39
- */
40
- export function queryWithResource (parameter, api = commonApi.queryWithResource, serviceName = 'af-system') {
41
- return request('/api/' + serviceName + '/' + api, METHOD.POST, parameter, null)
42
- }
43
-
44
- /**
45
- * 通用新增/修改
46
- */
47
- export function addOrModify (parameter, api = commonApi.addOrModify, serviceName = 'af-system') {
48
- return request('/api/' + serviceName + '/' + api, METHOD.POST, parameter, null)
49
- }
50
-
51
- /**
52
- * 通用删除
53
- */
54
- export function remove (parameter, api = commonApi.delete, serviceName = 'af-system') {
55
- return request('/api/' + serviceName + '/' + api, METHOD.POST, parameter, null)
56
- }
57
-
58
- export { commonApi }
1
+ import { indexedDB } from '@vue2-client/utils/indexedDB'
2
+ import notification from 'ant-design-vue/lib/notification'
3
+ import message from 'ant-design-vue/lib/message'
4
+ import { blobValidate } from '@vue2-client/utils/common'
5
+ import errorCode from '@vue2-client/utils/errorCode'
6
+ import { saveAs } from 'file-saver'
7
+ import { post } from '@/services/api/restTools'
8
+
9
+ const commonApi = {
10
+ // 获取表格列配置
11
+ getColumnsJson: '/api/af-system/logic/getColumns',
12
+ // 通用查询
13
+ query: 'logic/commonQuery',
14
+ // 表单查询
15
+ queryWithResource: 'logic/commonQueryWithResource',
16
+ // 通用新增/修改
17
+ addOrModify: 'logic/commonAddOrModify',
18
+ // 通用删除
19
+ delete: 'logic/commonDelete',
20
+ // 获取字典键列表
21
+ getDictionaryParam: '/api/af-system/logic/getDictionaryParam',
22
+ // 获取所有员工及其部门的级联菜单数据
23
+ getEmpTree: '/api/af-system/logic/getEmpTree',
24
+ // 导入数据
25
+ importData: 'logic/importData',
26
+ // 下载数据
27
+ download: 'resource/download',
28
+ // 通用上传
29
+ upload: '/resource/upload'
30
+ }
31
+
32
+ /**
33
+ * 带缓存查询的表格配置文件查询
34
+ * @param queryParamsName 配置名称
35
+ * @param callback 回调函数
36
+ */
37
+ export function getColumnsJson (queryParamsName, callback) {
38
+ indexedDB.getByWeb(queryParamsName, commonApi.getColumnsJson, { str: queryParamsName }, callback)
39
+ }
40
+
41
+ /**
42
+ * 通用查询
43
+ */
44
+ export function query (parameter, serviceName = 'af-system') {
45
+ return post('/api/' + serviceName + '/' + commonApi.query, parameter, null)
46
+ }
47
+
48
+ /**
49
+ * 通用表单查询
50
+ */
51
+ export function queryWithResource (parameter, serviceName = 'af-system') {
52
+ return post('/api/' + serviceName + '/' + commonApi.queryWithResource, parameter, null)
53
+ }
54
+
55
+ /**
56
+ * 通用新增/修改
57
+ */
58
+ export function addOrModify (parameter, serviceName = 'af-system') {
59
+ return post('/api/' + serviceName + '/' + commonApi.addOrModify, parameter, null)
60
+ }
61
+
62
+ /**
63
+ * 通用删除
64
+ */
65
+ export function remove (parameter, serviceName = 'af-system') {
66
+ return post('/api/' + serviceName + '/' + commonApi.delete, parameter, null)
67
+ }
68
+
69
+ /**
70
+ * 通用导入
71
+ */
72
+ export function importData (parameter, serviceName = 'af-system') {
73
+ return post('/api/' + serviceName + '/' + commonApi.importData, parameter, null)
74
+ }
75
+
76
+ /**
77
+ * 通用上传
78
+ */
79
+ export function upload (parameter, serviceName = 'af-system', config) {
80
+ return post('/api/' + serviceName + '/' + commonApi.upload, parameter, config)
81
+ }
82
+
83
+ // 通用下载
84
+ export function download (parameter, filename, serviceName = 'af-system') {
85
+ const notificationKey = 'download'
86
+ notification.open({
87
+ key: notificationKey,
88
+ message: '正在下载数据,请稍候',
89
+ duration: null,
90
+ icon: h => {
91
+ return h(
92
+ 'a-icon',
93
+ {
94
+ props: {
95
+ type: 'loading'
96
+ }
97
+ }
98
+ )
99
+ }
100
+ })
101
+ return post('/api/' + serviceName + '/' + commonApi.download, parameter, {
102
+ responseType: 'blob'
103
+ }).then(async (data) => {
104
+ const isLogin = await blobValidate(data)
105
+ if (isLogin) {
106
+ const blob = new Blob([data])
107
+ saveAs(blob, filename)
108
+ message.success('下载成功')
109
+ } else {
110
+ const resText = await data.text()
111
+ const rspObj = JSON.parse(resText)
112
+ const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
113
+ message.error(errMsg)
114
+ }
115
+ notification.close(notificationKey)
116
+ }).catch((r) => {
117
+ message.error('功能尚未实现,敬请期待!')
118
+ // message.error('下载文件出现错误,请联系管理员!')
119
+ notification.close(notificationKey)
120
+ })
121
+ }
122
+
123
+ export { commonApi }
@@ -0,0 +1,10 @@
1
+ // 验证是否为blob格式
2
+ export async function blobValidate (data) {
3
+ try {
4
+ const text = await data.text()
5
+ JSON.parse(text)
6
+ return false
7
+ } catch (error) {
8
+ return true
9
+ }
10
+ }
@@ -0,0 +1,6 @@
1
+ export default {
2
+ '401': '认证失败,无法访问系统资源',
3
+ '403': '当前操作没有权限',
4
+ '404': '访问资源不存在',
5
+ 'default': '系统未知错误,请反馈给管理员'
6
+ }
@@ -1,109 +0,0 @@
1
- <template>
2
- <a-drawer
3
- title="请选择展示列"
4
- :placement="placement"
5
- :width="width"
6
- :visible="visible"
7
- @close="onClose"
8
- >
9
- <a-checkbox :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange">全选</a-checkbox>
10
- <a-checkbox-group :options="columnsList" v-model="selectColumnsList" @change="onChange" />
11
- </a-drawer>
12
- </template>
13
-
14
- <script>
15
-
16
- export default {
17
- name: 'CustomColumnsDrawer',
18
- props: {
19
- placement: {
20
- type: String,
21
- default: 'right'
22
- },
23
- width: {
24
- type: String,
25
- default: '190'
26
- },
27
- columnsMeta: {
28
- type: Array,
29
- default: null
30
- },
31
- visible: {
32
- type: Boolean,
33
- default: false
34
- }
35
- },
36
- data () {
37
- return {
38
- // 表格列选择项集合
39
- columnsList: [],
40
- // 选中的列集合
41
- selectColumnsList: [],
42
- // 全选样式
43
- indeterminate: false,
44
- // 是否全选
45
- checkAll: true
46
- }
47
- },
48
- mounted () {
49
- let index = 0
50
- this.columnsMeta.forEach((item) => {
51
- // 组织表格列选择项
52
- const rowData = {
53
- label: item.title,
54
- value: item.dataIndex
55
- }
56
- if (index === 0) {
57
- rowData.disabled = true
58
- index++
59
- } else {
60
- // 如果存在固定列,则设置为不可选择项
61
- rowData.disabled = item.fixed !== undefined
62
- }
63
- // 放入表格列选择项集合中
64
- this.columnsList.push(rowData)
65
- // 放入默认选择项
66
- this.selectColumnsList.push(rowData.value)
67
- })
68
- },
69
- methods: {
70
- onChange (checkedValues) {
71
- // 控制全选样式
72
- this.indeterminate = !!checkedValues.length && checkedValues.length < this.columnsList.length
73
- this.checkAll = checkedValues.length === this.columnsList.length
74
- },
75
- onCheckAllChange (e) {
76
- const list = []
77
- this.columnsList.forEach((item) => {
78
- if (e.target.checked) {
79
- list.push(item.value)
80
- } else {
81
- if (item.disabled) {
82
- list.push(item.value)
83
- }
84
- }
85
- })
86
- Object.assign(this, {
87
- selectColumnsList: list,
88
- indeterminate: false,
89
- checkAll: e.target.checked
90
- })
91
- },
92
- onClose () {
93
- this.$emit('update:visible', false)
94
- }
95
- },
96
- watch: {
97
- 'selectColumnsList' (val) {
98
- const selectColumns = []
99
- // 遍历选中项,放入表格列中
100
- this.columnsMeta.forEach((item) => {
101
- if (val.indexOf(item.dataIndex) > -1) {
102
- selectColumns.push(item)
103
- }
104
- })
105
- this.$emit('update:columns', selectColumns)
106
- }
107
- }
108
- }
109
- </script>
@@ -1,3 +0,0 @@
1
- import CustomColumnsDrawer from './CustomColumnsDrawer'
2
-
3
- export default CustomColumnsDrawer
@@ -1,46 +0,0 @@
1
- # CustomColumnsDrawer 自定义表格列
2
-
3
- 提供一个可以自定义选择需要展示的表格列抽屉实现
4
-
5
-
6
-
7
- ## 何时使用
8
-
9
- 允许用户自定义选择需要展示的表格列,常用于列较多的表格查询展示。
10
-
11
-
12
-
13
- 引用方式:
14
-
15
- ```javascript
16
- import CustomColumnsDrawer from '@vue2-client/vue2-client/components/CustomColumnsDrawer'
17
-
18
- export default {
19
- components: {
20
- CustomColumnsDrawer
21
- }
22
- }
23
- ```
24
-
25
-
26
-
27
- ## 代码演示
28
-
29
- ```html
30
- <custom-columns-drawer
31
- :visible.sync="visible"
32
- :columns.sync="tableShowColumns"
33
- :columns-meta="columnsMeta"
34
- />
35
- ```
36
-
37
- ## API
38
-
39
- | 参数 | 说明 | 类型 | 默认值 |
40
- |-------------|-------------------------------|----------------|-------|
41
- | placement | 抽屉的方向,详情参考Ant Design Vue的官方文档 | String, Object | right |
42
- | width | 抽屉的宽度,详情参考Ant Design Vue的官方文档 | String, Object | 190 |
43
- | columnsMeta | 表格列配置的原始json数据 | Array | null |
44
- | visible | 是否显示 | Boolean | false |
45
-
46
-