feat(src/views/user): 为新增用户,编辑用户添加节流功能

duizhaopin_ui
duan 2 years ago
parent 9c763b3fe9
commit fbff08cc9c

@ -53,7 +53,7 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="是否启用" prop="is_enabled" required>
<el-form-item label="是否启用" prop="is_enabled">
<el-switch v-model="formData.is_enabled" />
</el-form-item>
</el-col>
@ -66,6 +66,7 @@
</div>
</template>
<script>
import { throttle } from '@/utils/index'
export default {
name: 'UserForm',
components: {},
@ -138,12 +139,13 @@ export default {
created() {},
mounted() {},
methods: {
submitForm() {
submitForm: throttle(function() {
this.$refs['elForm'].validate(valid => {
if (!valid) return
this.$emit('handlesubmit', this.formData)
})
},
}, 2000),
resetForm() {
this.$refs['elForm'].resetFields()
},

@ -115,3 +115,37 @@ export function param2Obj(url) {
})
return obj
}
// 防抖
export function debounce(fn, time) {
time = time || 200
// 定时器
let timer = null
return function(...args) {
var _this = this
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(function() {
timer = null
fn.apply(_this, args)
}, time)
}
}
// 节流
export function throttle(fn, time) {
let timer = null
time = time || 1000
return function(...args) {
if (timer) {
return
}
const _this = this
timer = setTimeout(() => {
timer = null
}, time)
fn.apply(_this, args)
}
}

@ -209,6 +209,7 @@ export default {
},
pageChange(page) {
this.page = page
this.getList()
},
handleCheckAllChange(val) {
this.checkedCities = val ? this.cities : []
@ -276,10 +277,14 @@ export default {
type: 'warning'
}).then(() =>
del(stringify({ 'user_id': this.multipleSelection[0].user })).then(
res => this.$message.success({
res => {
this.$message.success({
type: 'success',
message: res.msg
})
this.multipleSelection = []
this.getList()
}
)
).catch(() => {
this.$message({

Loading…
Cancel
Save