haiwei-module-common 1.0.3 → 1.0.5
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 +2 -2
- package/src/api/components/attachment.js +42 -0
- package/src/api/components/dataSource.js +20 -0
- package/src/views/dataSource/components/save/index.vue +158 -0
- package/src/views/dataSource/index/cols.js +49 -0
- package/src/views/dataSource/index/index.vue +86 -0
- package/src/views/dataSource/index/page.js +56 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": 1,
|
|
3
3
|
"name": "haiwei-module-common",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"code": "common",
|
|
6
6
|
"title": "通用模块",
|
|
7
7
|
"description": "通用模块",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"haiwei-module-admin": "^1.2.2",
|
|
22
|
-
"haiwei-ui": "^1.5.
|
|
22
|
+
"haiwei-ui": "^1.5.1"
|
|
23
23
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import module from '../../module'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 附件上传、下载、预览
|
|
5
|
+
*
|
|
6
|
+
* 历史:该接口原为 Common 模块自己的 `common/attachment/Upload`、`common/attachment/Download/{id}`,
|
|
7
|
+
* 于 1.0.1 版随后端一起移除,文件上传统一下沉到框架 Admin 模块的 file 接口。
|
|
8
|
+
* 但本模块 index.js 的 callback 与文档(haiwei.Docs 01_Common.md)都还依赖
|
|
9
|
+
* `$api.common.attachment` 这个入口,缺失会直接导致前端启动时抛
|
|
10
|
+
* "Cannot read properties of undefined (reading 'getUploadUrl')",故在此保留入口、
|
|
11
|
+
* 内部转发到 `$api.admin.file`。
|
|
12
|
+
*
|
|
13
|
+
* 注意:下载与预览的入参已由「附件 ID」变为「文件路径(fullPath)」
|
|
14
|
+
*/
|
|
15
|
+
export default () => {
|
|
16
|
+
// 上传地址
|
|
17
|
+
const getUploadUrl = () => {
|
|
18
|
+
return $api.admin.file.getUploadUrl()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 上传:moduleCode 固定为当前模块
|
|
22
|
+
const upload = (file, group, accessMode = 0, accounts = '') => {
|
|
23
|
+
return $api.admin.file.upload(file, module.code, group, accessMode, accounts)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 下载
|
|
27
|
+
const download = fullPath => {
|
|
28
|
+
return $api.admin.file.download(fullPath)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 预览
|
|
32
|
+
const preview = fullPath => {
|
|
33
|
+
return $api.admin.file.preview(fullPath)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
getUploadUrl,
|
|
38
|
+
upload,
|
|
39
|
+
download,
|
|
40
|
+
preview
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import module from '../../module'
|
|
2
|
+
|
|
3
|
+
export default name => {
|
|
4
|
+
const root = `${module.code}/${name}/`
|
|
5
|
+
const crud = $http.crud(root)
|
|
6
|
+
|
|
7
|
+
const test = model => {
|
|
8
|
+
return $http.post(root + 'Test', model)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const template = provider => {
|
|
12
|
+
return $http.get(root + 'Template', { provider })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...crud,
|
|
17
|
+
test,
|
|
18
|
+
template
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nm-form-dialog ref="form" v-bind="form" v-on="on" :visible.sync="visible_">
|
|
3
|
+
<el-row>
|
|
4
|
+
<el-col :span="20" :offset="1">
|
|
5
|
+
<el-form-item label="名称:" prop="name">
|
|
6
|
+
<el-input v-model="form.model.name" clearable autofocus />
|
|
7
|
+
</el-form-item>
|
|
8
|
+
<el-form-item label="编码:" prop="code">
|
|
9
|
+
<el-input v-model="form.model.code" clearable placeholder="字母、数字、下划线、中划线" />
|
|
10
|
+
</el-form-item>
|
|
11
|
+
<el-form-item label="数据库类型:" prop="provider">
|
|
12
|
+
<nm-enum-select v-model="form.model.provider" module-code="common" enum-name="DataSourceProvider" :clearable="false" />
|
|
13
|
+
</el-form-item>
|
|
14
|
+
<el-form-item v-if="isEdit_" label="当前连接串:">
|
|
15
|
+
<el-input :value="form.model.masked" disabled />
|
|
16
|
+
</el-form-item>
|
|
17
|
+
<el-form-item :label="isEdit_ ? '新连接串:' : '连接串:'" prop="connectionString">
|
|
18
|
+
<el-input v-model="form.model.connectionString" type="textarea" :rows="3" :placeholder="isEdit_ ? '留空表示不修改,修改时请填写完整连接串' : '请填写完整连接串'" />
|
|
19
|
+
</el-form-item>
|
|
20
|
+
<el-form-item label="状态:" prop="enabled">
|
|
21
|
+
<el-switch v-model="form.model.enabled" active-text="启用" inactive-text="停用" />
|
|
22
|
+
</el-form-item>
|
|
23
|
+
<el-form-item label="备注:" prop="remark">
|
|
24
|
+
<el-input v-model="form.model.remark" type="textarea" :rows="2" maxlength="500" show-word-limit />
|
|
25
|
+
</el-form-item>
|
|
26
|
+
</el-col>
|
|
27
|
+
</el-row>
|
|
28
|
+
|
|
29
|
+
<template v-slot:footer-buttons>
|
|
30
|
+
<nm-button code="common_datasource_test" type="primary" text="测试连接" :loading="testing" @click="test" />
|
|
31
|
+
</template>
|
|
32
|
+
</nm-form-dialog>
|
|
33
|
+
</template>
|
|
34
|
+
<script>
|
|
35
|
+
import { mixins } from 'haiwei-ui'
|
|
36
|
+
|
|
37
|
+
// 接口
|
|
38
|
+
const api = $api.common.dataSource
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
mixins: [mixins.formSave],
|
|
42
|
+
data() {
|
|
43
|
+
return {
|
|
44
|
+
title: '数据源',
|
|
45
|
+
testing: false,
|
|
46
|
+
/** 最近一次自动填入的连接串,用于判断是否可以覆盖 */
|
|
47
|
+
autoConnectionString: '',
|
|
48
|
+
actions: {
|
|
49
|
+
add: api.add,
|
|
50
|
+
edit: api.edit,
|
|
51
|
+
update: api.update
|
|
52
|
+
},
|
|
53
|
+
form: {
|
|
54
|
+
width: '700px',
|
|
55
|
+
labelWidth: '110px',
|
|
56
|
+
model: {
|
|
57
|
+
/** 名称 */
|
|
58
|
+
name: '',
|
|
59
|
+
/** 编码 */
|
|
60
|
+
code: '',
|
|
61
|
+
/** 数据库类型 */
|
|
62
|
+
provider: null,
|
|
63
|
+
/** 连接串,编辑时留空表示不修改 */
|
|
64
|
+
connectionString: '',
|
|
65
|
+
/** 掩码后的当前连接串,仅编辑时展示 */
|
|
66
|
+
masked: '',
|
|
67
|
+
/** 是否启用 */
|
|
68
|
+
enabled: true,
|
|
69
|
+
/** 备注 */
|
|
70
|
+
remark: ''
|
|
71
|
+
},
|
|
72
|
+
rules: {
|
|
73
|
+
name: [{ required: true, message: '请输入名称' }],
|
|
74
|
+
code: [
|
|
75
|
+
{ required: true, message: '请输入编码' },
|
|
76
|
+
{ pattern: /^[A-Za-z0-9_-]{1,50}$/, message: '编码只能由字母、数字、下划线、中划线组成,且不超过50个字符' }
|
|
77
|
+
],
|
|
78
|
+
provider: [
|
|
79
|
+
{
|
|
80
|
+
validator: (rule, value, callback) => {
|
|
81
|
+
if (value === null || value === undefined || value === '') {
|
|
82
|
+
callback(new Error('请选择数据库类型'))
|
|
83
|
+
} else {
|
|
84
|
+
callback()
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
trigger: 'change'
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
connectionString: [
|
|
91
|
+
{
|
|
92
|
+
validator: (rule, value, callback) => {
|
|
93
|
+
if (this.isAdd_ && !value) {
|
|
94
|
+
callback(new Error('请填写连接串'))
|
|
95
|
+
} else {
|
|
96
|
+
callback()
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
trigger: 'blur'
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
watch: {
|
|
107
|
+
'form.model.provider'(provider) {
|
|
108
|
+
this.applyDefaultConnectionString(provider)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
methods: {
|
|
112
|
+
/** 新增时选择数据库类型后,连接串为空则填入默认连接串,方便用户修改 */
|
|
113
|
+
applyDefaultConnectionString(provider) {
|
|
114
|
+
if (!this.isAdd_ || provider === null || provider === undefined || provider === '') return
|
|
115
|
+
|
|
116
|
+
const current = this.form.model.connectionString
|
|
117
|
+
// 已手工填写过的不覆盖
|
|
118
|
+
if (current && current !== this.autoConnectionString) return
|
|
119
|
+
|
|
120
|
+
api
|
|
121
|
+
.template(provider)
|
|
122
|
+
.then(value => {
|
|
123
|
+
// 请求期间类型或连接串被改动的,丢弃本次结果
|
|
124
|
+
if (this.form.model.provider !== provider) return
|
|
125
|
+
const exist = this.form.model.connectionString
|
|
126
|
+
if (exist && exist !== this.autoConnectionString) return
|
|
127
|
+
|
|
128
|
+
this.autoConnectionString = value || ''
|
|
129
|
+
this.form.model.connectionString = this.autoConnectionString
|
|
130
|
+
})
|
|
131
|
+
.catch(() => {})
|
|
132
|
+
},
|
|
133
|
+
/** 测试连接:新增时用填写的连接串,编辑时可留空测已保存的 */
|
|
134
|
+
test() {
|
|
135
|
+
const { id, provider, connectionString } = this.form.model
|
|
136
|
+
|
|
137
|
+
if (provider === null || provider === undefined || provider === '') {
|
|
138
|
+
return this.$message.warning('请选择数据库类型')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!connectionString && this.isAdd_) {
|
|
142
|
+
return this.$message.warning('请填写连接串')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.testing = true
|
|
146
|
+
api
|
|
147
|
+
.test({ id: this.isEdit_ ? id : null, provider, connectionString })
|
|
148
|
+
.then(msg => {
|
|
149
|
+
this.testing = false
|
|
150
|
+
this.$message.success(msg || '连接成功')
|
|
151
|
+
})
|
|
152
|
+
.catch(() => {
|
|
153
|
+
this.testing = false
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
</script>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{
|
|
3
|
+
name: 'id',
|
|
4
|
+
label: '编号',
|
|
5
|
+
show: false
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
name: 'name',
|
|
9
|
+
label: '名称'
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'code',
|
|
13
|
+
label: '编码',
|
|
14
|
+
width: 150
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'providerName',
|
|
18
|
+
label: '数据库类型',
|
|
19
|
+
width: 120
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'masked',
|
|
23
|
+
label: '连接串',
|
|
24
|
+
show: false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'enabled',
|
|
28
|
+
label: '状态',
|
|
29
|
+
width: 80,
|
|
30
|
+
format: val => (val ? '启用' : '停用')
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'remark',
|
|
34
|
+
label: '备注',
|
|
35
|
+
show: false
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'creator',
|
|
39
|
+
label: '创建人',
|
|
40
|
+
width: 100,
|
|
41
|
+
show: false
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'createdTime',
|
|
45
|
+
label: '创建时间',
|
|
46
|
+
width: 150,
|
|
47
|
+
show: false
|
|
48
|
+
}
|
|
49
|
+
]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nm-container>
|
|
3
|
+
<nm-list ref="list" v-bind="list">
|
|
4
|
+
<!--查询条件-->
|
|
5
|
+
<template v-slot:querybar>
|
|
6
|
+
<el-form-item label="名称:" prop="name">
|
|
7
|
+
<el-input v-model="list.model.name" clearable />
|
|
8
|
+
</el-form-item>
|
|
9
|
+
<el-form-item label="编码:" prop="code">
|
|
10
|
+
<el-input v-model="list.model.code" clearable />
|
|
11
|
+
</el-form-item>
|
|
12
|
+
<el-form-item label="类型:" prop="provider">
|
|
13
|
+
<nm-enum-select v-model="list.model.provider" module-code="common" enum-name="DataSourceProvider" />
|
|
14
|
+
</el-form-item>
|
|
15
|
+
<el-form-item label="状态:" prop="enabled">
|
|
16
|
+
<el-select v-model="list.model.enabled" clearable placeholder="请选择...">
|
|
17
|
+
<el-option label="启用" :value="true" />
|
|
18
|
+
<el-option label="停用" :value="false" />
|
|
19
|
+
</el-select>
|
|
20
|
+
</el-form-item>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<!--按钮-->
|
|
24
|
+
<template v-slot:querybar-buttons="{ total }">
|
|
25
|
+
<nm-button v-bind="buttons.add" @click="add(total)" />
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<!--操作列-->
|
|
29
|
+
<template v-slot:col-operation="{ row }">
|
|
30
|
+
<nm-button v-bind="buttons.test" @click="test(row)" />
|
|
31
|
+
<nm-button v-bind="buttons.edit" @click="edit(row)" />
|
|
32
|
+
<nm-button-delete v-bind="buttons.del" :id="row.id" :action="removeAction" @success="refresh" />
|
|
33
|
+
</template>
|
|
34
|
+
</nm-list>
|
|
35
|
+
|
|
36
|
+
<save-page :id="curr.id" :total="total" :visible.sync="dialog.save" @success="refresh" />
|
|
37
|
+
</nm-container>
|
|
38
|
+
</template>
|
|
39
|
+
<script>
|
|
40
|
+
import { mixins } from 'haiwei-ui'
|
|
41
|
+
import page from './page'
|
|
42
|
+
import cols from './cols'
|
|
43
|
+
import SavePage from '../components/save'
|
|
44
|
+
|
|
45
|
+
// 接口
|
|
46
|
+
const api = $api.common.dataSource
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
name: page.name,
|
|
50
|
+
mixins: [mixins.list],
|
|
51
|
+
components: { SavePage },
|
|
52
|
+
data() {
|
|
53
|
+
return {
|
|
54
|
+
curr: {},
|
|
55
|
+
list: {
|
|
56
|
+
title: '数据源管理',
|
|
57
|
+
cols,
|
|
58
|
+
action: api.query,
|
|
59
|
+
model: {
|
|
60
|
+
/** 名称 */
|
|
61
|
+
name: '',
|
|
62
|
+
/** 编码 */
|
|
63
|
+
code: '',
|
|
64
|
+
/** 数据库类型 */
|
|
65
|
+
provider: null,
|
|
66
|
+
/** 是否启用 */
|
|
67
|
+
enabled: null
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
removeAction: api.remove,
|
|
71
|
+
buttons: page.buttons
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
methods: {
|
|
75
|
+
/** 测试已保存的数据源连接 */
|
|
76
|
+
test(row) {
|
|
77
|
+
api
|
|
78
|
+
.test({ id: row.id })
|
|
79
|
+
.then(msg => {
|
|
80
|
+
this.$message.success(msg || '连接成功')
|
|
81
|
+
})
|
|
82
|
+
.catch(() => {})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
</script>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** 页面信息 */
|
|
2
|
+
const page = new (function() {
|
|
3
|
+
this.title = '数据源管理'
|
|
4
|
+
this.icon = 'database'
|
|
5
|
+
this.name = 'common_datasource'
|
|
6
|
+
this.path = '/common/dataSource'
|
|
7
|
+
|
|
8
|
+
// 关联权限
|
|
9
|
+
this.permissions = [
|
|
10
|
+
`${this.name}_query_get`,
|
|
11
|
+
`${this.name}_add_post`,
|
|
12
|
+
`${this.name}_edit_get`,
|
|
13
|
+
`${this.name}_update_post`,
|
|
14
|
+
`${this.name}_delete_delete`,
|
|
15
|
+
`${this.name}_test_post`,
|
|
16
|
+
`${this.name}_template_get`
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
this.buttons = {
|
|
20
|
+
add: {
|
|
21
|
+
text: '添加',
|
|
22
|
+
type: 'success',
|
|
23
|
+
code: `${this.name}_add`,
|
|
24
|
+
icon: 'add',
|
|
25
|
+
permissions: [`${this.name}_add_post`]
|
|
26
|
+
},
|
|
27
|
+
test: {
|
|
28
|
+
text: '测试连接',
|
|
29
|
+
type: 'text',
|
|
30
|
+
code: `${this.name}_test`,
|
|
31
|
+
permissions: [`${this.name}_test_post`]
|
|
32
|
+
},
|
|
33
|
+
edit: {
|
|
34
|
+
text: '编辑',
|
|
35
|
+
icon: 'edit',
|
|
36
|
+
type: 'text',
|
|
37
|
+
code: `${this.name}_edit`,
|
|
38
|
+
permissions: [`${this.name}_edit_get`, `${this.name}_update_post`]
|
|
39
|
+
},
|
|
40
|
+
del: {
|
|
41
|
+
text: '删除',
|
|
42
|
+
icon: 'delete',
|
|
43
|
+
type: 'text',
|
|
44
|
+
code: `${this.name}_del`,
|
|
45
|
+
permissions: [`${this.name}_delete_delete`]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
})()
|
|
49
|
+
|
|
50
|
+
/** 路由信息 */
|
|
51
|
+
export const route = {
|
|
52
|
+
page,
|
|
53
|
+
component: () => import(/* webpackChunkName: "Common.DataSource" */ './index')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default page
|