haiwei-ui 1.3.3 → 1.3.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
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<el-dialog ref="dialog" :id="id" :class="class_" :top="draggable_ ? '' : top" :modal="modal"
|
|
2
|
+
<el-dialog ref="dialog" :id="id" :class="class_" :top="draggable_ ? '' : top" :modal="modal"
|
|
3
|
+
:close-on-click-modal="closeOnClickModal_" :fullscreen="hasFullscreen"
|
|
4
|
+
:visible.sync="visible_" :show-close="false" :append-to-body="true" :destroy-on-close="destroyOnClose" v-on="on">
|
|
3
5
|
<!--头部-->
|
|
4
6
|
<template v-slot:title>
|
|
5
7
|
<section v-if="icon" class="nm-dialog-icon">
|
|
@@ -310,16 +312,13 @@
|
|
|
310
312
|
onOpen() {
|
|
311
313
|
this.$nextTick(() => {
|
|
312
314
|
this.resize()
|
|
313
|
-
|
|
314
315
|
on(window, 'resize', this.resize)
|
|
315
316
|
if (!this.noScrollbar) {
|
|
316
317
|
addResizeListener(this.elScrollbarViewEl, this.resize)
|
|
317
318
|
}
|
|
318
|
-
|
|
319
319
|
if (!this.draggable_) return
|
|
320
320
|
on(this.titleEl, 'mousedown', this.handleDragDown)
|
|
321
321
|
})
|
|
322
|
-
|
|
323
322
|
this.$emit('open')
|
|
324
323
|
},
|
|
325
324
|
onOpened() {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<nm-dialog ref="dialog" class="nm-form-dialog" :title="title" :icon="icon" :width="width" :height="height"
|
|
3
|
-
|
|
2
|
+
<nm-dialog ref="dialog" class="nm-form-dialog" :title="title" :icon="icon" :width="width" :height="height"
|
|
3
|
+
:footer="footer" :fullscreen="fullscreen" :close-on-click-modal="closeOnClickModal" :loading="showLoading"
|
|
4
|
+
:footer-close-button="footerCloseButton" :draggable="draggable" :drag-out-page="dragOutPage"
|
|
5
|
+
:drag-min-width="dragMinWidth" :visible.sync="visible_" v-on="dialogOn">
|
|
6
|
+
<nm-form ref="form" no-loading :model="model" :rules="rules" :action="action" :label-width="labelWidth"
|
|
7
|
+
:label-position="labelPosition" :customValidate="validate" :success-msg="successMsg"
|
|
8
|
+
:success-msg-text="successMsgText" :disabled="disabled" :inline="inline"
|
|
9
|
+
:customResetFunction="customResetFunction" v-on="formOn" @validate="onValidate">
|
|
4
10
|
<slot />
|
|
5
11
|
</nm-form>
|
|
6
12
|
|
|
@@ -18,195 +24,217 @@
|
|
|
18
24
|
</nm-dialog>
|
|
19
25
|
</template>
|
|
20
26
|
<script>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
import visible from '../../mixins/components/visible'
|
|
28
|
+
export default {
|
|
29
|
+
name: 'FormDialog',
|
|
30
|
+
mixins: [visible],
|
|
31
|
+
data() {
|
|
32
|
+
return {
|
|
33
|
+
loading_: false,
|
|
34
|
+
formOn: {
|
|
35
|
+
success: this.onSuccess,
|
|
36
|
+
error: this.onError,
|
|
37
|
+
reset: this.onReset,
|
|
38
|
+
'validate-error': this.onValidateError
|
|
39
|
+
},
|
|
40
|
+
dialogOn: {
|
|
41
|
+
open: this.onOpen,
|
|
42
|
+
opened: this.onOpened,
|
|
43
|
+
close: this.onClose,
|
|
44
|
+
closed: this.onClosed
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
props: {
|
|
49
|
+
/** 标题 */
|
|
50
|
+
title: String,
|
|
51
|
+
/** 图标 */
|
|
52
|
+
icon: String,
|
|
53
|
+
/** 宽度 */
|
|
54
|
+
width: String,
|
|
55
|
+
/** Dialog 的高度 */
|
|
56
|
+
height: [Number, String],
|
|
57
|
+
/** 显示尾部 */
|
|
58
|
+
footer: {
|
|
59
|
+
type: Boolean,
|
|
60
|
+
default: true
|
|
61
|
+
},
|
|
62
|
+
/** 是否可以通过点击 modal 关闭 Dialog */
|
|
63
|
+
closeOnClickModal: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: null
|
|
66
|
+
},
|
|
67
|
+
/** 是否显示全屏按钮 */
|
|
68
|
+
fullscreen: Boolean,
|
|
69
|
+
/** 表单模型 */
|
|
70
|
+
model: {
|
|
71
|
+
type: Object,
|
|
72
|
+
required: true
|
|
73
|
+
},
|
|
74
|
+
/** 验证规则 */
|
|
75
|
+
rules: Object,
|
|
76
|
+
/** 提交请求 */
|
|
77
|
+
action: Function,
|
|
78
|
+
/** 行内表单 */
|
|
79
|
+
inline: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false
|
|
82
|
+
},
|
|
83
|
+
/** 标签的宽度 */
|
|
84
|
+
labelWidth: String,
|
|
85
|
+
/** 表单域标签的位置,如果值为 left 或者 right 时,则需要设置 label-width */
|
|
86
|
+
labelPosition: String,
|
|
87
|
+
// 自定义验证
|
|
88
|
+
validate: Function,
|
|
89
|
+
/** 是否显示成功提示消息 */
|
|
90
|
+
successMsg: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
default: true
|
|
93
|
+
},
|
|
94
|
+
/** 成功提示消息文本 */
|
|
95
|
+
successMsgText: {
|
|
96
|
+
type: String,
|
|
97
|
+
default: '保存成功'
|
|
98
|
+
},
|
|
99
|
+
/** Ok按钮 */
|
|
100
|
+
btnOk: {
|
|
101
|
+
type: Boolean,
|
|
102
|
+
default: true
|
|
103
|
+
},
|
|
104
|
+
/** Ok按钮文本 */
|
|
105
|
+
btnOkText: {
|
|
106
|
+
type: String,
|
|
107
|
+
default: '保存'
|
|
108
|
+
},
|
|
109
|
+
/** reset按钮 */
|
|
110
|
+
btnReset: {
|
|
111
|
+
type: Boolean,
|
|
112
|
+
default: true
|
|
113
|
+
},
|
|
114
|
+
/** 自定义重置操作 */
|
|
115
|
+
customResetFunction: Function,
|
|
116
|
+
// 保存成功后是否关闭对话框
|
|
117
|
+
closeWhenSuccess: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
default: true
|
|
120
|
+
},
|
|
121
|
+
/** 禁用表单 */
|
|
122
|
+
disabled: Boolean,
|
|
123
|
+
/** 显示加载动画 */
|
|
124
|
+
loading: Boolean,
|
|
125
|
+
/** 不显示加载动画 */
|
|
126
|
+
noLoading: {
|
|
127
|
+
type: Boolean,
|
|
128
|
+
default: false
|
|
129
|
+
},
|
|
130
|
+
/** 打开时是否清楚验证信息 */
|
|
131
|
+
clearValidateOnOpen: {
|
|
132
|
+
type: Boolean,
|
|
133
|
+
default: true
|
|
134
|
+
},
|
|
135
|
+
/** 是否显示底部关闭按钮 */
|
|
136
|
+
footerCloseButton: Boolean,
|
|
137
|
+
/** 可拖拽的 */
|
|
138
|
+
draggable: {
|
|
139
|
+
type: Boolean,
|
|
140
|
+
default: null
|
|
141
|
+
},
|
|
142
|
+
/** 是否可拖出页面 */
|
|
143
|
+
dragOutPage: Boolean,
|
|
144
|
+
/** 拖拽出页面后保留的最小宽度 */
|
|
145
|
+
dragMinWidth: Number
|
|
146
|
+
},
|
|
147
|
+
computed: {
|
|
148
|
+
showLoading() {
|
|
149
|
+
return !this.noLoading && (this.loading_ || this.loading)
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
methods: {
|
|
153
|
+
/** 提交 */
|
|
154
|
+
async submit() {
|
|
155
|
+
// 设置loading状态
|
|
156
|
+
this.loading_ = true
|
|
157
|
+
|
|
158
|
+
// 触发 before-submit 钩子
|
|
159
|
+
if (this.$listeners['before-submit']) {
|
|
160
|
+
try {
|
|
161
|
+
// 执行 before-submit 钩子并等待结果
|
|
162
|
+
const result = await this.$emit('before-submit', this.model)
|
|
163
|
+
|
|
164
|
+
// 如果返回false,停止提交
|
|
165
|
+
if (result === false) {
|
|
166
|
+
this.loading_ = false
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
// 返回true或undefined则继续提交
|
|
170
|
+
} catch (error) {
|
|
171
|
+
this.loading_ = false
|
|
172
|
+
this.$emit('error', error)
|
|
173
|
+
return
|
|
39
174
|
}
|
|
40
175
|
}
|
|
176
|
+
|
|
177
|
+
// 继续原有提交逻辑
|
|
178
|
+
this.$refs.form.submit()
|
|
41
179
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
type: Object,
|
|
66
|
-
required: true
|
|
67
|
-
},
|
|
68
|
-
/** 验证规则 */
|
|
69
|
-
rules: Object,
|
|
70
|
-
/** 提交请求 */
|
|
71
|
-
action: Function,
|
|
72
|
-
/** 行内表单 */
|
|
73
|
-
inline: {
|
|
74
|
-
type: Boolean,
|
|
75
|
-
default: false
|
|
76
|
-
},
|
|
77
|
-
/** 标签的宽度 */
|
|
78
|
-
labelWidth: String,
|
|
79
|
-
/** 表单域标签的位置,如果值为 left 或者 right 时,则需要设置 label-width */
|
|
80
|
-
labelPosition: String,
|
|
81
|
-
// 自定义验证
|
|
82
|
-
validate: Function,
|
|
83
|
-
/** 是否显示成功提示消息 */
|
|
84
|
-
successMsg: {
|
|
85
|
-
type: Boolean,
|
|
86
|
-
default: true
|
|
87
|
-
},
|
|
88
|
-
/** 成功提示消息文本 */
|
|
89
|
-
successMsgText: {
|
|
90
|
-
type: String,
|
|
91
|
-
default: '保存成功'
|
|
92
|
-
},
|
|
93
|
-
/** Ok按钮 */
|
|
94
|
-
btnOk: {
|
|
95
|
-
type: Boolean,
|
|
96
|
-
default: true
|
|
97
|
-
},
|
|
98
|
-
/** Ok按钮文本 */
|
|
99
|
-
btnOkText: {
|
|
100
|
-
type: String,
|
|
101
|
-
default: '保存'
|
|
102
|
-
},
|
|
103
|
-
/** reset按钮 */
|
|
104
|
-
btnReset: {
|
|
105
|
-
type: Boolean,
|
|
106
|
-
default: true
|
|
107
|
-
},
|
|
108
|
-
/** 自定义重置操作 */
|
|
109
|
-
customResetFunction: Function,
|
|
110
|
-
// 保存成功后是否关闭对话框
|
|
111
|
-
closeWhenSuccess: {
|
|
112
|
-
type: Boolean,
|
|
113
|
-
default: true
|
|
114
|
-
},
|
|
115
|
-
/** 禁用表单 */
|
|
116
|
-
disabled: Boolean,
|
|
117
|
-
/** 显示加载动画 */
|
|
118
|
-
loading: Boolean,
|
|
119
|
-
/** 不显示加载动画 */
|
|
120
|
-
noLoading: {
|
|
121
|
-
type: Boolean,
|
|
122
|
-
default: false
|
|
123
|
-
},
|
|
124
|
-
/** 打开时是否清楚验证信息 */
|
|
125
|
-
clearValidateOnOpen: {
|
|
126
|
-
type: Boolean,
|
|
127
|
-
default: true
|
|
128
|
-
},
|
|
129
|
-
/** 是否显示底部关闭按钮 */
|
|
130
|
-
footerCloseButton: Boolean,
|
|
131
|
-
/** 可拖拽的 */
|
|
132
|
-
draggable: {
|
|
133
|
-
type: Boolean,
|
|
134
|
-
default: null
|
|
135
|
-
},
|
|
136
|
-
/** 是否可拖出页面 */
|
|
137
|
-
dragOutPage: Boolean,
|
|
138
|
-
/** 拖拽出页面后保留的最小宽度 */
|
|
139
|
-
dragMinWidth: Number
|
|
140
|
-
},
|
|
141
|
-
computed: {
|
|
142
|
-
showLoading() {
|
|
143
|
-
return !this.noLoading && (this.loading_ || this.loading)
|
|
180
|
+
/** 重置 */
|
|
181
|
+
reset() {
|
|
182
|
+
this.$nextTick(() => {
|
|
183
|
+
this.$refs.form.reset()
|
|
184
|
+
})
|
|
185
|
+
},
|
|
186
|
+
/** 清除验证信息 */
|
|
187
|
+
clearValidate() {
|
|
188
|
+
this.$refs.form.clearValidate()
|
|
189
|
+
},
|
|
190
|
+
/** 打开loading */
|
|
191
|
+
openLoading() {
|
|
192
|
+
this.loading_ = true
|
|
193
|
+
},
|
|
194
|
+
/** 关闭loading */
|
|
195
|
+
closeLoading() {
|
|
196
|
+
this.loading = false
|
|
197
|
+
},
|
|
198
|
+
// 成功
|
|
199
|
+
onSuccess(data) {
|
|
200
|
+
// 关闭对话框
|
|
201
|
+
if (this.closeWhenSuccess) {
|
|
202
|
+
setTimeout(this.hide, 800)
|
|
144
203
|
}
|
|
204
|
+
this.loading_ = false
|
|
205
|
+
this.$emit('success', data)
|
|
145
206
|
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
207
|
+
onReset() {
|
|
208
|
+
this.$emit('reset')
|
|
209
|
+
},
|
|
210
|
+
onError() {
|
|
211
|
+
this.loading_ = false
|
|
212
|
+
this.$emit('error')
|
|
213
|
+
},
|
|
214
|
+
onValidateError() {
|
|
215
|
+
this.loading_ = false
|
|
216
|
+
this.$emit('validate-error')
|
|
217
|
+
},
|
|
218
|
+
onOpen() {
|
|
219
|
+
if (this.clearValidateOnOpen) {
|
|
154
220
|
this.$nextTick(() => {
|
|
155
|
-
this.$refs.form.
|
|
221
|
+
this.$refs.form.clearValidate()
|
|
156
222
|
})
|
|
157
|
-
},
|
|
158
|
-
/** 清除验证信息 */
|
|
159
|
-
clearValidate() {
|
|
160
|
-
this.$refs.form.clearValidate()
|
|
161
|
-
},
|
|
162
|
-
/** 打开loading */
|
|
163
|
-
openLoading() {
|
|
164
|
-
this.loading_ = true
|
|
165
|
-
},
|
|
166
|
-
/** 关闭loading */
|
|
167
|
-
closeLoading() {
|
|
168
|
-
this.loading = false
|
|
169
|
-
},
|
|
170
|
-
// 成功
|
|
171
|
-
onSuccess(data) {
|
|
172
|
-
// 关闭对话框
|
|
173
|
-
if (this.closeWhenSuccess) {
|
|
174
|
-
setTimeout(this.hide, 800)
|
|
175
|
-
}
|
|
176
|
-
this.loading_ = false
|
|
177
|
-
this.$emit('success', data)
|
|
178
|
-
},
|
|
179
|
-
onReset() {
|
|
180
|
-
this.$emit('reset')
|
|
181
|
-
},
|
|
182
|
-
onError() {
|
|
183
|
-
this.loading_ = false
|
|
184
|
-
this.$emit('error')
|
|
185
|
-
},
|
|
186
|
-
onValidateError() {
|
|
187
|
-
this.loading_ = false
|
|
188
|
-
this.$emit('validate-error')
|
|
189
|
-
},
|
|
190
|
-
onOpen() {
|
|
191
|
-
if (this.clearValidateOnOpen) {
|
|
192
|
-
this.$nextTick(() => {
|
|
193
|
-
this.$refs.form.clearValidate()
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
this.$emit('open')
|
|
197
|
-
},
|
|
198
|
-
onOpened() {
|
|
199
|
-
this.$emit('opened')
|
|
200
|
-
},
|
|
201
|
-
onClose() {
|
|
202
|
-
this.$emit('close')
|
|
203
|
-
},
|
|
204
|
-
onClosed() {
|
|
205
|
-
this.$emit('closed')
|
|
206
|
-
},
|
|
207
|
-
onValidate(prop, valid, msg) {
|
|
208
|
-
this.$emit('validate', prop, valid, msg)
|
|
209
223
|
}
|
|
224
|
+
this.$emit('open')
|
|
225
|
+
},
|
|
226
|
+
onOpened() {
|
|
227
|
+
this.$emit('opened')
|
|
228
|
+
},
|
|
229
|
+
onClose() {
|
|
230
|
+
this.$emit('close')
|
|
231
|
+
},
|
|
232
|
+
onClosed() {
|
|
233
|
+
this.$emit('closed')
|
|
234
|
+
},
|
|
235
|
+
onValidate(prop, valid, msg) {
|
|
236
|
+
this.$emit('validate', prop, valid, msg)
|
|
210
237
|
}
|
|
211
238
|
}
|
|
239
|
+
}
|
|
212
240
|
</script>
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import qs from 'qs'
|
|
3
|
-
import dayjs from 'dayjs'
|
|
4
|
-
import token from './token'
|
|
5
|
-
import { Message, MessageBox } from 'element-ui'
|
|
6
|
-
import { store } from '../store'
|
|
7
|
-
import { router } from '../router'
|
|
8
|
-
|
|
9
|
-
axios.defaults.headers.post['Content-Type'] = 'application/json'
|
|
10
|
-
axios.defaults.headers.put['Content-Type'] = 'application/json'
|
|
11
|
-
|
|
12
|
-
function Http() {
|
|
13
|
-
this.axios = axios
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 序列化参数为Url形式
|
|
17
|
-
Http.prototype.stringify = params => {
|
|
18
|
-
return qs.stringify(params, {
|
|
19
|
-
allowDots: true
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
Http.prototype.post = (url, params, config) => {
|
|
24
|
-
return axios.post(url, params, config)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Http.prototype.get = (url, params, config) => {
|
|
28
|
-
const config_ = Object.assign({}, config, {
|
|
29
|
-
// 参数
|
|
30
|
-
params,
|
|
31
|
-
// 修改参数序列化方法
|
|
32
|
-
paramsSerializer: p => {
|
|
33
|
-
// 使用逗号分隔参数
|
|
34
|
-
return qs.stringify(p, {
|
|
35
|
-
allowDots: true
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
return axios.get(url, config_)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
Http.prototype.delete = (url, params, config) => {
|
|
43
|
-
const config_ = Object.assign({}, config, {
|
|
44
|
-
// 参数
|
|
45
|
-
params,
|
|
46
|
-
// 修改参数序列化方法
|
|
47
|
-
paramsSerializer: p => {
|
|
48
|
-
// 使用逗号分隔参数
|
|
49
|
-
return qs.stringify(p, {
|
|
50
|
-
allowDots: true
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
return axios.delete(url, config_)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
Http.prototype.put = (url, params, config) => {
|
|
58
|
-
return axios.put(url, params, config)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
Http.prototype.download = (url, params, config) => {
|
|
62
|
-
const config_ = Object.assign({ responseType: 'blob' }, config, {
|
|
63
|
-
// 参数
|
|
64
|
-
params,
|
|
65
|
-
// 修改参数序列化方法
|
|
66
|
-
paramsSerializer: p => {
|
|
67
|
-
// 使用逗号分隔参数
|
|
68
|
-
return qs.stringify(p, {
|
|
69
|
-
allowDots: true
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
return axios.get(url, config_)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
Http.prototype.preview = (url, params, config) => {
|
|
77
|
-
const config_ = Object.assign({ responseType: 'blob', headers: { preview: true } }, config, {
|
|
78
|
-
// 参数
|
|
79
|
-
params,
|
|
80
|
-
// 修改参数序列化方法
|
|
81
|
-
paramsSerializer: p => {
|
|
82
|
-
// 使用逗号分隔参数
|
|
83
|
-
return qs.stringify(p, {
|
|
84
|
-
allowDots: true
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
return axios.get(url, config_)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
Http.prototype.export = (url, params, config) => {
|
|
92
|
-
return axios.post(url, params, Object.assign({ responseType: 'blob' }, config))
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 通用CRUD接口地址
|
|
96
|
-
Http.prototype.crud = root => {
|
|
97
|
-
if (!root.endsWith('/')) {
|
|
98
|
-
root += '/'
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
query(params) {
|
|
102
|
-
return $http.get(`${root}query`, params)
|
|
103
|
-
},
|
|
104
|
-
add(params) {
|
|
105
|
-
return $http.post(`${root}add`, params)
|
|
106
|
-
},
|
|
107
|
-
remove(id) {
|
|
108
|
-
return $http.delete(`${root}delete`, { id })
|
|
109
|
-
},
|
|
110
|
-
edit(id) {
|
|
111
|
-
return $http.get(`${root}edit`, { id })
|
|
112
|
-
},
|
|
113
|
-
update(params) {
|
|
114
|
-
return $http.post(`${root}update`, params)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// 设为全局属性$http
|
|
120
|
-
if (!window.$http) window.$http = new Http()
|
|
121
|
-
|
|
122
|
-
// 消息提醒显示时长(ms)
|
|
123
|
-
const messageDuration = 1500
|
|
124
|
-
//是否显示了账户在其他地方登录的提示框
|
|
125
|
-
let showLoginOnOtherPlaces = false
|
|
126
|
-
|
|
127
|
-
//处理文件下载请求
|
|
128
|
-
const handleDownload = response => {
|
|
129
|
-
//如果返回的是application/json,则表示返回的是json,没有要下载的问题,可能是逻辑处理失败
|
|
130
|
-
if (response.data.type === 'application/json') {
|
|
131
|
-
var reader = new FileReader()
|
|
132
|
-
reader.onload = e => {
|
|
133
|
-
var data = JSON.parse(e.target.result)
|
|
134
|
-
if (data.code === 1) {
|
|
135
|
-
return data.data
|
|
136
|
-
} else {
|
|
137
|
-
Message.error({
|
|
138
|
-
message: data.msg,
|
|
139
|
-
showClose: true,
|
|
140
|
-
duration: messageDuration
|
|
141
|
-
})
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
reader.readAsText(response.data)
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const url = window.URL.createObjectURL(response.data)
|
|
150
|
-
|
|
151
|
-
// 如果是预览直接返回
|
|
152
|
-
if (response.config.headers['preview']) return url
|
|
153
|
-
|
|
154
|
-
let fileName = ''
|
|
155
|
-
// 如果响应头包含'content-disposition'属性,则从该属性中获取文件名称
|
|
156
|
-
let cd = response.headers['content-disposition']
|
|
157
|
-
if (cd) {
|
|
158
|
-
fileName = decodeURI(cd.split("''")[1])
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//如果文件名不存在,则使用时间戳
|
|
162
|
-
if (!fileName) {
|
|
163
|
-
fileName = dayjs().format('YYYYMMDDHHMMSSS')
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
//通过模拟a标签点击事件下载文件
|
|
167
|
-
const link = document.createElement('a')
|
|
168
|
-
link.href = url
|
|
169
|
-
link.setAttribute('download', fileName)
|
|
170
|
-
document.body.appendChild(link)
|
|
171
|
-
link.click()
|
|
172
|
-
document.body.removeChild(link)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
//刷新令牌
|
|
176
|
-
const refreshToken = () => {
|
|
177
|
-
let t = token.get()
|
|
178
|
-
if (t && t.refreshToken) {
|
|
179
|
-
return store.state.app.system.actions.refreshToken(t.refreshToken)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
Promise.reject('refresh token error')
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// 初始化
|
|
186
|
-
export default config => {
|
|
187
|
-
// 接口根路径
|
|
188
|
-
axios.defaults.baseURL = config.baseUrl
|
|
189
|
-
|
|
190
|
-
// 拦截请求
|
|
191
|
-
axios.interceptors.request.use(
|
|
192
|
-
config => {
|
|
193
|
-
let t = token.get()
|
|
194
|
-
if (t && t.accessToken) {
|
|
195
|
-
config.headers.Authorization = 'Bearer ' + t.accessToken
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// 开发环境下打印请求日志
|
|
199
|
-
if (process.env.NODE_ENV === 'development') {
|
|
200
|
-
console.group(`[API请求] ${config.method.toUpperCase()} ${config.url}`)
|
|
201
|
-
console.log('请求配置:', {
|
|
202
|
-
方法: config.method,
|
|
203
|
-
URL: config.url,
|
|
204
|
-
参数: config.params,
|
|
205
|
-
数据: config.data,
|
|
206
|
-
头信息: config.headers
|
|
207
|
-
})
|
|
208
|
-
console.groupEnd()
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return config
|
|
212
|
-
},
|
|
213
|
-
function(error) {
|
|
214
|
-
// 开发环境下打印请求错误日志
|
|
215
|
-
if (process.env.NODE_ENV === 'development') {
|
|
216
|
-
console.error('[请求拦截器错误]:', error)
|
|
217
|
-
}
|
|
218
|
-
return Promise.reject(error)
|
|
219
|
-
}
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
// 响应前拦截器
|
|
223
|
-
axios.interceptors.response.use(
|
|
224
|
-
response => {
|
|
225
|
-
const { config } = response
|
|
226
|
-
|
|
227
|
-
// 开发环境下打印响应成功日志
|
|
228
|
-
if (process.env.NODE_ENV === 'development') {
|
|
229
|
-
console.group(`[API响应] ${config.method.toUpperCase()} ${config.url}`)
|
|
230
|
-
console.log('响应信息:', {
|
|
231
|
-
状态码: response.status,
|
|
232
|
-
状态文本: response.statusText,
|
|
233
|
-
数据: response.data,
|
|
234
|
-
头信息: response.headers
|
|
235
|
-
})
|
|
236
|
-
console.groupEnd()
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// 文件下载/预览
|
|
240
|
-
if (config.responseType && config.responseType === 'blob') {
|
|
241
|
-
return handleDownload(response)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (response.data.code === 1) {
|
|
245
|
-
return response.data.data
|
|
246
|
-
} else if (response.data.code === 0 && !config.noErrorMsg) {
|
|
247
|
-
Message.error({
|
|
248
|
-
message: response.data.msg,
|
|
249
|
-
showClose: true,
|
|
250
|
-
duration: messageDuration
|
|
251
|
-
})
|
|
252
|
-
return Promise.reject(response.data.msg)
|
|
253
|
-
} else {
|
|
254
|
-
return response.data
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
error => {
|
|
258
|
-
// 开发环境下打印响应错误日志
|
|
259
|
-
if (process.env.NODE_ENV === 'development') {
|
|
260
|
-
const method = error.config && error.config.method ? error.config.method.toUpperCase() : 'UNKNOWN'
|
|
261
|
-
const url = error.config && error.config.url ? error.config.url : 'unknown'
|
|
262
|
-
const status = error.response && error.response.status
|
|
263
|
-
const responseData = error.response && error.response.data
|
|
264
|
-
|
|
265
|
-
console.group(`[API错误] ${method} ${url}`)
|
|
266
|
-
console.log('错误信息:', {
|
|
267
|
-
状态码: status,
|
|
268
|
-
错误消息: error.message,
|
|
269
|
-
响应数据: responseData,
|
|
270
|
-
请求配置: error.config
|
|
271
|
-
})
|
|
272
|
-
console.groupEnd()
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
let currentRoute = router.currentRoute
|
|
276
|
-
let redirect = currentRoute.name !== 'login' ? currentRoute.fullPath : '/' // 跳转页面
|
|
277
|
-
if (error && error.response) {
|
|
278
|
-
switch (error.response.status) {
|
|
279
|
-
case 401:
|
|
280
|
-
return refreshToken()
|
|
281
|
-
.then(data => {
|
|
282
|
-
//重新初始化令牌
|
|
283
|
-
store.commit('app/token/init', data)
|
|
284
|
-
//重新发一起一次上次的的请求
|
|
285
|
-
error.config.headers.Authorization = 'Bearer ' + data.accessToken
|
|
286
|
-
return axios.request(error.config)
|
|
287
|
-
})
|
|
288
|
-
.catch(() => {
|
|
289
|
-
// 如果刷新失败,需要删除token并跳转到登录页面
|
|
290
|
-
token.remove()
|
|
291
|
-
router.push({
|
|
292
|
-
name: 'login',
|
|
293
|
-
query: {
|
|
294
|
-
redirect
|
|
295
|
-
}
|
|
296
|
-
})
|
|
297
|
-
})
|
|
298
|
-
case 403:
|
|
299
|
-
store.dispatch(
|
|
300
|
-
'app/page/close',
|
|
301
|
-
{
|
|
302
|
-
fullPath: currentRoute.path,
|
|
303
|
-
router: router,
|
|
304
|
-
to: {
|
|
305
|
-
name: 'error403'
|
|
306
|
-
}
|
|
307
|
-
},
|
|
308
|
-
{ root: true }
|
|
309
|
-
)
|
|
310
|
-
break
|
|
311
|
-
case 622:
|
|
312
|
-
//单账户登录功能
|
|
313
|
-
if (!showLoginOnOtherPlaces) {
|
|
314
|
-
showLoginOnOtherPlaces = true
|
|
315
|
-
MessageBox.confirm('账户已在别处登录, 请重新登录~', '提示', {
|
|
316
|
-
confirmButtonText: '确定',
|
|
317
|
-
type: 'warning',
|
|
318
|
-
showCancelButton: false,
|
|
319
|
-
callback() {
|
|
320
|
-
// 删除token
|
|
321
|
-
token.remove()
|
|
322
|
-
router.push({
|
|
323
|
-
name: 'login',
|
|
324
|
-
query: {
|
|
325
|
-
redirect
|
|
326
|
-
}
|
|
327
|
-
})
|
|
328
|
-
showLoginOnOtherPlaces = false
|
|
329
|
-
}
|
|
330
|
-
})
|
|
331
|
-
}
|
|
332
|
-
break
|
|
333
|
-
default:
|
|
334
|
-
console.error(error.response.data.msg)
|
|
335
|
-
Message.error({
|
|
336
|
-
message: '系统异常,请联系管理员~',
|
|
337
|
-
duration: messageDuration
|
|
338
|
-
})
|
|
339
|
-
break
|
|
340
|
-
}
|
|
341
|
-
} else {
|
|
342
|
-
if (currentRoute.name === 'login') {
|
|
343
|
-
Message.error({
|
|
344
|
-
message: '无法连接网络~',
|
|
345
|
-
duration: messageDuration
|
|
346
|
-
})
|
|
347
|
-
} else {
|
|
348
|
-
token.remove()
|
|
349
|
-
router.push({ name: 'login', query: { redirect } })
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return Promise.reject(error)
|
|
353
|
-
}
|
|
354
|
-
)
|
|
355
|
-
}
|