1.共享登录(单点登录)主要是前端部分
主要是根据是否有cookie来判断是否已经登录主系统,然后再根据是否有当前系统的登录信息来(这块主要是sessionStorage做的)判断是否要再登录当前系统。
设置、读取和设置cookie的方法
function setCookie(name,value)
{ var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{ var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); return (arr=document.cookie.match(reg))?unescape(arr[2]):null;
}
function delCookie(name)
{ var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
2.部门树的数据处理
后台返回的数据结构如下,需要处理成一维数组。
deptTree:[{"children":[{"deptId":"001","deptName":"xxx","businessUnit":"000001","treeNodeNum":111111,"need":"Y","children":[{"deptId":"0000011","deptName":"xxxxxx","businessUnit":"00011","treeNodeNum":5555,"need":"Y"},...]
主要是运用递归的方式处理
loopDept: function (data) {var _this = this;var deptTreeNode = [];if (data.need == 'Y') {deptTreeNode.push(data.deptId);}if (data.children) {data.children.forEach(function (node) {var nodes = _this.loopDept(node);deptTreeNode = deptTreeNode.concat(nodes);})}return deptTreeNode;},
递归组件
<template><ul class="treeList"><liv-for="(item,index) in list":key="index"class="treebox"><span><imgsrc="@/assets/deptIcon.png"alt=""><em @click="goteamerList(item)">{{item.deptName | fixName }}</em><van-iconname="arrow-up"v-show="!item.showMore && item.children"@click="changeStatus(item)"size="0.4rem"/><van-iconname="arrow-down"v-show="item.showMore && item.children"@click="changeStatus(item)"size="0.4rem"/></span><myTreesv-if="item.children && !item.showMore":list="item.children"></myTrees></li></ul></template>
-
<script>
export default {name: "myTrees",props: {list: Array},data() {return {scopesDefault: [],scopes: []};},filters:{fixName(value){if(value && value.length > 20){let startStr = value.substring(0,10);let endStr = value.substr(-9,9);return value = startStr+"..."+endStr;}else{return value;}}},methods: {changeStatus(item) {item.showMore = !item.showMore;},scope() {this.list.forEach((item, index) => {if ("children" in item) {this.$set(item, "showMore", true);} else {this.$set(item, "showMore", false);}});},goteamerList(item) {let {businessUnit,deptId,isJKNode,isJRNode} = item;sessionStorage.setItem("deptInfo", JSON.stringify(item));this.$router.push({name: "teamerList",query:{businessUnit,deptId,isJKNode,isJRNode}});}},created() {this.scope();}
};
</script>
3.一些处理数据的方式
list.forEach(function (ele) {//数组设置法if (ele.isInner == 'Y') {if (tempInner[ele.belongCategoryId]) {tempInner[ele.belongCategoryId].push(ele)} else {tempInner[ele.belongCategoryId] = [ele]}} else {if (tempOut[ele.belongCategoryId]) {tempOut[ele.belongCategoryId].push(ele)} else {tempOut[ele.belongCategoryId] = [ele]}}//对象设置法if (ele.isInner == 'Y') {if (tempInner.hasOwnProperty(ele.belongCategoryId)) {tempInner[ele.belongCategoryId] += ","+ele.name } else {tempInner[ele.belongCategoryId] = ele.name}} else {if (tempOut.hasOwnProperty(ele.belongCategoryId)) {tempOut[ele.belongCategoryId] += ","+ele.name } else {tempOut[ele.belongCategoryId] = ele.name}}})
前端渣渣摸鱼时间所录,先就这些,想到再写,如有问题请指出。