haiwei-module-admin 1.1.6 → 1.1.8
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
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": 0,
|
|
3
3
|
"name": "haiwei-module-admin",
|
|
4
4
|
"code": "admin",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.8",
|
|
6
6
|
"description": "haiwei前端Admin模块组件",
|
|
7
7
|
"author": "Eric",
|
|
8
8
|
"license": "ISC",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"haiwei-skins-classics": "^1.0.7",
|
|
22
|
-
"haiwei-ui": "^1.
|
|
22
|
+
"haiwei-ui": "^1.4.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@vue/cli-plugin-babel": "^4.4.4",
|
|
@@ -3,9 +3,7 @@ import module from '../../module'
|
|
|
3
3
|
export default name => {
|
|
4
4
|
const root = `${module.code}/${name}/`
|
|
5
5
|
const crud = $http.crud(root)
|
|
6
|
-
|
|
7
6
|
console.log('crud', crud)
|
|
8
|
-
|
|
9
7
|
const urls = {
|
|
10
8
|
upload: root + 'Upload',
|
|
11
9
|
hardDelete: root + 'HardDelete'
|
|
@@ -15,6 +13,71 @@ export default name => {
|
|
|
15
13
|
return `${$http.axios.defaults.baseURL}${urls.upload}`
|
|
16
14
|
}
|
|
17
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 简单文件上传接口
|
|
18
|
+
* @param {File} file - 要上传的文件对象
|
|
19
|
+
* @param {string} moduleCode - 模块编码,标识文件所属的模块
|
|
20
|
+
* @param {string} group - 文件分组,用于对文件进行分类管理
|
|
21
|
+
* @param {number} [accessMode=0] - 文件访问方式:0-私有,1-公开,2-授权,默认为0(私有)
|
|
22
|
+
* @param {string} [accounts=''] - 授权模式下关联的账户ID,多个账户使用英文逗号分隔,仅在accessMode=2时有效
|
|
23
|
+
* @returns {Promise} 返回Promise对象,成功时返回包含文件信息的响应数据
|
|
24
|
+
* @example
|
|
25
|
+
* // 基本使用示例
|
|
26
|
+
* const fileInput = document.getElementById('fileInput')
|
|
27
|
+
* const file = fileInput.files[0]
|
|
28
|
+
*
|
|
29
|
+
* $api.admin.file.upload(
|
|
30
|
+
* file,
|
|
31
|
+
* 'user-module',
|
|
32
|
+
* 'avatar',
|
|
33
|
+
* 1, // 公开访问
|
|
34
|
+
* ''
|
|
35
|
+
* ).then(response => {
|
|
36
|
+
* if (response.code === 1) {
|
|
37
|
+
* console.log('上传成功:', response.data)
|
|
38
|
+
* // response.data 包含 { fullPath: '文件完整路径', url: '文件访问URL' }
|
|
39
|
+
* } else {
|
|
40
|
+
* console.error('上传失败:', response.msg)
|
|
41
|
+
* }
|
|
42
|
+
* }).catch(error => {
|
|
43
|
+
* console.error('请求错误:', error)
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* @description
|
|
47
|
+
* 此方法封装了文件上传的核心逻辑,使用FormData格式发送multipart/form-data请求。
|
|
48
|
+
* 文件字段名为'formFile',与后端接口保持一致。
|
|
49
|
+
* 上传成功后的响应格式为:{ code: 1, data: { fullPath: '...', url: '...' }, msg: '...' }
|
|
50
|
+
* 上传失败的响应格式为:{ code: 0, msg: '错误信息' }
|
|
51
|
+
*/
|
|
52
|
+
const upload = (file, moduleCode, group, accessMode = 0, accounts = '') => {
|
|
53
|
+
// 创建FormData对象,用于构建multipart/form-data格式的请求体
|
|
54
|
+
const formData = new FormData()
|
|
55
|
+
|
|
56
|
+
// 添加文件字段,字段名必须为'formFile'以匹配后端接口
|
|
57
|
+
formData.append('formFile', file)
|
|
58
|
+
|
|
59
|
+
// 添加模块编码参数,标识文件所属的业务模块
|
|
60
|
+
formData.append('moduleCode', moduleCode)
|
|
61
|
+
|
|
62
|
+
// 添加文件分组参数,用于对上传的文件进行分类管理
|
|
63
|
+
formData.append('group', group)
|
|
64
|
+
|
|
65
|
+
// 添加访问方式参数:0-私有,1-公开,2-授权
|
|
66
|
+
formData.append('accessMode', accessMode)
|
|
67
|
+
|
|
68
|
+
// 如果提供了账户ID参数,则添加到请求中(仅在授权模式下需要)
|
|
69
|
+
if (accounts) {
|
|
70
|
+
formData.append('accounts', accounts)
|
|
71
|
+
}
|
|
72
|
+
// 发送POST请求到文件上传接口
|
|
73
|
+
// 使用multipart/form-data内容类型,适合文件上传
|
|
74
|
+
return $http.post(urls.upload, formData, {
|
|
75
|
+
headers: {
|
|
76
|
+
'Content-Type': 'multipart/form-data'
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
18
81
|
const hardDelete = id => {
|
|
19
82
|
return $http.delete(urls.hardDelete, { id })
|
|
20
83
|
}
|
|
@@ -36,6 +99,7 @@ export default name => {
|
|
|
36
99
|
return {
|
|
37
100
|
...crud,
|
|
38
101
|
getUploadUrl,
|
|
102
|
+
upload,
|
|
39
103
|
hardDelete,
|
|
40
104
|
getByFullPath,
|
|
41
105
|
preview,
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
</template>
|
|
7
7
|
|
|
8
8
|
<script>
|
|
9
|
-
|
|
10
|
-
const enumCache = new Map()
|
|
9
|
+
import { mixins } from 'haiwei-ui'
|
|
11
10
|
|
|
12
11
|
export default {
|
|
12
|
+
mixins: [mixins.text],
|
|
13
13
|
props: {
|
|
14
14
|
/** 枚举值 */
|
|
15
15
|
value: {
|
|
@@ -54,24 +54,18 @@ export default {
|
|
|
54
54
|
default: 'small'
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
data() {
|
|
58
|
-
return {
|
|
59
|
-
enumList: [],
|
|
60
|
-
loading: false
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
57
|
computed: {
|
|
64
58
|
displayText() {
|
|
65
|
-
if (this.
|
|
59
|
+
if (this.value_ === null || this.value_ === undefined || this.value_ === '') {
|
|
66
60
|
return this.emptyText
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
const enumItem = this.
|
|
70
|
-
return enumItem ? enumItem.label : this.
|
|
63
|
+
const enumItem = this.options.find(item => item.value == this.value_)
|
|
64
|
+
return enumItem ? enumItem.label : this.value_
|
|
71
65
|
},
|
|
72
66
|
|
|
73
67
|
showTag() {
|
|
74
|
-
return this.useTag && this.
|
|
68
|
+
return this.useTag && this.value_ !== null && this.value_ !== undefined && this.value_ !== ''
|
|
75
69
|
},
|
|
76
70
|
|
|
77
71
|
// 计算tag颜色类型
|
|
@@ -86,12 +80,12 @@ export default {
|
|
|
86
80
|
// 如果是对象,根据枚举值查找对应的颜色
|
|
87
81
|
if (typeof this.tagType === 'object' && this.tagType !== null) {
|
|
88
82
|
// 首先尝试精确匹配
|
|
89
|
-
if (this.tagType[this.
|
|
90
|
-
return this.tagType[this.
|
|
83
|
+
if (this.tagType[this.value_] !== undefined) {
|
|
84
|
+
return this.tagType[this.value_]
|
|
91
85
|
}
|
|
92
86
|
|
|
93
87
|
// 尝试数字匹配
|
|
94
|
-
const numValue = Number(this.
|
|
88
|
+
const numValue = Number(this.value_)
|
|
95
89
|
if (this.tagType[numValue] !== undefined) {
|
|
96
90
|
return this.tagType[numValue]
|
|
97
91
|
}
|
|
@@ -99,12 +93,12 @@ export default {
|
|
|
99
93
|
}
|
|
100
94
|
|
|
101
95
|
// 如果没有指定或未找到匹配,根据枚举值自动计算
|
|
102
|
-
if (this.
|
|
96
|
+
if (this.value_ === null || this.value_ === undefined || this.value_ === '') {
|
|
103
97
|
return 'info'
|
|
104
98
|
}
|
|
105
99
|
|
|
106
100
|
// 将值转换为数字
|
|
107
|
-
const numValue = Number(this.
|
|
101
|
+
const numValue = Number(this.value_)
|
|
108
102
|
|
|
109
103
|
// 简单的颜色映射
|
|
110
104
|
if (numValue === 0) return 'primary' // 默认/初始状态
|
|
@@ -120,62 +114,19 @@ export default {
|
|
|
120
114
|
watch: {
|
|
121
115
|
moduleCode: {
|
|
122
116
|
immediate: true,
|
|
123
|
-
handler: '
|
|
117
|
+
handler: 'refresh'
|
|
124
118
|
},
|
|
125
119
|
enumName: {
|
|
126
120
|
immediate: true,
|
|
127
|
-
handler: '
|
|
121
|
+
handler: 'refresh'
|
|
128
122
|
},
|
|
129
123
|
libName: {
|
|
130
124
|
immediate: true,
|
|
131
|
-
handler: '
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
async loadEnumList() {
|
|
136
|
-
if (!this.moduleCode || !this.enumName) {
|
|
137
|
-
this.enumList = []
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// 生成缓存键
|
|
142
|
-
const cacheKey = `${this.moduleCode}_${this.enumName}_${this.libName || ''}`
|
|
143
|
-
|
|
144
|
-
// 检查缓存
|
|
145
|
-
if (enumCache.has(cacheKey)) {
|
|
146
|
-
this.enumList = enumCache.get(cacheKey)
|
|
147
|
-
return
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 防止重复请求
|
|
151
|
-
if (this.loading) {
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
this.loading = true
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
const { moduleCode, enumName, libName } = this
|
|
159
|
-
const result = await $api.admin.tool.enumSelect({ moduleCode, enumName, libName })
|
|
160
|
-
|
|
161
|
-
// API返回的是数组格式:[{label: '出仓', value: 0}, {label: '入仓', value: 1}]
|
|
162
|
-
if (result && Array.isArray(result)) {
|
|
163
|
-
this.enumList = result
|
|
164
|
-
// 缓存结果
|
|
165
|
-
enumCache.set(cacheKey, result)
|
|
166
|
-
} else {
|
|
167
|
-
this.enumList = []
|
|
168
|
-
}
|
|
169
|
-
} catch (error) {
|
|
170
|
-
console.error('加载枚举列表失败:', error)
|
|
171
|
-
this.enumList = []
|
|
172
|
-
} finally {
|
|
173
|
-
this.loading = false
|
|
174
|
-
}
|
|
125
|
+
handler: 'refresh'
|
|
126
|
+
},
|
|
127
|
+
value(val) {
|
|
128
|
+
if (val !== this.value_) this.value_ = val
|
|
175
129
|
}
|
|
176
|
-
},
|
|
177
|
-
mounted() {
|
|
178
|
-
// 移除mounted中的调用,由watch的immediate处理
|
|
179
130
|
}
|
|
180
131
|
}
|
|
181
132
|
</script>
|