文件上传方法改写

修复dialog关闭事件触发两次的问题
master
toesbieya 6 years ago
parent f3e08fd247
commit 08a6567e23
  1. 6
      vue/src/bizComponents/RegionSelector/index.vue
  2. 88
      vue/src/bizComponents/UploadFile/index.vue
  3. 2
      vue/src/config/request.js
  4. 12
      vue/src/mixins/bizDocumentDialogMixin.js
  5. 7
      vue/src/mixins/dialogMixin.js
  6. 23
      vue/src/utils/file.js
  7. 2
      vue/src/views/purchase/inbound/components/EditDialog.vue
  8. 7
      vue/src/views/purchase/inbound/components/OrderSelector.vue
  9. 4
      vue/src/views/purchase/order/components/EditDialog.vue
  10. 9
      vue/src/views/purchase/order/components/SupplierSelector.vue
  11. 9
      vue/src/views/sell/order/components/CustomerSelector.vue
  12. 4
      vue/src/views/sell/order/components/EditDialog.vue
  13. 7
      vue/src/views/sell/order/components/StockSelector.vue
  14. 2
      vue/src/views/sell/outbound/components/EditDialog.vue
  15. 7
      vue/src/views/sell/outbound/components/OrderSelector.vue
  16. 6
      vue/src/views/sell/outbound/components/StockSelector.vue
  17. 4
      vue/src/views/stock/current/DetailDialog.vue
  18. 6
      vue/src/views/system/customer/EditDialog.vue
  19. 6
      vue/src/views/system/department/components/EditDialog.vue
  20. 6
      vue/src/views/system/resource/EditDialog.vue
  21. 6
      vue/src/views/system/role/components/EditDialog.vue
  22. 6
      vue/src/views/system/supplier/EditDialog.vue
  23. 10
      vue/src/views/system/user/components/EditDialog.vue
  24. 8
      vue/src/views/userCenter/components/Account.vue
  25. 8
      vue/src/views/userCenter/components/Avatar.vue

