Commit f343ba10 by 无尘

add: 增加排序

parent 38565929
...@@ -101,3 +101,9 @@ methods: { ...@@ -101,3 +101,9 @@ methods: {
} }
``` ```
## logs
- 20190110
- 增加菜单排序
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "@gic-test/vue-office-aside", "name": "@gic-test/vue-office-aside",
"description": "vue-office-aside Plugin", "description": "vue-office-aside Plugin",
"author": "fairyly <498745097@qq.com>", "author": "fairyly <498745097@qq.com>",
"version": "1.0.25", "version": "1.0.26",
"license": "MIT", "license": "MIT",
"private": false, "private": false,
"main": "dist/vue-office-aside.js", "main": "dist/vue-office-aside.js",
......
...@@ -28,9 +28,7 @@ ...@@ -28,9 +28,7 @@
</div> </div>
</div> </div>
</template> </template>
<script> <script>
// import { getRequest } from './api';
import qs from 'qs'; import qs from 'qs';
export default { export default {
name: 'vue-office-aside', name: 'vue-office-aside',
...@@ -38,26 +36,21 @@ ...@@ -38,26 +36,21 @@
data () { data () {
return { return {
repProjectName: 'haoban-manage-web', // 项目名 repProjectName: 'haoban-manage-web', // 项目名
// 高度 asideHeight: '0px', // 高度
asideHeight: '0px',
pathName: '', // 路由名 pathName: '', // 路由名
leftCollapse: false,// 是否收起左侧 leftCollapse: false, // 是否收起左侧
leftModuleName: '', leftModuleName: '',
// defaultSub: ['1','2','3','4','5','6','7','8','9'], // 默认打开子菜单 // defaultSub: ['1','2','3','4','5','6','7','8','9'], // 默认打开子菜单
menuLeftRouter: [ menuLeftRouter: [],
],
// 获取 location origin // 获取 location origin
baseUrl: '', baseUrl: '',
//已选菜单 //已选菜单
selectMenu: '', selectMenu: '',
} }
}, },
beforeMount() { beforeMount() {
var that = this const that = this
var host = window.location.origin; let host = window.location.origin;
console.log("当前host:",host)
if (host.indexOf('localhost') != '-1') { if (host.indexOf('localhost') != '-1') {
that.baseUrl = 'http://www.gicdev.com'; that.baseUrl = 'http://www.gicdev.com';
}else { }else {
...@@ -71,7 +64,7 @@ ...@@ -71,7 +64,7 @@
}, },
handleSelect(key, keyPath){ handleSelect(key, keyPath){
var that = this const that = this
console.log(key, keyPath); console.log(key, keyPath);
that.selectMenu = key that.selectMenu = key
}, },
...@@ -79,39 +72,31 @@ ...@@ -79,39 +72,31 @@
// 设置新数据 // 设置新数据
setNewData(newData) { setNewData(newData) {
const that = this; const that = this;
console.log("左侧菜单:that.pathName:",that.pathName,"that.selectMenu:",that.selectMenu )
// 处理成需要的路由 // 处理成需要的路由
// var list = [],lists = [];
newData.forEach(function(ele,index){ newData.forEach(function(ele,index){
// 设置 url // 设置 url
ele.url = '/'+ ele.url; ele.url = '/'+ ele.url;
ele.levelFlag = false; // 有子级 ele.levelFlag = false; // 有子级
if (!!ele.children && !!ele.children.length) { if (!!ele.children && !!ele.children.length) {
let displayList = ele.children.map(item=>item.display) let displayList = ele.children.map(item=>item.display)
// console.log('displayList:',displayList)
if (displayList.includes(1)) { if (displayList.includes(1)) {
ele.levelFlag = false; // 有子级 ele.levelFlag = false; // 有子级
}else { }else {
ele.levelFlag = true; // 有子级,单独路由 ele.levelFlag = true; // 有子级,单独路由
} }
ele.children.forEach(function(el,key){ ele.children.forEach(function(el,key){
// 设置 url // 设置 url
el.url = '/'+ el.url; el.url = '/'+ el.url;
}) })
} }
}) })
that.menuLeftRouter = newData; that.menuLeftRouter = newData;
that.setSelectMenu(newData) that.setSelectMenu(newData);
console.log("处理后的左侧菜单 list:",newData,that.selectMenu )
}, },
setSelectMenu(data) { setSelectMenu(data) {
const that = this; const that = this;
data.forEach(function(ele,index){ data.forEach(function(ele,index){
console.log(that.pathName, ele.url)
if (('/' + that.pathName) == ele.url) { if (('/' + that.pathName) == ele.url) {
that.selectMenu = '/' + that.pathName that.selectMenu = '/' + that.pathName
}else { }else {
...@@ -126,13 +111,13 @@ ...@@ -126,13 +111,13 @@
// 触发父组件路由 // 触发父组件路由
toRouter(path) { toRouter(path) {
var that = this; const that = this;
that.$emit('toLeftRouterView', '/'+path) that.$emit('toLeftRouterView', '/'+path)
}, },
// 刷新路由 // 刷新路由
refreshRoute() { refreshRoute() {
var that = this const that = this
//获取项目名 pathname (路由的hash) //获取项目名 pathname (路由的hash)
that.routePathName = window.location.hash.split('/')[1]; that.routePathName = window.location.hash.split('/')[1];
if (that.routePathName.indexOf('?')!= -1) { if (that.routePathName.indexOf('?')!= -1) {
...@@ -141,7 +126,6 @@ ...@@ -141,7 +126,6 @@
if (that.routePathName.indexOf('/')!= -1) { if (that.routePathName.indexOf('/')!= -1) {
that.routePathName = that.routePathName.split('/')[0] that.routePathName = that.routePathName.split('/')[0]
} }
console.log("routePathname:",that.routePathName)
that.pathName = that.routePathName that.pathName = that.routePathName
that.getLeftMenu() that.getLeftMenu()
}, },
...@@ -161,22 +145,25 @@ ...@@ -161,22 +145,25 @@
} }
return father.level == 1; //返回第一层 return father.level == 1; //返回第一层
}); });
tree.sort(function(a,b){
return a.sort - b.sort
});
return tree; return tree;
}, },
// 获取左侧菜单 /**
* 获取左侧菜单
*/
getLeftMenu() { getLeftMenu() {
var that = this const that = this;
var para = { let para = {
project: that.repProjectName, project: that.repProjectName,
router: that.pathName, router: that.pathName,
requestProject: that.repProjectName requestProject: that.repProjectName
} }
that.axios.post(that.baseUrl+'/haoban-manage-web/menu-detail',qs.stringify(para)) that.axios.post(that.baseUrl+'/haoban-manage-web/menu-detail',qs.stringify(para))
.then((res) => { .then((res) => {
// console.log(res,res.data,res.data.errorCode) let resData = res.data;
var resData = res.data
if (resData.errorCode == 1) { if (resData.errorCode == 1) {
if (!resData.result) { if (!resData.result) {
that.$message.error({ that.$message.error({
...@@ -185,29 +172,15 @@ ...@@ -185,29 +172,15 @@
}) })
return; return;
} }
that.setNewData(that.treeData(resData.result.leftMenu)) that.setNewData(that.treeData(resData.result.leftMenu))
// if (!!resData.result.level4) {
// that.selectMenu = '/'+resData.result.level4.menuUrl
// return;
// }
// if (!!resData.result.level3) {
// that.selectMenu = '/'+resData.result.level3.menuUrl
// }
// sessionStorage.setItem('activeHead',resData.result.level2.menuCode)
return; return;
} }
that.$message.error({ that.$message.error({
duration: 1000, duration: 1000,
message: resData.message message: resData.message
}) })
}) })
.catch(function (error) { .catch(function (error) {
console.log(error);
// that.toLogin()
that.$message.error({ that.$message.error({
duration: 1000, duration: 1000,
message: error.message message: error.message
...@@ -218,50 +191,39 @@ ...@@ -218,50 +191,39 @@
watch: { watch: {
$route: { $route: {
handler: function(val, oldVal){ handler: function(val, oldVal){
console.log("左侧菜单插件获取当前路由:",val);
}, },
// 深度观察监听 // 深度观察监听
deep: true deep: true
}, },
collapseFlag: function(newData,oldData){ collapseFlag: function(newData,oldData){
var that = this; const that = this;
// console.log("左侧新数据:",newData,oldData)
that.leftCollapse = newData; that.leftCollapse = newData;
}, },
projectName: function(newData,oldData){ projectName: function(newData,oldData){
var that = this; const that = this;
// console.log("新数据:",newData,oldData)
that.repProjectName = newData || 'haoban-manage-web'; that.repProjectName = newData || 'haoban-manage-web';
}, },
}, },
/* 接收数据 */ /* 接收数据 */
mounted(){ mounted(){
console.log("传递的左侧菜单参数:",this.projectName,this.$route) const that = this;
var that = this; that.repProjectName = that.projectName || 'haoban-manage-web'; // 获取项目名
// 项目名
that.repProjectName = that.projectName || 'haoban-manage-web';
// 获取高度 // 获取高度
that.asideHeight = (document.documentElement.clientHeight || document.body.clientHeight) - 64 +'px'; that.asideHeight = (document.documentElement.clientHeight || document.body.clientHeight) - 64 +'px';
//获取项目名 pathname (路由的hash) //获取项目名 pathname (路由的hash)
that.pathName = window.location.hash.split('/')[1]; that.pathName = window.location.hash.split('/')[1];
if (that.pathName.indexOf('?')!= -1) { if (that.pathName.indexOf('?')!= -1) {
that.pathName = that.pathName.split('?')[0] that.pathName = that.pathName.split('?')[0]
} }
// 获取菜单 // 获取菜单
that.getLeftMenu(); that.getLeftMenu();
//折叠参数 //折叠参数
that.leftCollapse = that.collapseFlag; that.leftCollapse = that.collapseFlag;
}
},
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment