Commit d52316ee7be66f7621529f0cbbf3d258ec3c9c80

Authored by Aaron
1 parent 7bcc1a9c
Exists in master and in 1 other branch legacy

调整重置表单逻辑

examples/main.js
@@ -13,100 +13,38 @@ import '@/styles/theme/index.css'; @@ -13,100 +13,38 @@ import '@/styles/theme/index.css';
13 import '@/styles/nprogress.scss'; 13 import '@/styles/nprogress.scss';
14 import "highlight.js/styles/color-brewer.css"; 14 import "highlight.js/styles/color-brewer.css";
15 15
16 -import { Notification } from 'element-ui';  
17 -  
18 const request = axios.create({ 16 const request = axios.create({
19 baseURL: 'http://47.110.137.80:7104/cbin/', 17 baseURL: 'http://47.110.137.80:7104/cbin/',
20 timeout: 1000 * 60, 18 timeout: 1000 * 60,
21 withCredentials: true, 19 withCredentials: true,
22 headers: { 20 headers: {
23 - token: 'd2ec639eb3a4e6e2fc3ab2adc6e652fc', 21 + token: '04c8fe07d7ded87936343ef8f0a6767a',
24 'Accept-Language': 'zh-CN' 22 'Accept-Language': 'zh-CN'
25 } 23 }
26 }); 24 });
27 25
28 -const codeMessage = {  
29 - 200: '服务器成功返回请求的数据',  
30 - 201: '新建或修改数据成功。',  
31 - 202: '一个请求已经进入后台排队(异步任务)',  
32 - 204: '删除数据成功。',  
33 - 400: '发出的请求有错误,服务器没有进行新建或修改数据,的操作。',  
34 - 401: '用户没有权限(令牌、用户名、密码错误)。',  
35 - 403: '用户得到授权,但是访问是被禁止的。',  
36 - 404: '发出的请求针对的是不存在的记录,服务器没有进行操作',  
37 - 406: '请求的格式不可得。',  
38 - 410: '请求的资源被永久删除,且不会再得到的。',  
39 - 422: '当创建一个对象时,发生一个验证错误。',  
40 - 500: '服务器发生错误,请检查服务器',  
41 - 502: '网关错误',  
42 - 503: '服务不可用,服务器暂时过载或维护',  
43 - 504: '网关超时'  
44 -};  
45 -  
46 -const checkStatus = (response) => {  
47 - if (response.status >= 200 && response.status < 300) {  
48 - return response;  
49 - }  
50 - const errortext = codeMessage[response.status] || response.statusText;  
51 - const messageContent = `  
52 - ${response.request.responseURL}  
53 - ${errortext}  
54 - `;  
55 - Notification.error({  
56 - title: `请求错误 ${response.status}:`,  
57 - message: messageContent,  
58 - duration: 3000,  
59 - });  
60 - const error = new Error(errortext);  
61 - error.name = response.status;  
62 - error.response = response;  
63 - return error;  
64 -}  
65 -  
66 // respone 拦截器 26 // respone 拦截器
67 request.interceptors.response.use( 27 request.interceptors.response.use(
68 response => { 28 response => {
69 const { data = {}, config } = response; 29 const { data = {}, config } = response;
70 - const { code, msg } = data; 30 + const { code } = data;
71 if (config && config.interceptors === false) { // 请求配置不做返回拦截的情况 31 if (config && config.interceptors === false) { // 请求配置不做返回拦截的情况
72 return response; 32 return response;
73 } else { 33 } else {
74 - if (`${code}` === '401') { // 授权失效  
75 - removeToken();  
76 - router.push({ name: 'login' }, () => {  
77 - location.reload();  
78 - });  
79 - } else if (`${code}` === '1000') { // 业务逻辑错误提示  
80 - Notification.error({  
81 - title: '提示',  
82 - message: msg,  
83 - duration: 3000,  
84 - });  
85 - return false;  
86 - } else if (`${code}` === '0') { // 请求成功 34 + if (`${code}` === '0') {
87 return data; 35 return data;
88 - } else { // 其它错误,开发环境提示  
89 - if (process.env.NODE_ENV === 'development') {  
90 - Notification.error({  
91 - title: '提示',  
92 - message: msg,  
93 - duration: 3000,  
94 - });  
95 - } 36 + } else {
96 return false; 37 return false;
97 } 38 }
98 } 39 }
99 }, 40 },
100 error => { 41 error => {
101 - const e = checkStatus(error.response);  
102 - console.error(e); 42 + console.error(error);
103 return { success: false }; 43 return { success: false };
104 }); 44 });
105 45
106 Vue.prototype.$axios = request; 46 Vue.prototype.$axios = request;
107 47
108 -  
109 -  
110 // 进度条配置 48 // 进度条配置
111 NProgress.configure({ showSpinner: false }); 49 NProgress.configure({ showSpinner: false });
112 50
examples/views/page/test.vue
1 <template> 1 <template>
2 - <eagle-scheme  
3 - :option="{ $http: $axios, url: '/overseas/store' }"  
4 - :list="schemeList"  
5 - > 2 + <eagle-scheme class="p-3" :list="schemeList" :option="{ $http: $axios, url: '/overseas/price/sale' }">
  3 + <template #search-enableFlag="{ model }">
  4 + <eagle-select v-model="model.enableFlag" :dataSource="[{ label: '正常', value: true }, { label: '禁用', value: false }]"></eagle-select>
  5 + </template>
6 <el-table-column type="selection" width="50"></el-table-column> 6 <el-table-column type="selection" width="50"></el-table-column>
  7 + <template #table-productCode>
  8 + <el-table-column prop="productName" label="产品" min-width="100">
  9 + <span slot-scope="{ row: { productName, productCode } }">{{ productName || productCode }}</span>
  10 + </el-table-column>
  11 + </template>
  12 + <template #table-append>
  13 + <el-table-column prop="createTime" label="创建时间" min-width="180"></el-table-column>
  14 + <el-table-column prop="createUser" label="创建人" min-width="160" show-overflow-tooltip></el-table-column>
  15 + <el-table-column prop="modifyTime" label="修改时间" min-width="180"></el-table-column>
  16 + <el-table-column prop="modifyUser" label="修改人" min-width="160" show-overflow-tooltip></el-table-column>
  17 + </template>
7 </eagle-scheme> 18 </eagle-scheme>
8 </template> 19 </template>
9 20
@@ -13,40 +24,41 @@ export default { @@ -13,40 +24,41 @@ export default {
13 data() { 24 data() {
14 return { 25 return {
15 schemeList: [ 26 schemeList: [
16 - { type: 'el-input', label: 'ID', key: 'id', include: 'form', visible: (model, { formMode } = {}) => { return formMode == 'edit' }, 27 + { type: 'el-input', label: 'ID', key: 'id', include: 'form', visible: (model, { formMode } = {}) => { return formMode == 'edit' }, show: false,
17 props: { disabled: true }, 28 props: { disabled: true },
18 }, 29 },
19 - { type: 'el-input', label: '门店编码', key: 'code', exclude: 'search',  
20 - rules: [{ required: true, message: '门店编码不能为空', trigger: 'blur' }],  
21 - props: { placeholder: '门店编码' }, 30 + { type: 'el-input', label: '编码', key: 'code', default: '1231231321231',
  31 + rules: [{ required: true, message: '编码不能为空', trigger: 'blur' }],
  32 + props: { placeholder: '编码', disabled: (model, { formMode } = {}) => { return formMode == 'edit' } },
22 }, 33 },
23 - { type: 'el-input', label: '门店名称', key: 'name',  
24 - rules: [{ required: true, message: '门店名称不能为空', trigger: 'blur' }],  
25 - props: { placeholder: '门店名称' }, 34 + { type: 'el-input', label: '产品', key: 'productCode',
  35 + rules: [{ required: true, message: '产品不能为空', trigger: 'blur' }],
  36 + props: { url: '/overseas/product/select' },
26 }, 37 },
27 - { type: 'el-input', label: '合作伙伴', key: 'dwCustomerCode', exclude: 'search',  
28 - rules: [{ required: true, message: '合作伙伴不能为空', trigger: 'change' }],  
29 - props: { placeholder: '合作伙伴' }, 38 + { type: 'el-input-number', label: '价格', key: 'price', exclude: 'search',
  39 + rules: [{ required: true, message: '价格不能为空', trigger: 'blur' }],
  40 + props: { placeholder: '价格' },
30 }, 41 },
31 - { type: 'el-input', label: '联系人', key: 'contact', exclude: 'search',  
32 - rules: [{ required: true, message: '联系人不能为空', trigger: 'change' }],  
33 - props: { placeholder: '联系人' }, 42 + { type: 'el-input', label: '价格说明', key: 'note', exclude: 'search',
  43 + props: { placeholder: '价格说明' },
34 }, 44 },
35 - { type: 'el-input', label: '联系方式', key: 'phone', exclude: 'search',  
36 - rules: [{ required: true, message: '联系方式不能为空', trigger: 'change' }],  
37 - props: { placeholder: '联系方式' }, 45 + { type: 'el-input', label: '出发城市', key: 'fromCity', exclude: 'search',
  46 + rules: [{ required: true, message: '出发城市不能为空', trigger: 'change' }],
  47 + props: { dictionaryCode: 'FROM_CITY_LIST' },
38 }, 48 },
39 - { type: 'el-input', label: '联系地址', key: 'address', exclude: 'search',  
40 - rules: [{ required: true, message: '联系地址不能为空', trigger: 'change' }],  
41 - props: { placeholder: '联系地址' }, 49 + { type: 'el-input', label: '目的地', key: 'toCountry', exclude: 'search',
  50 + rules: [{ required: true, message: '目的地不能为空', trigger: 'change' }],
  51 + props: { dictionaryCode: 'TO_COUNTRY' },
42 }, 52 },
43 - { type: 'el-input', label: '管理员密码', key: 'password', exclude: 'search',  
44 - rules: [{ required: true, message: '管理员密码不能为空', trigger: 'change' }],  
45 - props: { placeholder: '管理员密码' }, 53 + { type: 'el-input', label: '状态', key: 'enableFlag', span: 24, searchScheme: { span: 6 },
46 }, 54 },
47 - { type: 'el-input', label: '门店类型', key: 'type',  
48 - rules: [{ required: true, message: '管理员密码不能为空', trigger: 'change' }],  
49 - props: { placeholder: '管理员密码' }, 55 + { type: 'el-date-picker', label: '生效时间', key: 'enabledTime', exclude: 'search', minWidth: '180',
  56 + rules: [{ required: true, message: '生效时间不能为空', trigger: 'change' }],
  57 + props: { type: 'datetime', placeholder: '生效时间', 'value-format': 'yyyy-MM-dd HH:mm:ss' },
  58 + },
  59 + { type: 'el-date-picker', label: '禁用时间', key: 'disabledTime', exclude: 'search', minWidth: '180',
  60 + rules: [{ required: true, message: '禁用时间不能为空', trigger: 'change' }],
  61 + props: { type: 'datetime', placeholder: '禁用时间', 'value-format': 'yyyy-MM-dd HH:mm:ss' },
50 }, 62 },
51 ], 63 ],
52 } 64 }
packages/scheme/index.vue
@@ -115,7 +115,7 @@ @@ -115,7 +115,7 @@
115 </div> 115 </div>
116 </div> 116 </div>
117 <el-dialog v-loading="dialogLoading" element-loading-background="rgba(255, 255, 255, 0.3)" :custom-class="dialogProps['custom-class'] || 'eagle-scheme__dialog'" :title="dialogProps.title || dialogTitle" :visible.sync="dialogVisible" v-bind="{ width: '65%', ...dialogProps }"> 117 <el-dialog v-loading="dialogLoading" element-loading-background="rgba(255, 255, 255, 0.3)" :custom-class="dialogProps['custom-class'] || 'eagle-scheme__dialog'" :title="dialogProps.title || dialogTitle" :visible.sync="dialogVisible" v-bind="{ width: '65%', ...dialogProps }">
118 - <eagle-form v-if="dialogType === 'dialog-form' && !$scopedSlots['dialog-form'] && !$slots['dialog-form']" :list="_formList" v-model="formModel" :params="{ formMode }" :span="formProps.span || 12" :formProps="formProps" @submit="handleSubmit" @cancel="handleCancel"> 118 + <eagle-form v-if="dialogType === 'dialog-form' && !$scopedSlots['dialog-form'] && !$slots['dialog-form']" ref="eagle-form" :list="_formList" v-model="formModel" :params="{ formMode }" :span="formProps.span || 12" :formProps="formProps" @submit="handleSubmit" @cancel="handleCancel">
119 <!-- 表单分组具名插槽 --> 119 <!-- 表单分组具名插槽 -->
120 <template v-for="key in formGroupSlotsKeys"> 120 <template v-for="key in formGroupSlotsKeys">
121 <slot v-if="$scopedSlots[`form-${key}`] || $slots[`form-${key}`]" :name="`form-${key}`" :slot="key" :model="formModel"></slot> 121 <slot v-if="$scopedSlots[`form-${key}`] || $slots[`form-${key}`]" :name="`form-${key}`" :slot="key" :model="formModel"></slot>
@@ -298,7 +298,6 @@ export default { @@ -298,7 +298,6 @@ export default {
298 async doSearch(param) { 298 async doSearch(param) {
299 const { totalCountAlias = 'totalCount' } = this.option || {}; 299 const { totalCountAlias = 'totalCount' } = this.option || {};
300 if (this.option.searchAPI) { // 配置了自定义查询API的情况 300 if (this.option.searchAPI) { // 配置了自定义查询API的情况
301 - console.log('searchAPI');  
302 this.tableLoading = true; 301 this.tableLoading = true;
303 try { 302 try {
304 const response = await this.option.searchAPI(param) || {}; 303 const response = await this.option.searchAPI(param) || {};
@@ -311,7 +310,6 @@ export default { @@ -311,7 +310,6 @@ export default {
311 this.tableLoading = false; 310 this.tableLoading = false;
312 } 311 }
313 } else if (_$http && this.option.url) { // 给定了http的情况 312 } else if (_$http && this.option.url) { // 给定了http的情况
314 - console.log('_$http search');  
315 this.tableLoading = true; 313 this.tableLoading = true;
316 _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`) 314 _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`)
317 .then((response) => { 315 .then((response) => {
@@ -333,7 +331,7 @@ export default { @@ -333,7 +331,7 @@ export default {
333 this.dialogTitle = this.i18n('eagle.scheme.detail') || '详情'; 331 this.dialogTitle = this.i18n('eagle.scheme.detail') || '详情';
334 this.dialogType = 'dialog-view'; 332 this.dialogType = 'dialog-view';
335 this.tableCurrentRow = row; 333 this.tableCurrentRow = row;
336 - this.formModel = {}; 334 + this.resetFormModel();
337 this.formMode = "view"; 335 this.formMode = "view";
338 this.$emit('dialog-change', this.dialogType); 336 this.$emit('dialog-change', this.dialogType);
339 this.showDialog(); 337 this.showDialog();
@@ -343,7 +341,6 @@ export default { @@ -343,7 +341,6 @@ export default {
343 async doDetail(param) { 341 async doDetail(param) {
344 const { primaryKey = 'id', detailPrimaryKey, detailRow = false } = this.option || {}; 342 const { primaryKey = 'id', detailPrimaryKey, detailRow = false } = this.option || {};
345 if (this.option.detailAPI && !detailRow) { // 配置了自定义查询API的情况 343 if (this.option.detailAPI && !detailRow) { // 配置了自定义查询API的情况
346 - console.log('detailAPI');  
347 this.dialogLoading = true; 344 this.dialogLoading = true;
348 try { 345 try {
349 const result = await this.option.detailAPI(param); 346 const result = await this.option.detailAPI(param);
@@ -354,7 +351,6 @@ export default { @@ -354,7 +351,6 @@ export default {
354 this.dialogLoading = false; 351 this.dialogLoading = false;
355 } 352 }
356 } else if (_$http && this.option.url && !detailRow) { // 给定了http的情况 353 } else if (_$http && this.option.url && !detailRow) { // 给定了http的情况
357 - console.log('_$http detail');  
358 this.dialogLoading = true; 354 this.dialogLoading = true;
359 const defaultDetailMethod = `info/${detailPrimaryKey || primaryKey}/${param[detailPrimaryKey] || param[primaryKey]}`; 355 const defaultDetailMethod = `info/${detailPrimaryKey || primaryKey}/${param[detailPrimaryKey] || param[primaryKey]}`;
360 const detailMethodFormat = this.option.detailMethod ? `${this.option.detailMethod.trim('/')}/${param[detailPrimaryKey || primaryKey]}` : undefined; 356 const detailMethodFormat = this.option.detailMethod ? `${this.option.detailMethod.trim('/')}/${param[detailPrimaryKey || primaryKey]}` : undefined;
@@ -375,7 +371,7 @@ export default { @@ -375,7 +371,7 @@ export default {
375 this.dialogTitle = this.i18n('eagle.scheme.new') || '新增'; 371 this.dialogTitle = this.i18n('eagle.scheme.new') || '新增';
376 this.dialogType = 'dialog-form'; 372 this.dialogType = 'dialog-form';
377 this.tableCurrentRow = row; 373 this.tableCurrentRow = row;
378 - this.formModel = {}; 374 + this.resetFormModel();
379 this.formMode = "new"; 375 this.formMode = "new";
380 this.$emit('dialog-change', this.dialogType); 376 this.$emit('dialog-change', this.dialogType);
381 this.showDialog(); 377 this.showDialog();
@@ -385,7 +381,7 @@ export default { @@ -385,7 +381,7 @@ export default {
385 this.dialogTitle = this.i18n('eagle.scheme.edit') || '编辑'; 381 this.dialogTitle = this.i18n('eagle.scheme.edit') || '编辑';
386 this.dialogType = 'dialog-form'; 382 this.dialogType = 'dialog-form';
387 this.tableCurrentRow = row; 383 this.tableCurrentRow = row;
388 - this.formModel = {}; 384 + this.resetFormModel();
389 this.formMode = "edit"; 385 this.formMode = "edit";
390 this.$emit('dialog-change', this.dialogType); 386 this.$emit('dialog-change', this.dialogType);
391 this.showDialog(); 387 this.showDialog();
@@ -395,7 +391,6 @@ export default { @@ -395,7 +391,6 @@ export default {
395 async doGet(param) { 391 async doGet(param) {
396 const { primaryKey = 'id', getPrimaryKey, getRow = false } = this.option || {}; 392 const { primaryKey = 'id', getPrimaryKey, getRow = false } = this.option || {};
397 if (this.option.getAPI) { // 配置了自定义查询API的情况 393 if (this.option.getAPI) { // 配置了自定义查询API的情况
398 - console.log('getAPI');  
399 this.dialogLoading = true; 394 this.dialogLoading = true;
400 try { 395 try {
401 const result = await this.option.getAPI(param); 396 const result = await this.option.getAPI(param);
@@ -406,7 +401,6 @@ export default { @@ -406,7 +401,6 @@ export default {
406 this.dialogLoading = false; 401 this.dialogLoading = false;
407 } 402 }
408 } else if (_$http && this.option.url && !getRow) { // 给定了http的情况 403 } else if (_$http && this.option.url && !getRow) { // 给定了http的情况
409 - console.log('_$http get');  
410 this.dialogLoading = true; 404 this.dialogLoading = true;
411 const defaultGetMethod = `get/${getPrimaryKey || primaryKey}/${param[getPrimaryKey] || param[primaryKey]}`; 405 const defaultGetMethod = `get/${getPrimaryKey || primaryKey}/${param[getPrimaryKey] || param[primaryKey]}`;
412 const getMethodFormat = this.option.getMethod ? `${this.option.getMethod.trim('/')}/${param[getPrimaryKey || primaryKey]}` : undefined; 406 const getMethodFormat = this.option.getMethod ? `${this.option.getMethod.trim('/')}/${param[getPrimaryKey || primaryKey]}` : undefined;
@@ -445,7 +439,6 @@ export default { @@ -445,7 +439,6 @@ export default {
445 const { primaryKey = 'id', deletePrimaryKey } = this.option || {}; 439 const { primaryKey = 'id', deletePrimaryKey } = this.option || {};
446 const param = selection.map(item => item[deletePrimaryKey || primaryKey]); 440 const param = selection.map(item => item[deletePrimaryKey || primaryKey]);
447 if (this.option.deleteAPI) { // 配置了自定义删除API的情况 441 if (this.option.deleteAPI) { // 配置了自定义删除API的情况
448 - console.log('deleteAPI');  
449 this.dialogLoading = true; 442 this.dialogLoading = true;
450 try { 443 try {
451 const success = await this.option.deleteAPI(param, selection); 444 const success = await this.option.deleteAPI(param, selection);
@@ -460,7 +453,6 @@ export default { @@ -460,7 +453,6 @@ export default {
460 this.dialogLoading = false; 453 this.dialogLoading = false;
461 } 454 }
462 } else if (_$http && this.option.url) { // 给定了http的情况 455 } else if (_$http && this.option.url) { // 给定了http的情况
463 - console.log('_$http delete');  
464 this.dialogLoading = true; 456 this.dialogLoading = true;
465 const postData = param; 457 const postData = param;
466 _$http.post(`${this.option.url.trim('/')}/${this.option.deleteMethod || 'delete'}`, postData) 458 _$http.post(`${this.option.url.trim('/')}/${this.option.deleteMethod || 'delete'}`, postData)
@@ -477,6 +469,18 @@ export default { @@ -477,6 +469,18 @@ export default {
477 }); 469 });
478 } 470 }
479 }, 471 },
  472 + // 重置表单值
  473 + resetFormModel() {
  474 + this.$nextTick(() => {
  475 + if (this.$refs['eagle-form']) {
  476 + this.$refs['eagle-form'].reset();
  477 + } else {
  478 + Object.keys(this.formModel).forEach(key => {
  479 + this.formModel[key] = undefined;
  480 + });
  481 + }
  482 + });
  483 + },
480 // 设置表单值 484 // 设置表单值
481 setFormModel(value) { 485 setFormModel(value) {
482 if (value && value instanceof Object) { 486 if (value && value instanceof Object) {
@@ -511,7 +515,6 @@ export default { @@ -511,7 +515,6 @@ export default {
511 async doNewSubmit(param) { 515 async doNewSubmit(param) {
512 const { primaryKey = 'id', formPrimaryKey } = this.option || {}; 516 const { primaryKey = 'id', formPrimaryKey } = this.option || {};
513 if (this.option.newAPI) { // 配置了自定义查询API的情况 517 if (this.option.newAPI) { // 配置了自定义查询API的情况
514 - console.log('newAPI');  
515 this.dialogLoading = true; 518 this.dialogLoading = true;
516 try { 519 try {
517 const success = await this.option.newAPI(param); 520 const success = await this.option.newAPI(param);
@@ -526,7 +529,6 @@ export default { @@ -526,7 +529,6 @@ export default {
526 this.dialogLoading = false; 529 this.dialogLoading = false;
527 } 530 }
528 } else if (_$http && this.option.url) { // 给定了http的情况 531 } else if (_$http && this.option.url) { // 给定了http的情况
529 - console.log('_$http new');  
530 this.dialogLoading = true; 532 this.dialogLoading = true;
531 const postData = { ...param }; 533 const postData = { ...param };
532 delete postData[formPrimaryKey || primaryKey]; 534 delete postData[formPrimaryKey || primaryKey];
@@ -547,7 +549,6 @@ export default { @@ -547,7 +549,6 @@ export default {
547 // 编辑提交逻辑 549 // 编辑提交逻辑
548 async doEditSubmit(param) { 550 async doEditSubmit(param) {
549 if (this.option.editAPI) { // 配置了自定义查询API的情况 551 if (this.option.editAPI) { // 配置了自定义查询API的情况
550 - console.log('editAPI');  
551 this.dialogLoading = true; 552 this.dialogLoading = true;
552 try { 553 try {
553 const success = await this.option.editAPI(param); 554 const success = await this.option.editAPI(param);
@@ -562,7 +563,6 @@ export default { @@ -562,7 +563,6 @@ export default {
562 this.dialogLoading = false; 563 this.dialogLoading = false;
563 } 564 }
564 } else if (_$http && this.option.url) { // 给定了http的情况 565 } else if (_$http && this.option.url) { // 给定了http的情况
565 - console.log('_$http edit');  
566 this.dialogLoading = true; 566 this.dialogLoading = true;
567 _$http.post(`${this.option.url.trim('/')}/${this.option.editMethod || 'update'}`, param) 567 _$http.post(`${this.option.url.trim('/')}/${this.option.editMethod || 'update'}`, param)
568 .then(response => { 568 .then(response => {