From 42104f6047bd39b91ac55bd6252b8944b43d24f3 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 11 Jun 2020 16:48:28 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9profile=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E6=9B=B4=E6=96=B0remote=20?= =?UTF-8?q?apps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/GenericCreateUpdateForm/index.vue | 8 ++++---- src/userviews/users/UserProfile/ProfileInfo.vue | 11 ++++++++--- .../applications/RemoteApp/RemoteAppCreateUpdate.vue | 2 +- .../CommandFilterDetail/RulesCreateUpdate.vue | 9 ++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/layout/components/GenericCreateUpdateForm/index.vue b/src/layout/components/GenericCreateUpdateForm/index.vue index a64a02cf7..1288923aa 100644 --- a/src/layout/components/GenericCreateUpdateForm/index.vue +++ b/src/layout/components/GenericCreateUpdateForm/index.vue @@ -5,7 +5,7 @@ :method="method" :form="form" :fields="fields" - :url="totalUrl" + :url="iUrl" :is-submitting="isSubmitting" v-bind="$attrs" v-on="$listeners" @@ -116,7 +116,7 @@ export default { method() { return this.getMethod(this) }, - totalUrl() { + iUrl() { return this.getUrl() } }, @@ -137,7 +137,7 @@ export default { return handler(values) }, defaultPerformSubmit(validValues) { - return this.$axios[this.method](this.totalUrl, validValues) + return this.$axios[this.method](this.iUrl, validValues) }, defaultOnSubmit(validValues) { const performSubmit = this.performSubmit || this.defaultPerformSubmit @@ -178,7 +178,7 @@ export default { return object }, async getObjectDetail() { - return this.$axios.get(this.totalUrl) + return this.$axios.get(this.iUrl) } } } diff --git a/src/userviews/users/UserProfile/ProfileInfo.vue b/src/userviews/users/UserProfile/ProfileInfo.vue index b562de63c..d89a1df17 100644 --- a/src/userviews/users/UserProfile/ProfileInfo.vue +++ b/src/userviews/users/UserProfile/ProfileInfo.vue @@ -9,7 +9,7 @@ a - From a20e1c16181d5ad03f0591a583285430e20d03e8 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 11 Jun 2020 17:56:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?org=E5=90=8E=E9=9C=80=E8=A6=81=E5=88=B7=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=9B=B4=E6=96=B0form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericCreateUpdateForm/index.vue | 85 +++++++++---------- src/store/modules/users.js | 6 ++ src/views/xpack/InterfaceSettings.vue | 15 +--- .../xpack/Org/OrganizationCreateUpdate.vue | 10 ++- src/views/xpack/router.js | 15 ++-- 5 files changed, 69 insertions(+), 62 deletions(-) diff --git a/src/layout/components/GenericCreateUpdateForm/index.vue b/src/layout/components/GenericCreateUpdateForm/index.vue index 1288923aa..491ecda72 100644 --- a/src/layout/components/GenericCreateUpdateForm/index.vue +++ b/src/layout/components/GenericCreateUpdateForm/index.vue @@ -4,7 +4,6 @@ ref="form" :method="method" :form="form" - :fields="fields" :url="iUrl" :is-submitting="isSubmitting" v-bind="$attrs" @@ -24,12 +23,6 @@ export default { type: String, default: '' }, - fields: { - type: Array, - default: () => { - return [] - } - }, object: { type: Object, default: null @@ -48,7 +41,9 @@ export default { }, performSubmit: { type: Function, - default: null + default(validValues) { + return this.$axios[this.method](this.iUrl, validValues) + } }, createSuccessMsg: { type: String, @@ -76,6 +71,12 @@ export default { return { name: routeName } } }, + getNextRoute: { + type: Function, + default(res, method) { + return method === 'post' ? this.createSuccessNextRoute : this.updateSuccessNextRoute + } + }, getMethod: { type: Function, default: function() { @@ -87,12 +88,6 @@ export default { } } }, - getNextRoute: { - type: Function, - default(res, method) { - return method === 'post' ? this.createSuccessNextRoute : this.updateSuccessNextRoute - } - }, getUrl: { type: Function, default: function() { @@ -103,6 +98,33 @@ export default { } return url } + }, + onPerformSuccess: { + type: Function, + default(res, method, vm) { + const msg = method === 'post' ? this.createSuccessMsg : this.updateSuccessMsg + const route = this.getNextRoute(res, method) + this.$emit('submitSuccess', res) + this.$message.success(msg) + setTimeout(() => this.$router.push(route), 100) + } + }, + onPerformError: { + type: Function, + default(error, method, vm) { + this.$emit('submitError', error) + const response = error.response + const data = response.data + if (response.status === 400) { + for (const key of Object.keys(data)) { + let value = data[key] + if (value instanceof Array) { + value = value.join(';') + } + this.$refs.form.setFieldError(key, value) + } + } + } } }, data() { @@ -120,7 +142,7 @@ export default { return this.getUrl() } }, - async mounted() { + async created() { this.loading = true try { const values = await this.getFormValue() @@ -136,36 +158,12 @@ export default { values = this.cleanFormValue(values) return handler(values) }, - defaultPerformSubmit(validValues) { - return this.$axios[this.method](this.iUrl, validValues) - }, defaultOnSubmit(validValues) { - const performSubmit = this.performSubmit || this.defaultPerformSubmit - const msg = this.method === 'post' ? this.createSuccessMsg : this.updateSuccessMsg - const event = this.method === 'post' ? 'createSuccess' : 'updateSuccess' this.isSubmitting = true - performSubmit(validValues).then((res) => { - const route = this.getNextRoute(res, this.method) - this.$emit(event, res) - this.$emit('submitSuccess', res) - this.$message.success(msg) - setTimeout(() => this.$router.push(route), 100) - }).catch(error => { - this.$emit('submitError', error) - const response = error.response - const data = response.data - if (response.status === 400) { - for (const key of Object.keys(data)) { - let value = data[key] - if (value instanceof Array) { - value = value.join(';') - } - this.$refs.form.setFieldError(key, value) - } - } - }).finally(() => { - this.isSubmitting = false - }) + this.performSubmit(validValues) + .then((res) => this.onPerformSuccess.bind(this)(res, this.method, this)) + .catch((error) => this.onPerformError(error, this.method, this)) + .finally(() => { this.isSubmitting = false }) }, async getFormValue() { if (this.method !== 'put') { @@ -174,6 +172,7 @@ export default { let object = this.object if (object === null) { object = await this.getObjectDetail() + this.$emit('update:object', object) } return object }, diff --git a/src/store/modules/users.js b/src/store/modules/users.js index aa120f1c8..f30f90ba4 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -37,6 +37,9 @@ const mutations = { SET_ORGS: (state, orgs) => { state.orgs = orgs }, + ADD_ORG: (state, org) => { + state.orgs.push(org) + }, SET_ROLES(state, roles) { state.roles = roles }, @@ -119,6 +122,9 @@ const actions = { }).catch((e) => reject(e)) }) }, + addAdminOrg({ commit, state }, org) { + commit('ADD_ORG', org) + }, // user logout logout({ commit, state }) { return new Promise((resolve, reject) => { diff --git a/src/views/xpack/InterfaceSettings.vue b/src/views/xpack/InterfaceSettings.vue index 29b1c4035..e63859dcf 100644 --- a/src/views/xpack/InterfaceSettings.vue +++ b/src/views/xpack/InterfaceSettings.vue @@ -1,5 +1,5 @@