# ele-mock **Repository Path**: jxmlearner/ele-mock ## Basic Information - **Project Name**: ele-mock - **Description**: No description available - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-11 - **Last Updated**: 2021-09-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 一、一些笔记 1. 处理tree数据 ```js // 获取绝对岗位-岗位树 getDepartmentPostRightTreeData () { this.$Geting(this.$api.getGrantListPositionTree, {appId: this.$appId}).then((res = {}) => { if (res.code === '0') { let resData = res.data || []; const loopFn = (treeDataArr) => { treeDataArr.forEach(item => { item.checkboxDisabled = true; loopFn(item.children); }); }; loopFn(resData); this.departmentPostRightTreeData = resData; } }); } ``` 2. `git log --oneline` 退出: 英文状态下按 q 如果记录过多,则按Page Up、Page Down、↓、↑来控制显示;按q退出历史记录列表。 3. swiper使用 + 使用参考: https://www.jianshu.com/p/1cd13ed541dd + https://www.swiper.com.cn/demo/240-effect-coverflow.html + https://www.swiper.com.cn 在vue中使用 https://github.surmon.me/vue-awesome-swiper/ `cnpm i swiper vue-awesome-swiper -S` 3. 简单的递归使用 ```js // 验证权限菜单 const checkAuthMenu = (menuPath, menuList) => { let isAuthMenu = false; const loopFn = (treeDataArr) => { for (let i = 0;i < treeDataArr.length;i++) { if (treeDataArr[i].menuUrl === menuPath) { isAuthMenu = true; break; } else { loopFn(treeDataArr[i].children); } } }; loopFn(menuList); return isAuthMenu; }; // 获取权限菜单中的第一个 const firstAuthMenu = (menuList) => { let firstMenu = ''; const loopFn = (treeDataArr) => { for (let i = 0;i < treeDataArr.length;i++) { if (treeDataArr[i].menuUrl) { firstMenu = firstMenu || treeDataArr[i].menuUrl; break; } else { loopFn(treeDataArr[i].children); } } }; loopFn(menuList); return firstMenu; }; ``` 4. el-date-picker 日期选择控件的日期范围控制 ```js pickerOptions: { disabledDate: time => { return time.getTime() < this.curImmigrationDate } } ``` 5. 表单数据有变化时点关闭才会弹出确认框 + 参考:https://www.csdn.net/gather_23/MtTaAg0sODkwMy1ibG9n.html ```js export default { name: 'checkItemForm', data () { return { ruleForm: { customerName: this.customerMoveOutItem.customerName, // 客户姓名 customerPhone: this.customerMoveOutItem.customerPhone, // 电话号码 customerCode: this.customerMoveOutItem.customerCode, // 客户编码 houseName: '', // 选中的房屋名称 customerId:this.customerMoveOutItem.customerId, // 客户ID customerHouseId: '', // 房屋关联ID houseId: '', // 房屋ID moveOutDate: '', // 迁出日期 remark: '', // 备注 houseList: [], houseCode: '' }, pickerOptions: { disabledDate: time => { return time.getTime() < this.curImmigrationDate } }, preFormData: null, // 表单的原始值 hasChangedFormData: false // 用这个来标识表单数据是否变更了 }; }, created () { let self = this; this.ruleForm.houseList = []; this.customerMoveOutItem.houseList.forEach(function(item){ if (item.delFlag == 0 && item.identityName !== '业主') { // 迁出房屋只针对租户 // debugger; self.ruleForm.houseList.push(item); } }) }, mounted () { // console.log(this.customerMoveOutItem, '迁出客户的数据'); this.preFormData = Object.assign({}, this.ruleForm) }, watch: { ruleForm: { handler: function(newVal, oldVal) { for(let i in this.ruleForm) { if (newVal[i] != this.preFormData[i]) { this.hasChangedFormData = true; break; } else { this.hasChangedFormData = false; } } }, deep: true } }, methods: { dialogCloseed () { if (this.hasChangedFormData) { // 数据更改了才弹出确认框 this.$confirm('当前编辑的内容尚未保存,是否确认取消保存?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => { // this.doSave(); this.$emit('dialogClose'); }).catch(() => {}); } else { this.$emit('dialogClose'); } } } }; ``` 6. 树数据量很大的处理 https://github.com/pengqiangsheng/vue-magic-tree https://www.jianshu.com/p/ddb9ab507cfd 安装: `cnpm i vue-magic-tree -S` 7. 动态设置表单字段的 required ```html ``` 8. vue中拖拽 + 1. `cnpm i vuedraggable -S` + 2. `https://github.com/SortableJS/Vue.Draggable` 9. 同级div设置display:inline-block,父级div强制不换行 ```html
测试测试
测试测试
测试测试
测试测试
测试测试
``` 10. vue中自定义指令 ``` Vue.directive('foucs', { inserted: function(el, binding, vnode, oldVnode) { el.focus(); } }) ``` 11. echarts的tooltip自动播放 参考地址:https://blog.csdn.net/LZY_1993/article/details/78630805 12. el-scrollbar的滚动事件监听 https://www.cnblogs.com/lwlblog/p/13283681.html 13. vue-treeselect cnpm install --save @riophae/vue-treeselect 14. 自定义过滤器 ```js filters: { transformTime (val) { if (!val) return ''; let date = new Date(val); let y = date.getFullYear(); let m = date.getMonth() + 1; let d = date.getDate(); let h = date.getHours(); let minute = date.getMinutes(); d = d < 10 ? ('0' + d) : d; h = h < 10 ? ('0' + h) : h; m = m < 10 ? ('0' + m) : m; minute = minute < 10 ? ('0' + minute) : minute; return `${y}-${m}-${d} ${h}:${minute}`; } } ``` 15. vue自带的打包报告 `npm run build -- --report` 16. 深拷贝 ```js export const deepClone = obj => { //判断拷贝的要进行深拷贝的是数组还是对象,是数组的话进行数组拷贝,对象的话进行对象拷贝 var objClone = Array.isArray(obj) ? [] : {}; //进行深拷贝的不能为空,并且是对象或者是 if (obj && typeof obj === "object") { for (let key in obj) { if (obj.hasOwnProperty(key)) { if (obj[key] && typeof obj[key] === "object") { objClone[key] = deepClone(obj[key]); } else { objClone[key] = obj[key]; } } } } return objClone; } ``` 17. js判断是否在iframe中 ``` 1.方式一 if (self.frameElement && self.frameElement.tagName == "IFRAME") {   alert('在iframe中'); } 2.方式二 if (window.frames.length != parent.frames.length) {   alert('在iframe中'); } 3.方式三 if (self != top) {   alert('在iframe中'); } 以上用任何一种都可以判断代码是否在iframe中. ``` 18. 移动端如果使用了faskclick 在IOS下,``需要双击才能打开 ``` import FastClick from 'fastclick'; FastClick.attach(document.body); // 解决移动端300ms延迟 ``` 只需要在元素上增加 class='needsclick' ``` ``` 19. 过滤数组中属性值相同的项 ```js [ { a:1, b:4 }, { a:2, b:4 }, { a:3, b:5 }, ].reduce( (cur,next) => { if(!cur.some(x => x.b === next.b)) { cur.push(next); } return cur },[]) ``` 20. 过滤表情 ``` ``` 21. 移动端的拖拽 ``` mousedown、mousemove、mouseup和touchstart、touchmove、touchend 拖动时候用到的三个事件:mousedown、mousemove、mouseup在移动端都不起任何作用。毕竟移动端是没有鼠标的,查资料后发现, 在移动端与之相对应的分别是:touchstart、touchmove、touchend事件。 还有一点要注意的是在PC端获取当前鼠标的坐标是:event.clientX和event.clientY, 在移动端获取坐标位置则是:event.touches[0].clientX和event.touches[0].clientY。 ``` 22. 树优化 https://www.cnblogs.com/yuwenjing0727/p/7210625.html https://github.com/bitmain-frontend/huge-tree 23. node 复制文件和文件夹 ```js var fs = require('fs') var path = require('path') var copyFile = function(srcPath, tarPath, cb) { var rs = fs.createReadStream(srcPath) rs.on('error', function(err) { if (err) { console.log('read error', srcPath) } cb && cb(err) }) var ws = fs.createWriteStream(tarPath) ws.on('error', function(err) { if (err) { console.log('write error', tarPath) } cb && cb(err) }) ws.on('close', function(ex) { cb && cb(ex) }) rs.pipe(ws) } // 复制目录及其子目录 var copyFolder = function(srcDir, tarDir, cb) { fs.readdir(srcDir, function(err, files) { var count = 0 var checkEnd = function() { ++count == files.length && cb && cb() } if (err) { checkEnd() return } files.forEach(function(file) { var srcPath = path.join(srcDir, file) var tarPath = path.join(tarDir, file) fs.stat(srcPath, function(err, stats) { if (stats.isDirectory()) { console.log('mkdir', tarPath) fs.mkdir(tarPath, function(err) { if (err) { console.log(err) return } copyFolder(srcPath, tarPath, checkEnd) }) } else { copyFile(srcPath, tarPath, checkEnd) } }) }) //为空时直接回调 files.length === 0 && cb && cb() }) } ``` 23. 正则表达式 ```js /* (?=exp) 正向前瞻 匹配后面满足表达式exp的位置 (?!exp) 负向前瞻 匹配后面不满足表达式exp的位置 (?<=exp) 正向后瞻 匹配前面满足表达式exp的位置(JS不支持) (?