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

duizhaopin_ui
duan 2 years ago
parent 9c763b3fe9
commit fbff08cc9c

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

@ -115,3 +115,37 @@ export function param2Obj(url) {
}) })
return obj 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) { pageChange(page) {
this.page = page this.page = page
this.getList()
}, },
handleCheckAllChange(val) { handleCheckAllChange(val) {
this.checkedCities = val ? this.cities : [] this.checkedCities = val ? this.cities : []
@ -276,10 +277,14 @@ export default {
type: 'warning' type: 'warning'
}).then(() => }).then(() =>
del(stringify({ 'user_id': this.multipleSelection[0].user })).then( del(stringify({ 'user_id': this.multipleSelection[0].user })).then(
res => this.$message.success({ res => {
type: 'success', this.$message.success({
message: res.msg type: 'success',
}) message: res.msg
})
this.multipleSelection = []
this.getList()
}
) )
).catch(() => { ).catch(() => {
this.$message({ this.$message({

Loading…
Cancel
Save