Commit 11973743c58753f01086ffff98b795f6299ca56a
1 parent
5ed2e601
Exists in
master
and in
1 other branch
调整Scheme组件默认返回值格式
Showing
5 changed files
with
70 additions
and
99 deletions
Show diff stats
examples/main.js
| ... | ... | @@ -16,10 +16,12 @@ import "highlight.js/styles/color-brewer.css"; |
| 16 | 16 | import { Notification } from 'element-ui'; |
| 17 | 17 | |
| 18 | 18 | const request = axios.create({ |
| 19 | - baseURL: 'http://47.110.137.80:7101/', | |
| 20 | - timeout: 1000, | |
| 19 | + baseURL: 'http://47.110.137.80:7104/cbin/', | |
| 20 | + timeout: 1000 * 60, | |
| 21 | + withCredentials: true, | |
| 21 | 22 | headers: { |
| 22 | - 'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTE4ODM0MTEsInN1YiI6ImFkbWluIiwiY3JlYXRlZCI6MTU1MTg4MzQxMTk2NX0.rocgsQq_EEbBDV-BcHpJCUS92KGjBH-0Pf47IrW9v3aj6xJCoFIrnKX4vtpPfYscTk1roBhR5s3I1DIvT8B9wg' | |
| 23 | + token: 'be81d1ba777f7081ef6897eec3b4bdf2', | |
| 24 | + 'Accept-Language': 'zh-CN' | |
| 23 | 25 | } |
| 24 | 26 | }); |
| 25 | 27 | |
| ... | ... | @@ -64,32 +66,40 @@ const checkStatus = (response) => { |
| 64 | 66 | // respone 拦截器 |
| 65 | 67 | request.interceptors.response.use( |
| 66 | 68 | response => { |
| 67 | - const { data = {} } = response; | |
| 68 | - const { businessException, errorCode, message, success } = data; | |
| 69 | - if (success) { | |
| 70 | - return data; | |
| 71 | - } else if (businessException) { | |
| 72 | - if (errorCode) { | |
| 73 | - Notification.error({ | |
| 74 | - title: '提示', | |
| 75 | - message, | |
| 76 | - duration: 3000, | |
| 77 | - }); | |
| 78 | - } | |
| 79 | - return { success: false }; | |
| 69 | + const { data = {}, config } = response; | |
| 70 | + const { code, msg } = data; | |
| 71 | + if (config && config.interceptors === false) { // 请求配置不做返回拦截的情况 | |
| 72 | + return response; | |
| 80 | 73 | } else { |
| 81 | - if (errorCode) { | |
| 74 | + if (`${code}` === '401') { // 授权失效 | |
| 75 | + removeToken(); | |
| 76 | + router.push({ name: 'login' }, () => { | |
| 77 | + location.reload(); | |
| 78 | + }); | |
| 79 | + } else if (`${code}` === '1000') { // 业务逻辑错误提示 | |
| 82 | 80 | Notification.error({ |
| 83 | 81 | title: '提示', |
| 84 | - message: codeMessage[errorCode], | |
| 82 | + message: msg, | |
| 85 | 83 | duration: 3000, |
| 86 | 84 | }); |
| 85 | + return false; | |
| 86 | + } else if (`${code}` === '0') { // 请求成功 | |
| 87 | + return data; | |
| 88 | + } else { // 其它错误,开发环境提示 | |
| 89 | + if (process.env.NODE_ENV === 'development') { | |
| 90 | + Notification.error({ | |
| 91 | + title: '提示', | |
| 92 | + message: msg, | |
| 93 | + duration: 3000, | |
| 94 | + }); | |
| 95 | + } | |
| 96 | + return false; | |
| 87 | 97 | } |
| 88 | - return { success: false }; | |
| 89 | 98 | } |
| 90 | 99 | }, |
| 91 | 100 | error => { |
| 92 | 101 | const e = checkStatus(error.response); |
| 102 | + console.error(e); | |
| 93 | 103 | return { success: false }; |
| 94 | 104 | }); |
| 95 | 105 | ... | ... |
examples/views/page/test.vue
| 1 | 1 | <template> |
| 2 | 2 | <eagle-scheme |
| 3 | - :option="{ $http: $axios, url: '/dataDictionary', detailMethod: 'queryById', getMethod: 'queryById', editMethod: 'modify' }" | |
| 3 | + :option="{ $http: $axios, url: '/overseas/store' }" | |
| 4 | 4 | :list="schemeList" |
| 5 | - :formProps="{ span: 24, 'label-width': '60px' }" | |
| 6 | - :detailProps="{ span: 24, 'label-width': '50px' }" | |
| 7 | - :dialogProps="dialogProps" | |
| 8 | - @dialog-change="handleDialogChange" | |
| 9 | 5 | > |
| 10 | 6 | <el-table-column type="selection" width="50"></el-table-column> |
| 11 | 7 | </eagle-scheme> |
| ... | ... | @@ -13,82 +9,47 @@ |
| 13 | 9 | |
| 14 | 10 | <script> |
| 15 | 11 | export default { |
| 16 | - name: 'test', | |
| 12 | + name: 'basicStore', | |
| 17 | 13 | data() { |
| 18 | 14 | return { |
| 19 | 15 | schemeList: [ |
| 20 | 16 | { type: 'el-input', label: 'ID', key: 'id', include: 'form', visible: (model, { formMode } = {}) => { return formMode == 'edit' }, |
| 21 | 17 | props: { disabled: true }, |
| 22 | 18 | }, |
| 23 | - { type: 'el-input', label: '编码', key: 'code', exclude: 'search', | |
| 24 | - rules: [{ required: true, message: '编码不能为空', trigger: 'blur' }], | |
| 25 | - props: { placeholder: '编码' }, | |
| 19 | + { type: 'el-input', label: '门店编码', key: 'code', exclude: 'search', | |
| 20 | + rules: [{ required: true, message: '门店编码不能为空', trigger: 'blur' }], | |
| 21 | + props: { placeholder: '门店编码' }, | |
| 26 | 22 | }, |
| 27 | - { type: 'el-input', label: '名称', key: 'name', | |
| 28 | - rules: [{ required: true, message: '名称不能为空', trigger: 'blur' }], | |
| 29 | - props: { placeholder: '名称' }, | |
| 23 | + { type: 'el-input', label: '门店名称', key: 'name', | |
| 24 | + rules: [{ required: true, message: '门店名称不能为空', trigger: 'blur' }], | |
| 25 | + props: { placeholder: '门店名称' }, | |
| 30 | 26 | }, |
| 31 | - { type: 'el-input', label: '备注', key: 'remark', include: 'table', | |
| 32 | - props: { placeholder: '备注' }, | |
| 27 | + { type: 'el-input', label: '合作伙伴', key: 'dwCustomerCode', exclude: 'search', | |
| 28 | + rules: [{ required: true, message: '合作伙伴不能为空', trigger: 'change' }], | |
| 29 | + props: { placeholder: '合作伙伴' }, | |
| 30 | + }, | |
| 31 | + { type: 'el-input', label: '联系人', key: 'contact', exclude: 'search', | |
| 32 | + rules: [{ required: true, message: '联系人不能为空', trigger: 'change' }], | |
| 33 | + props: { placeholder: '联系人' }, | |
| 34 | + }, | |
| 35 | + { type: 'el-input', label: '联系方式', key: 'phone', exclude: 'search', | |
| 36 | + rules: [{ required: true, message: '联系方式不能为空', trigger: 'change' }], | |
| 37 | + props: { placeholder: '联系方式' }, | |
| 38 | + }, | |
| 39 | + { type: 'el-input', label: '联系地址', key: 'address', exclude: 'search', | |
| 40 | + rules: [{ required: true, message: '联系地址不能为空', trigger: 'change' }], | |
| 41 | + props: { placeholder: '联系地址' }, | |
| 42 | + }, | |
| 43 | + { type: 'el-input', label: '管理员密码', key: 'password', exclude: 'search', | |
| 44 | + rules: [{ required: true, message: '管理员密码不能为空', trigger: 'change' }], | |
| 45 | + props: { placeholder: '管理员密码' }, | |
| 46 | + }, | |
| 47 | + { type: 'el-input', label: '门店类型', key: 'type', | |
| 48 | + rules: [{ required: true, message: '管理员密码不能为空', trigger: 'change' }], | |
| 49 | + props: { placeholder: '管理员密码' }, | |
| 33 | 50 | }, |
| 34 | 51 | ], |
| 35 | - dialogType: '', | |
| 36 | - } | |
| 37 | - }, | |
| 38 | - computed: { | |
| 39 | - dialogProps() { | |
| 40 | - return { width: this.dialogType === 'dialog-form' ? '500px' : '400px' }; | |
| 41 | 52 | } |
| 42 | 53 | }, |
| 43 | - methods: { | |
| 44 | - async searchAPI(param) { | |
| 45 | - return this.$axios.get(`/dataDictionary/page?current=1&size=10`) | |
| 46 | - .then((response) => { | |
| 47 | - const { result = [], totalCount = 0 } = response || {}; | |
| 48 | - return { result, totalCount }; | |
| 49 | - }).catch(() => { | |
| 50 | - return {}; | |
| 51 | - }); | |
| 52 | - }, | |
| 53 | - async getAPI(param) { | |
| 54 | - return this.$axios.get(`/dataDictionary/queryById?id=${param.id}`) | |
| 55 | - .then((response) => { | |
| 56 | - const { result = {} } = response || {}; | |
| 57 | - return result; | |
| 58 | - }).catch(() => { | |
| 59 | - return {}; | |
| 60 | - }); | |
| 61 | - }, | |
| 62 | - async newAPI(param) { | |
| 63 | - return this.$axios.post('/dataDictionary/add', param) | |
| 64 | - .then((response) => { | |
| 65 | - const { success = false } = response || {}; | |
| 66 | - return success; | |
| 67 | - }).catch(() => { | |
| 68 | - return false; | |
| 69 | - }); | |
| 70 | - }, | |
| 71 | - async editAPI(param) { | |
| 72 | - return this.$axios.post('/dataDictionary/modify', param) | |
| 73 | - .then((response) => { | |
| 74 | - const { success = false } = response || {}; | |
| 75 | - return success; | |
| 76 | - }).catch(() => { | |
| 77 | - return false; | |
| 78 | - }); | |
| 79 | - }, | |
| 80 | - async deleteAPI(param) { | |
| 81 | - return this.$axios.post('/dataDictionary/delete', param) | |
| 82 | - .then((response) => { | |
| 83 | - const { success = false } = response || {}; | |
| 84 | - return success; | |
| 85 | - }).catch(() => { | |
| 86 | - return false; | |
| 87 | - }); | |
| 88 | - }, | |
| 89 | - handleDialogChange(type) { | |
| 90 | - this.dialogType = type; | |
| 91 | - } | |
| 92 | - } | |
| 93 | 54 | } |
| 94 | 55 | </script> |
| 95 | 56 | \ No newline at end of file | ... | ... |
packages/form/index.vue
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | </style> |
| 18 | 18 | |
| 19 | 19 | <template> |
| 20 | - <el-form class="eagle-form" ref="form" :model="model" v-bind="{ size: 'small', 'label-width': '90px', ...formProps }"> | |
| 20 | + <el-form class="eagle-form" ref="form" :model="model" v-bind="{ size: 'small', 'label-width': '100px', ...formProps }"> | |
| 21 | 21 | <el-row :gutter="15"> |
| 22 | 22 | <template v-for="(data, index) in listOption.dataList"> |
| 23 | 23 | <template v-if="listOption.isGroup"> | ... | ... |
packages/scheme/index.vue
| ... | ... | @@ -307,8 +307,8 @@ export default { |
| 307 | 307 | this.tableLoading = true; |
| 308 | 308 | _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`) |
| 309 | 309 | .then((response) => { |
| 310 | - const { result = [], totalCount = 0 } = response || {}; | |
| 311 | - this.tableData = result; | |
| 310 | + const { result: { list = [], totalCount = 0 } = {} } = response || {}; | |
| 311 | + this.tableData = list; | |
| 312 | 312 | this.totalCount = totalCount; |
| 313 | 313 | }) |
| 314 | 314 | .finally(() => { |
| ... | ... | @@ -456,8 +456,8 @@ export default { |
| 456 | 456 | const postData = param; |
| 457 | 457 | _$http.post(`${this.option.url.trim('/')}/${this.option.newMethod || 'delete'}`, postData) |
| 458 | 458 | .then(response => { |
| 459 | - const { success = false } = response || {}; | |
| 460 | - if (success) { | |
| 459 | + const { code } = response || {}; | |
| 460 | + if (`${code}` === '0') { | |
| 461 | 461 | this.hideDialog(); |
| 462 | 462 | this.handleSearch(); |
| 463 | 463 | if (this.$message) { this.$message({ message: '删除成功', type: 'success' }); } |
| ... | ... | @@ -523,8 +523,8 @@ export default { |
| 523 | 523 | delete postData[formPrimaryKey || primaryKey]; |
| 524 | 524 | _$http.post(`${this.option.url.trim('/')}/${this.option.newMethod || 'add'}`, postData) |
| 525 | 525 | .then(response => { |
| 526 | - const { success = false } = response || {}; | |
| 527 | - if (success) { | |
| 526 | + const { code } = response || {}; | |
| 527 | + if (`${code}` === '0') { | |
| 528 | 528 | this.hideDialog(); |
| 529 | 529 | this.handleSearch(); |
| 530 | 530 | if (this.$message) { this.$message({ message: '提交成功', type: 'success' }); } |
| ... | ... | @@ -557,8 +557,8 @@ export default { |
| 557 | 557 | this.dialogLoading = true; |
| 558 | 558 | _$http.post(`${this.option.url.trim('/')}/${this.option.editMethod || 'update'}`, param) |
| 559 | 559 | .then(response => { |
| 560 | - const { success = false } = response || {}; | |
| 561 | - if (success) { | |
| 560 | + const { code } = response || {}; | |
| 561 | + if (`${code}` === '0') { | |
| 562 | 562 | this.hideDialog(); |
| 563 | 563 | this.handleSearch(); |
| 564 | 564 | if (this.$message) { this.$message({ message: '编辑成功', type: 'success' }); } | ... | ... |