haiwei-module-admin 1.1.6 → 1.1.7

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.6",
5
+ "version": "1.1.7",
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.2.4"
22
+ "haiwei-ui": "^1.2.7"
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,72 @@ 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
+
73
+ // 发送POST请求到文件上传接口
74
+ // 使用multipart/form-data内容类型,适合文件上传
75
+ return $http.post(urls.upload, formData, {
76
+ headers: {
77
+ 'Content-Type': 'multipart/form-data'
78
+ }
79
+ })
80
+ }
81
+
18
82
  const hardDelete = id => {
19
83
  return $http.delete(urls.hardDelete, { id })
20
84
  }
@@ -36,6 +100,7 @@ export default name => {
36
100
  return {
37
101
  ...crud,
38
102
  getUploadUrl,
103
+ upload,
39
104
  hardDelete,
40
105
  getByFullPath,
41
106
  preview,