前端封装的一些常用的方法
复杂数组中的对象去重
1 | var array = [{id:'1',name:'沈杰鑫'},{id:'1',name:'沈杰鑫'},{id:'1',name:'沈杰鑫'},{id:'1',name:'沈杰鑫'}] |
Element多选表格回显
需求:进行列表的选中操作,然后点击下一页,再返回,之前选中的记录就没有了。
设计思路:
进入多选表界面
选中多选框,使用:
@select=”handleSelection”
@select-all=”handleSelection”
当选中当个或者多个都会触发事件:handleSelection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36handleSelection(row) {
//将此行的数据赋值给toDeviceList
this.toDeviceList = row
//调用数据设置到对象的函数
this.setDeviceList()
}
// 将选中的数据保存起来
setDeviceList() {
//获取当前page为第几页
//currentPage当前页数
this.currentPage = this.deviceParams.pageNum
//将当前页选中的数据赋值给devicePageList对象中的key值
this.devicePageList[this.currentPage] = this.toDeviceList
}
// 多选表格回显
getDeviceList() {
this.$nextTick(() => {
//获取当前页数
this.currentPage = this.deviceParams.pageNum
//判断数据是否为空,为空则不进行回显
if (this.deviceToGroupTableData !== undefined && this.devicePageList[this.currentPage] !== undefined) {
//获取当前页选中的数据
this.devicePageList[this.currentPage].forEach((v, i) => {
//获取后端返回此页的数据
this.deviceToGroupTableData.forEach((_v, _i) => {
//判断选中的数据在此页是否有存在
if (v.deviceId === _v.deviceId) {
//有存在:将此条数据回显到界面上
this.$refs.deviceToGroupTableData.toggleRowSelection(_v)
}
})
})
}
})
}
每次进行分页点击后,进行回显函数调用
视频首帧截取
1 | <div class="dialog_pan_img"> |
JavaScript生成唯一ID
的方式:
UUID
1 | guid() { |