动态导航

master
夜良king 2022-02-27 18:24:35 +08:00
parent 7cd64553ab
commit 32336decc6
4 changed files with 112 additions and 84 deletions

View File

@ -1,7 +1,7 @@
import { getCurrentPermissionList } from "@/api/index";
import lazyLoading from './lazyLoading.js'; import lazyLoading from './lazyLoading.js';
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import { result } from './routerJson.js'; import { result } from './routerJson.js';
import { getCurrentPermissionList } from "@/api/index";
const config = require('@/config/index') const config = require('@/config/index')
@ -327,22 +327,21 @@ util.initRouter = function (vm) { // 初始化路由
return; return;
} }
if (!vm.$store.state.app.added) {
// 加载菜单 // 加载菜单
getCurrentPermissionList().then(res => { getCurrentPermissionList().then(res => {
if (!res.success) return false; if (!res.success) return false;
let menuData = result; let menuData = res.result;
// 格式化数据,设置 空children 为 null // 格式化数据,设置 空children 为 null
for (let i = 0; i < menuData.length; i++) { for (let i = 0; i < menuData.length; i++) {
let t = menuData[i].children; let t = menuData[i].children
for (let k = 0; k < t.length; k++) { for (let k = 0; k < t.length; k++) {
let tt = t[k].children; let tt = t[k].children;
for (let z = 0; z < tt.length; z++) { for (let z = 0; z < tt.length; z++) {
tt[z].children = null; tt[z].children = null
// 给所有三级路由添加字段显示一级菜单name方便点击页签时的选中筛选 // 给所有三级路由添加字段显示一级菜单name方便点击页签时的选中筛选
tt[z].firstRouterName = menuData[i].name; tt[z].firstRouterName = menuData[i].name
} }
} }
} }
@ -352,30 +351,16 @@ util.initRouter = function (vm) { // 初始化路由
util.initAllMenuData(constRoutes, menuData); util.initAllMenuData(constRoutes, menuData);
util.initRouterNode(otherRoutes, otherRouter); util.initRouterNode(otherRoutes, otherRouter);
// 添加所有主界面路由 // 添加所有主界面路由
vm.$store.commit( vm.$store.commit('updateAppRouter', constRoutes.filter(item => item.children.length > 0));
"updateAppRouter",
constRoutes.filter(item => item.children.length > 0)
);
// 添加全局路由 // 添加全局路由
vm.$store.commit("updateDefaultRouter", otherRoutes); vm.$store.commit('updateDefaultRouter', otherRoutes);
// 添加菜单路由 // 添加菜单路由
util.initMenuData(vm, menuData); util.initMenuData(vm, menuData);
// 缓存数据 修改加载标识 // 缓存数据 修改加载标识
window.localStorage.setItem("menuData", JSON.stringify(menuData)); window.localStorage.setItem('menuData', JSON.stringify(menuData));
vm.$store.commit("setAdded", true); vm.$store.commit('setAdded', true);
}); })
} else {
// 读取缓存数据
let data = window.localStorage.getItem('menuData');
if (!data) {
vm.$store.commit('setAdded', false);
return;
}
let menuData = JSON.parse(data);
// 添加菜单路由
util.initMenuData(vm, menuData);
}
}; };
// 添加所有顶部导航栏下的菜单路由 // 添加所有顶部导航栏下的菜单路由
@ -384,7 +369,6 @@ util.initAllMenuData = function (constRoutes, data) {
let allMenuData = []; let allMenuData = [];
data.forEach(e => { data.forEach(e => {
if (e.level == 0) { if (e.level == 0) {
console.log(e)
e.children.forEach(item => { e.children.forEach(item => {
allMenuData.push(item); allMenuData.push(item);
}) })
@ -454,7 +438,6 @@ util.initRouterNode = function (routers, data) { // data为所有子菜单数
for (var item of data) { for (var item of data) {
let menu = Object.assign({}, item); let menu = Object.assign({}, item);
menu.component = lazyLoading(menu.frontRoute); menu.component = lazyLoading(menu.frontRoute);
console.log(menu.component);
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
menu.children = []; menu.children = [];
util.initRouterNode(menu.children, item.children); util.initRouterNode(menu.children, item.children);

View File

@ -3,37 +3,65 @@
<Row type="flex" @keydown.enter.native="submitLogin"> <Row type="flex" @keydown.enter.native="submitLogin">
<Col style="width: 368px"> <Col style="width: 368px">
<Header /> <Header />
<Row style="flex-direction: column;"> <Row style="flex-direction: column">
<Form ref="usernameLoginForm" :model="form" :rules="rules" class="form"> <Form
ref="usernameLoginForm"
:model="form"
:rules="rules"
class="form"
>
<FormItem prop="username"> <FormItem prop="username">
<Input v-model="form.username" prefix="ios-contact" size="large" clearable placeholder="请输入用户名" <Input
autocomplete="off" /> v-model="form.username"
prefix="ios-contact"
size="large"
clearable
placeholder="请输入用户名"
autocomplete="off"
/>
</FormItem> </FormItem>
<FormItem prop="password"> <FormItem prop="password">
<Input type="password" v-model="form.password" prefix="ios-lock" size="large" password placeholder="请输入密码" <Input
autocomplete="off" /> type="password"
v-model="form.password"
prefix="ios-lock"
size="large"
password
placeholder="请输入密码"
autocomplete="off"
/>
</FormItem> </FormItem>
</Form> </Form>
<Row> <Row>
<div class="login-btn" type="primary" size="large" :loading="loading" @click="submitLogin" long> <div
class="login-btn"
type="primary"
size="large"
:loading="loading"
@click="submitLogin"
long
>
<span v-if="!loading"></span> <span v-if="!loading"></span>
<span v-else></span> <span v-else></span>
</div> </div>
</Row> </Row>
</Row> </Row>
<Footer /> <Footer />
<!-- 拼图验证码 --> <!-- 拼图验证码 -->
<verify ref="verify" class="verify-con" verifyType="LOGIN" @change="verifyChange"></verify> <verify
ref="verify"
class="verify-con"
verifyType="LOGIN"
@change="verifyChange"
></verify>
</Col> </Col>
</Row> </Row>
</div> </div>
</template> </template>
<script> <script>
import { getCurrentPermissionList } from "@/api/index";
import { login, userMsg } from "@/api/index"; import { login, userMsg } from "@/api/index";
import { validateMobile } from "@/libs/validate"; import { validateMobile } from "@/libs/validate";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
@ -95,6 +123,10 @@ export default {
}, },
}; };
}, },
created() {
window.localStorage.setItem("menuData", "");
},
methods: { methods: {
afterLogin(res) { afterLogin(res) {
let accessToken = res.result.accessToken; let accessToken = res.result.accessToken;
@ -104,6 +136,10 @@ export default {
// //
userMsg().then((res) => { userMsg().then((res) => {
if (res.success) { if (res.success) {
// location.reload();
// this.$router.go(0);
console.log("Huoqu ");
this.setStore("saveLogin", this.saveLogin); this.setStore("saveLogin", this.saveLogin);
if (this.saveLogin) { if (this.saveLogin) {
// 7 // 7
@ -113,9 +149,10 @@ export default {
} else { } else {
Cookies.set("userInfoSeller", JSON.stringify(res.result)); Cookies.set("userInfoSeller", JSON.stringify(res.result));
} }
util.initRouter(this);
this.$store.commit("setAvatarPath", res.result.storeLogo); this.$store.commit("setAvatarPath", res.result.storeLogo);
// //
util.initRouter(this);
this.$router.push({ this.$router.push({
name: "home_index", name: "home_index",
}); });
@ -139,8 +176,8 @@ export default {
this.loading = true; this.loading = true;
let fd = new FormData(); let fd = new FormData();
fd.append('username',this.form.username) fd.append("username", this.form.username);
fd.append('password',this.md5(this.form.password)) fd.append("password", this.md5(this.form.password));
login(fd) login(fd)
.then((res) => { .then((res) => {
this.loading = false; this.loading = false;
@ -157,7 +194,6 @@ export default {
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.login { .login {
height: 100%; height: 100%;
background: url("../assets/background.png") no-repeat; background: url("../assets/background.png") no-repeat;
@ -168,7 +204,6 @@ export default {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
.verify-con { .verify-con {
position: absolute; position: absolute;
top: 126px; top: 126px;
@ -194,9 +229,8 @@ export default {
transition: 0.35s; transition: 0.35s;
} }
.login-btn:hover { .login-btn:hover {
opacity: .9; opacity: 0.9;
border-radius: 10px; border-radius: 10px;
} }
} }
</style> </style>

View File

@ -263,7 +263,6 @@
this.loading = false; this.loading = false;
if (res.success) { if (res.success) {
this.data = res.result.records; this.data = res.result.records;
this.total = res.result.total; this.total = res.result.total;
} }
}); });

View File

@ -110,7 +110,7 @@
<Form ref="form" :model="form" :label-width="80" :rules="formValidate"> <Form ref="form" :model="form" :label-width="80" :rules="formValidate">
<FormItem label="手机号" prop="mobile"> <FormItem label="手机号" prop="mobile">
<Input placeholder="请输入要添加的会员手机号码" maxlength="11" style="width: 75%" v-model="form.mobile" <Input placeholder="请输入要添加的会员手机号码" maxlength="11" style="width: 75%" v-model="form.mobile"
autocomplete="off"/> autocomplete="off" @on-change="checkClerks"/>
&nbsp;<Button v-if="!memberCheck" @click="checkClerk"></Button> &nbsp;<Button v-if="!memberCheck" @click="checkClerk"></Button>
<Button v-if="memberCheck" @click="checkAgainClerk"></Button> <Button v-if="memberCheck" @click="checkAgainClerk"></Button>
</FormItem> </FormItem>
@ -180,6 +180,7 @@ export default {
}, },
data() { data() {
return { return {
open:0,
loading: true, // loading: true, //
selectCount: 0, // selectCount: 0, //
selectList: [], // selectList: [], //
@ -197,7 +198,7 @@ export default {
modalTitle: "", // modal modalTitle: "", // modal
form: { // form: { //
username: "", username: "",
mobile: "", mobile: 0,
sex: "", sex: "",
isSuper: 0, isSuper: 0,
roles: [], roles: [],
@ -448,6 +449,16 @@ export default {
init() { init() {
this.getUserList(); this.getUserList();
}, },
checkClerks() {
this.open = this.form.mobile.length;
console.log(this.open)
if(this.open == 11 ){
this.checkClerk();
}
if(this.open < 11){
this.checkAgainClerk()
}
},
// //
handleSelectDepTree(v) { handleSelectDepTree(v) {
if (v) { if (v) {
@ -626,6 +637,7 @@ export default {
}, },
// //
add() { add() {
// this.checkClerks();
this.modalType = 0; this.modalType = 0;
this.modalTitle = "添加店员"; this.modalTitle = "添加店员";
this.$refs.form.resetFields(); this.$refs.form.resetFields();