@ -6,7 +6,7 @@
title="选择行政区域"
width="30%"
top="50px"
@close="$emit('input', false)"
@close="closeDialog"
>
<el-scrollbar>
<el-tree
@ -28,10 +28,12 @@
<script>
import {mapState} from 'vuex'
import dialogMixin from "@/mixins/dialogMixin"
import {createLimitTree, getNodeId} from "@/utils/tree"
export default {
name: "RegionSelector",
mixins: [dialogMixin],
props: {
value: Boolean,
limit: Boolean,
@ -53,7 +55,7 @@
let ids = getNodeId(obj.children)
ids.unshift(obj.id)
this.$emit('select', obj, ids)
this.$emit('input', false)
this.closeDialog()
},
init() {
this.loading = true

@ -44,11 +44,12 @@
* 传入fileList自动拼接七牛云外链前缀
* successremove事件中的file.url均不带七牛云外链前缀
* */
import {attachmentPrefix, attachmentUploadUrl} from '@/config'
import axios from 'axios'
import {attachmentPrefix} from '@/config'
import {elError} from "@/utils/message"
import {isEmpty, timeFormat} from '@/utils'
import {isEmpty} from '@/utils'
import {isImage} from "@/utils/validate"
import {deleteUpload, download, getToken, autoCompleteUrl} from "@/utils/file"
import {deleteUpload, download, upload, autoCompleteUrl} from "@/utils/file"
import {numberFormatter} from "@/filter"
export default {
@ -117,8 +118,10 @@
//remove
remove(file) {
//
//
if (!file.raw) this.$emit('remove', {...file, url: file.url.replace(attachmentPrefix, '')})
else if (!file.response.err) deleteUpload(file.raw.key)
//
else if (file.response && !file.response.err) deleteUpload(file.raw.key)
this.$refs.upload.handleRemove(file)
let index = this.data.findIndex(i => i.url === file.url)
@ -141,8 +144,9 @@
elError(`最多只能上传${this.limit}个文件`)
},
//success
//successkey
success(res, file) {
file.raw.key = res.key
this.data.push(file)
this.$emit('success', file, res)
},
@ -165,75 +169,31 @@
elError(`${file.name}的大小超出${numberFormatter(maxSize)}`)
return false
}
return getToken()
/*return getToken()
.then(token => {
let now = new Date()
file.token = token
file.key = timeFormat('yyyy/MM/dd/', now) + now.getTime() + '/' + file.name
})
})*/
},
//elementhttps://github.com/ElemeFE/element/blob/dev/packages/upload/src/ajax.js
httpRequest(option) {
const xhr = new XMLHttpRequest()
xhr.upload.onprogress = function progress(e) {
if (e.total > 0) {
e.percent = (Number)((e.loaded / e.total * 100).toFixed(2))
}
option.onProgress(e)
}
const formData = new FormData()
//
formData.append("token", option.file.token)
formData.append("key", option.file.key)
formData.append(option.filename, option.file, option.file.name)
xhr.onerror = function error(e) {
option.onError(e)
}
xhr.onload = function onload() {
if (xhr.status < 200 || xhr.status >= 300) {
return option.onError(getError(attachmentUploadUrl, option, xhr))
}
option.onSuccess(getBody(xhr))
}
xhr.open('post', attachmentUploadUrl, true)
xhr.send(formData)
return xhr
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const promise = upload(option.file, option.file.name, {
onUploadProgress(e) {
if (e.total > 0) {
e.percent = (Number)((e.loaded / e.total * 100).toFixed(2))
}
option.onProgress(e)
},
cancelToken: source.token
})
promise.abort = source.cancel
return promise
}
}
}
function getError(action, option, xhr) {
let msg
if (xhr.response) msg = `${xhr.response.error || xhr.response}`
else if (xhr.responseText) msg = `${xhr.responseText}`
else msg = `fail to post ${action} ${xhr.status}`
const err = new Error(msg)
err.status = xhr.status
err.method = 'post'
err.url = action
return err
}
function getBody(xhr) {
const text = xhr.responseText || xhr.response
if (!text) return text
try {
return JSON.parse(text)
}
catch (e) {
return text
}
}
</script>
<style lang="scss">
.disabled .el-upload--picture-card {

@ -64,7 +64,7 @@ service.interceptors.response.use(
return Promise.reject(res)
},
error => {
console.log(error)
if (axios.isCancel(error)) return
error && Notification.error({
title: '错误',
message: '请求错误,请稍后重试'

@ -3,6 +3,7 @@ import DialogForm from '@/bizComponents/DialogForm'
import DialogFormItem from "@/bizComponents/DialogForm/DialogFormItem"
import DocumentSteps from '@/bizComponents/DocumentSteps'
import DocumentHistory from '@/bizComponents/DocumentHistory'
import dialogMixin from "@/mixins/dialogMixin"
import {commonMethods} from "@/mixins/bizDocumentTableMixin"
import {isEmpty, mergeObj, resetObj, timeFormat} from '@/utils'
import {elAlert, elConfirm, elPrompt, elSuccess} from "@/utils/message"
@ -11,6 +12,7 @@ import {deleteUpload} from "@/utils/file"
import {auth} from "@/utils/auth"
export default {
mixins: [dialogMixin],
components: {DialogForm, DialogFormItem, DocumentSteps, DocumentHistory, UploadFile},
props: {
//dialog显隐
@ -172,7 +174,7 @@ export default {
elSuccess(msg)
this.$emit('success', 'pass')
this.needSearch = true
this.cancel()
this.closeDialog()
})
.finally(() => this.loading = false)
},
@ -189,7 +191,7 @@ export default {
elSuccess(msg)
this.$emit('success', 'reject')
this.needSearch = true
this.cancel()
this.closeDialog()
})
.finally(() => this.loading = false)
},
@ -226,7 +228,7 @@ export default {
init(id) {
this.loading = true
if (isEmpty(id)) {
return elAlert(`获取${this.documentName}数据失败,请传入id`, () => this.cancel())
return elAlert(`获取${this.documentName}数据失败,请传入id`, this.closeDialog)
}
this.api.getById(id)
.then(data => {
@ -250,7 +252,7 @@ export default {
//关闭dialog并清除单据数据
cancel() {
this.$emit('input', false)
this.closeDialog()
if (this.needSearch) this.$emit('search')
//删除未保存的上传附件
let deleteArr = []
@ -260,7 +262,7 @@ export default {
if (deleteArr.length > 0) {
deleteUpload(deleteArr).catch(e => ({}))
}
setTimeout(() => this.clearForm(), 500)
setTimeout(() => this.clearForm(), 200)
this.loading = false
},

@ -0,0 +1,7 @@
export default {
methods: {
closeDialog() {
this.$emit('input', false)
}
}
}

@ -4,8 +4,15 @@ import {isEmpty, timeFormat} from "@/utils"
const baseUrl = '/file'
const formConfig = {
headers: {"Content-Type": "multipart/form-data"}
const defaultOptions = {
headers: {"Content-Type": "multipart/form-data"},
generateKey(filename) {
const now = new Date()
return timeFormat('yyyy/MM/dd/') + now.getTime() + '/' + filename
},
onUploadProgress(e) {
}
}
//获取七牛云直传需要的token
@ -31,17 +38,17 @@ export function deleteUpload(url) {
}
//七牛云直传
export function upload(blob, filename = '快照.png') {
export function upload(blob, filename = '快照.png', options = defaultOptions) {
return getToken()
.then(token => {
let now = new Date()
let param = new FormData()
const param = new FormData()
options = {...options, ...defaultOptions}
param.append('token', token)
param.append('key', timeFormat('yyyy/MM/dd/') + now.getTime() + '/' + filename)
param.append('key', options.generateKey(filename))
param.append('file', blob, filename)
return request.post(attachmentUploadUrl, param, {...formConfig, baseUrl: ''})
return request.post(attachmentUploadUrl, param, options)
})
.then(({data}) => data.key)
.then(({data}) => data)
}
//自动补全附件链接前缀

@ -74,7 +74,7 @@
<order-selector v-model="parentDialog" @select="selectParent"/>
<template v-slot:footer>
<span v-if="form.status===2" class="seal">已审核</span>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canSave" size="small" type="primary" @click="save"> </el-button>
<el-button v-if="canCommit" size="small" type="primary" @click="commit"> </el-button>
<el-button v-if="canWithdraw" size="small" type="danger" @click="withdraw"> </el-button>

@ -12,7 +12,7 @@
<el-scrollbar>
<el-row>
<el-button icon="el-icon-search" size="small" type="success" @click="search"> </el-button>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
</el-row>
<el-table
v-loading="config.loading"
@ -69,13 +69,14 @@
<script>
import LinerProgress from '@/components/LinerProgress'
import dialogMixin from "@/mixins/dialogMixin"
import tableMixin from '@/mixins/tablePageMixin'
import {getSubById, search} from "@/api/purchase/order"
import {elError} from "@/utils/message"
export default {
name: "OrderSelector",
mixins: [tableMixin],
mixins: [dialogMixin, tableMixin],
components: {LinerProgress},
props: {value: Boolean},
data() {
@ -119,7 +120,7 @@
this.cancel()
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.tableData = []
}
}

@ -103,7 +103,7 @@
<template v-slot:footer>
<span v-if="form.status===2" class="seal">已审核</span>
<span v-if="form.finish===2" class="seal">已完成</span>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canSave" size="small" type="primary" @click="save"> </el-button>
<el-button v-if="canCommit" size="small" type="primary" @click="commit"> </el-button>
<el-button v-if="canWithdraw" size="small" type="danger" @click="withdraw"> </el-button>
@ -111,7 +111,7 @@
<el-button v-if="canReject" size="small" type="danger" @click="reject"> </el-button>
</template>
<supplier-selector v-model="supplierDialog" @select="selectSupplier" @jump="$emit('input',false)"/>
<supplier-selector v-model="supplierDialog" @select="selectSupplier" @jump="closeDialog"/>
</dialog-form>
</template>

@ -12,7 +12,7 @@
<el-row>
<el-button icon="el-icon-search" size="small" type="success" @click="search"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button
v-if="canGoToSysSupplierPage"
plain
@ -66,6 +66,7 @@
<script>
import LinerProgress from '@/components/LinerProgress'
import dialogMixin from "@/mixins/dialogMixin"
import tableMixin from '@/mixins/tablePageMixin'
import {getSuppliers} from "@/api/system/supplier"
import {elError} from "@/utils/message"
@ -73,7 +74,7 @@
export default {
name: "SupplierSelector",
mixins: [tableMixin],
mixins: [dialogMixin, tableMixin],
components: {LinerProgress},
props: {value: Boolean},
data() {
@ -110,11 +111,11 @@
this.cancel()
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.tableData = []
},
goToSysSupplierPage() {
this.$emit('input', false)
this.closeDialog()
this.$emit('jump')
this.$nextTick(() => this.$router.push('/system/supplier'))
}

@ -12,7 +12,7 @@
<el-row>
<el-button icon="el-icon-search" size="small" type="success" @click="search"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button
v-if="canGoToSysCustomerPage"
plain
@ -66,6 +66,7 @@
<script>
import LinerProgress from '@/components/LinerProgress'
import dialogMixin from "@/mixins/dialogMixin"
import tableMixin from '@/mixins/tablePageMixin'
import {getCustomers} from "@/api/system/customer"
import {elError} from "@/utils/message"
@ -73,7 +74,7 @@
export default {
name: "CustomerSelector",
mixins: [tableMixin],
mixins: [dialogMixin, tableMixin],
components: {LinerProgress},
props: {value: Boolean},
data() {
@ -109,11 +110,11 @@
this.$emit('select', this.row)
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.tableData = []
},
goToSysCustomerPage() {
this.$emit('input', false)
this.closeDialog()
this.$emit('jump')
this.$nextTick(() => this.$router.push('/system/customer'))
}

@ -90,7 +90,7 @@
<template v-slot:footer>
<span v-if="form.status===2" class="seal">已审核</span>
<span v-if="form.finish===2" class="seal">已完成</span>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canSave" size="small" type="primary" @click="save"> </el-button>
<el-button v-if="canCommit" size="small" type="primary" @click="commit"> </el-button>
<el-button v-if="canWithdraw" size="small" type="danger" @click="withdraw"> </el-button>
@ -99,7 +99,7 @@
</template>
<stock-selector v-model="stockDialog" @select="selectStock"/>
<customer-selector v-model="customerDialog" @select="selectCustomer" @jump="$emit('input',false)"/>
<customer-selector v-model="customerDialog" @select="selectCustomer" @jump="closeDialog"/>
</dialog-form>
</template>

@ -13,7 +13,7 @@
<el-row>
<el-button icon="el-icon-search" size="small" type="success" @click="search"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
</el-row>
<el-row class="table-container">
<liner-progress :show="config.loading"/>
@ -43,13 +43,14 @@
<script>
import LinerProgress from '@/components/LinerProgress'
import dialogMixin from "@/mixins/dialogMixin"
import tableMixin from '@/mixins/tablePageMixin'
import {search} from "@/api/stock/current"
import {elError} from "@/utils/message"
export default {
name: "StockSelector",
mixins: [tableMixin],
mixins: [dialogMixin, tableMixin],
components: {LinerProgress},
props: {value: Boolean},
data() {
@ -74,7 +75,7 @@
this.$emit('select', this.selection)
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.$refs.table.clearSelection()
this.tableData = []
}

@ -88,7 +88,7 @@
<stock-selector v-model="stockDialog" :cid="row?row.cid:null" @select="selectStock"/>
<template v-slot:footer>
<span v-if="form.status===2" class="seal">已审核</span>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canSave" size="small" type="primary" @click="save"> </el-button>
<el-button v-if="canCommit" size="small" type="primary" @click="commit"> </el-button>
<el-button v-if="canWithdraw" size="small" type="danger" @click="withdraw"> </el-button>

@ -12,7 +12,7 @@
<el-scrollbar>
<el-row>
<el-button icon="el-icon-search" size="small" type="success" @click="search"> </el-button>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
</el-row>
<el-table
v-loading="config.loading"
@ -69,13 +69,14 @@
<script>
import LinerProgress from '@/components/LinerProgress'
import dialogMixin from "@/mixins/dialogMixin"
import tableMixin from '@/mixins/tablePageMixin'
import {getSubById, search} from "@/api/sell/order"
import {elError} from "@/utils/message"
export default {
name: "OrderSelector",
mixins: [tableMixin],
mixins: [dialogMixin, tableMixin],
components: {LinerProgress},
props: {value: Boolean},
data() {
@ -119,7 +120,7 @@
this.cancel()
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.tableData = []
}
}

@ -13,7 +13,7 @@
<el-row>
<el-button icon="el-icon-search" size="small" type="success" @click="search"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
</el-row>
<el-row class="table-container">
<liner-progress :show="loading"/>
@ -36,12 +36,14 @@
</template>
<script>
import dialogMixin from "@/mixins/dialogMixin"
import LinerProgress from '@/components/LinerProgress'
import {getDetail} from "@/api/stock/current"
import {elError} from "@/utils/message"
export default {
name: "StockSelector",
mixins: [dialogMixin],
components: {LinerProgress},
props: {
value: Boolean,
@ -69,7 +71,7 @@
this.$emit('select', this.selection)
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.$refs.table.clearSelection()
this.tableData = []
}

@ -33,11 +33,13 @@
<script>
import LinerProgress from '@/components/LinerProgress'
import DialogForm from "@/bizComponents/DialogForm"
import dialogMixin from "@/mixins/dialogMixin"
import {isEmpty, mul, plus} from "@/utils"
import {getDetail} from "@/api/stock/current"
export default {
name: "DetailDialog",
mixins: [dialogMixin],
components: {LinerProgress, DialogForm},
props: {value: Boolean, title: String, cid: Number},
data() {
@ -95,7 +97,7 @@
}
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.tableData = []
}
}

@ -41,7 +41,7 @@
</el-form-item>
</el-form>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canEdit" size="small" type="primary" @click="confirm"> </el-button>
</template>
@ -52,12 +52,14 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import RegionSelector from '@/bizComponents/RegionSelector'
import dialogMixin from "@/mixins/dialogMixin"
import {addCustomer, updateCustomer} from "@/api/system/customer"
import {isEmpty, mergeObj, resetObj} from '@/utils'
import {elConfirm} from "@/utils/message"
export default {
name: "EditDialog",
mixins: [dialogMixin],
components: {DialogForm, RegionSelector},
props: {
value: {type: Boolean, default: false},
@ -133,7 +135,7 @@
this.$nextTick(() => this.$refs.form.clearValidate())
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clearForm()
},
confirm() {

@ -22,7 +22,7 @@
</el-form-item>
</el-form>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
</template>
</dialog-form>
@ -30,12 +30,14 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import dialogMixin from "@/mixins/dialogMixin"
import {addDepartment, updateDepartment} from "@/api/system/department"
import {isEmpty} from '@/utils'
import {elConfirm, elSuccess} from "@/utils/message"
export default {
name: "EditDialog",
mixins: [dialogMixin],
components: {DialogForm},
props: {
value: {type: Boolean, default: false},
@ -103,7 +105,7 @@
this.$nextTick(() => this.$refs.form.clearValidate())
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clearForm()
},
confirm() {

@ -22,7 +22,7 @@
</el-form-item>
</el-form>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
</template>
</dialog-form>
@ -30,11 +30,13 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import dialogMixin from "@/mixins/dialogMixin"
import {updateResource} from "@/api/system/resource"
import {mergeObj, resetObj} from '@/utils'
export default {
name: "EditDialog",
mixins: [dialogMixin],
components: {DialogForm},
props: {
value: {type: Boolean, default: false},
@ -61,7 +63,7 @@
this.$nextTick(() => mergeObj(this.form, this.data))
},
cancel() {
this.$emit('input', false)
this.closeDialog()
resetObj(this.form)
this.$nextTick(() => this.$refs.form.clearValidate())
},

@ -40,7 +40,7 @@
<el-dropdown-item :command="{action:'expand',level:1}">仅展开一级</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
</template>
</dialog-form>
@ -48,12 +48,14 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import dialogMixin from "@/mixins/dialogMixin"
import {addRole, updateRole} from "@/api/system/role"
import {isEmpty, mergeObj} from '@/utils'
import {elTreeControl} from '@/utils/tree'
export default {
name: "EditDialog",
mixins: [dialogMixin],
components: {DialogForm},
props: {
value: {type: Boolean, default: false},
@ -120,7 +122,7 @@
this.$nextTick(() => this.$refs.form.clearValidate())
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clearForm()
},
confirm() {

@ -41,7 +41,7 @@
</el-form-item>
</el-form>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canEdit" size="small" type="primary" @click="confirm"> </el-button>
</template>
@ -52,12 +52,14 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import RegionSelector from '@/bizComponents/RegionSelector'
import dialogMixin from "@/mixins/dialogMixin"
import {addSupplier, updateSupplier} from "@/api/system/supplier"
import {isEmpty, mergeObj, resetObj} from '@/utils'
import {elConfirm} from "@/utils/message"
export default {
name: "EditDialog",
mixins: [dialogMixin],
components: {DialogForm, RegionSelector},
props: {
value: {type: Boolean, default: false},
@ -132,7 +134,7 @@
this.$nextTick(() => this.$refs.form.clearValidate())
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clearForm()
},
confirm() {

@ -22,7 +22,7 @@
</el-form-item>
</el-form>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button v-if="canEdit" size="small" type="primary" @click="confirm"> </el-button>
</template>
</dialog-form>
@ -31,12 +31,14 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import RoleSelector from './RoleSelector'
import dialogMixin from "@/mixins/dialogMixin"
import {addUser, updateUser, checkName} from "@/api/system/user"
import {isEmpty} from '@/utils'
import {elConfirm} from "@/utils/message"
export default {
name: "EditDialog",
mixins: [dialogMixin],
components: {DialogForm, RoleSelector},
props: {
value: {type: Boolean, default: false},
@ -113,7 +115,7 @@
this.$nextTick(() => this.$refs.form.clearValidate())
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clearForm()
},
confirm() {
@ -125,9 +127,7 @@
this.loading = true
return this.type === 'add' ? addUser(this.form) : updateUser(this.form)
})
.then(({msg}) => {
this.$emit('success', msg)
})
.then(({msg}) => this.$emit('success', msg))
.finally(() => this.loading = false)
})
}

@ -17,7 +17,7 @@
</el-form-item>
</el-form>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
</template>
</dialog-form>
@ -25,10 +25,12 @@
<script>
import DialogForm from '@/bizComponents/DialogForm'
import dialogMixin from "@/mixins/dialogMixin"
import {updateUserPwd} from "@/api/system/user"
import {elSuccess} from "@/utils/message"
export default {
mixins: [dialogMixin],
components: {DialogForm},
data() {
return {
@ -73,12 +75,12 @@
.then(() => elSuccess('修改成功'))
.finally(() => {
this.loading = false
this.cancel()
this.closeDialog()
})
})
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clearForm()
}
}

@ -36,7 +36,7 @@
</div>
</el-row>
<template v-slot:footer>
<el-button plain size="small" @click="cancel"> </el-button>
<el-button plain size="small" @click="closeDialog"> </el-button>
<el-button size="small" type="primary" @click="confirm"> </el-button>
</template>
</dialog-form>
@ -45,12 +45,14 @@
<script>
import {VueCropper} from 'vue-cropper'
import DialogForm from '@/bizComponents/DialogForm'
import dialogMixin from "@/mixins/dialogMixin"
import {elError, elSuccess} from "@/utils/message"
import {autoCompleteUrl, upload} from "@/utils/file"
import {updateAvatar} from "@/api/system/user"
export default {
name: "Avatar",
mixins: [dialogMixin],
components: {VueCropper, DialogForm},
props: {
value: Boolean
@ -88,7 +90,7 @@
this.loading = true
this.$refs.cropper.getCropBlob(data => {
upload(new Blob([data]), this.name)
.then(key => updateAvatar(key))
.then(({key}) => updateAvatar(key))
.then(({key, msg}) => {
this.$store.commit('user/avatar', autoCompleteUrl(key))
this.$store.dispatch('user/refresh')
@ -112,7 +114,7 @@
},
cancel() {
this.$emit('input', false)
this.closeDialog()
this.clear()
}
}

Loading…
Cancel
Save