--demand 添加权限

This commit is contained in:
yuping
2023-02-01 13:21:02 +08:00
parent d73dba81c8
commit 04f43c96e3
6 changed files with 112 additions and 156 deletions

View File

@@ -18,9 +18,8 @@
<router-view/>
</div>
</template>
<script>
import {computed, defineComponent, ref, onMounted} from "vue";
import {useRouter, useRoute} from "vue-router";
<script setup>
import {ref, onMounted} from "vue";
import {useStore, createStore} from "vuex";
import NavLeft from "@/components/NavLeft";
import NavTop from "@/components/NavTop";
@@ -31,147 +30,90 @@ import * as api from "./api/index1";
import * as api1 from "@/api/index1";
import * as api2 from "@/api/index";
export default defineComponent({
components: {
NavLeft,
NavTop,
OpenPages,
BreadCrumb,
},
setup() {
const router = useRouter();
const route = useRoute();
const store = useStore();
const isLogin = ref(false);
// console.log("router", router.getRoutes(), route);
console.log("版本2.1.6------------");
const routes = computed(() => {
return router.getRoutes().filter((e) => e.meta?.isLink);
});
// watch(
// () => route.path,
// () => {
// route.path === "/login" && (isLogin.value = true);
// }
// );
const currentRouteName = computed(() => route.name);
const store = useStore();
const isLogin = ref(false);
console.log("版本2.1.6------------");
function init() {
console.log(store);
getUserInfo();
initDict("faceclassPic");
initDict("faceclassClass");
initDict("faceclassScene");
initDict("projectLevel");
initDict("projectSys");
initDict("pathmapPic");
initDict("projectClass");
initDict("projectPic");
initDict("sysType");
getMemberInfo();
getOrgTree();
}
// 监听关闭浏览器
let time1 = ref(0);
let time2 = ref(0);
// 监听关闭浏览器
let time1 = ref(0);
let time2 = ref(0);
onMounted(() => {
init()
window.addEventListener('beforeunload', e => beforeunloadHandler(e));
window.addEventListener('unload', e => unloadHandler(e));
})
//添加监听事件
function beforeunloadHandler() {
time1.value = new Date().getTime();
// e.returnValue = '关闭提示';
}
//添加监听事件
function beforeunloadHandler() {
time1.value = new Date().getTime();
}
function unloadHandler() {
time2.value = new Date().getTime() - time1.value;
if (time2.value <= 5) {
store.replaceState(createStore({state: {openpages: null}}).state);
localStorage.removeItem("openpages");
}
}
function init() {
getUserInfo();
initDict("faceclassPic");
initDict("faceclassClass");
initDict("faceclassScene");
initDict("projectLevel");
initDict("projectSys");
initDict("pathmapPic");
initDict("projectClass");
initDict("projectPic");
initDict("sysType");
getMemberInfo();
getOrgTree();
}
onMounted(() => {
window.addEventListener('beforeunload', e => beforeunloadHandler(e));
window.addEventListener('unload', e => unloadHandler(e));
})
async function getMemberInfo() {
const list = localStorage.getItem("memberInitInfo");
if (list) {
store.commit("SET_MEMBER_INFO", JSON.parse(list));
return;
}
const memberInitInfo = await api1
.getMemberInfo({keyWord: "", pageNo: 1, pageSize: 10})
.then((res) => res.data.data.rows);
store.commit("SET_MEMBER_INFO", memberInitInfo);
localStorage.setItem("memberInitInfo", JSON.stringify(memberInitInfo));
}
async function getUserInfo() {
const userInfo = await api2.userInfo();
store.commit("SET_USER", userInfo.data.data);
}
async function initDict(key, localStory = false) {
let list;
if (localStory) {
list = localStorage.getItem(key);
if (list) {
store.commit("SET_DICT", {key, data: JSON.parse(list)});
return;
}
}
list = await getDictList(key);
localStory && localStorage.setItem(key, JSON.stringify(list));
store.commit("SET_DICT", {key, data: list});
}
const getDictList = (param) => api1.getDictTree({setCode: param,}).then((res) => res.data.data);
//获取组织树
const getOrgTree = () => {
api.getOrgTreeInfo().then((res) => {
store.commit("getOrgtreeList", res.data.data);
});
};
init();
return {
isLogin,
routes,
name: currentRouteName,
zhCN,
};
function unloadHandler() {
time2.value = new Date().getTime() - time1.value;
if (time2.value <= 5) {
store.replaceState(createStore({state: {openpages: null}}).state);
localStorage.removeItem("openpages");
}
});
}
async function getMemberInfo() {
const list = localStorage.getItem("memberInitInfo");
if (list) {
store.commit("SET_MEMBER_INFO", JSON.parse(list));
return;
}
const memberInitInfo = await api1
.getMemberInfo({keyWord: "", pageNo: 1, pageSize: 10})
.then((res) => res.data.data.rows);
store.commit("SET_MEMBER_INFO", memberInitInfo);
localStorage.setItem("memberInitInfo", JSON.stringify(memberInitInfo));
}
async function getUserInfo() {
const userInfo = await api2.userInfo();
store.commit("SET_USER", userInfo.data.data);
}
async function initDict(key, localStory = false) {
let list;
if (localStory) {
list = localStorage.getItem(key);
if (list) {
store.commit("SET_DICT", {key, data: JSON.parse(list)});
return;
}
}
list = await getDictList(key);
localStory && localStorage.setItem(key, JSON.stringify(list));
store.commit("SET_DICT", {key, data: list});
}
const getDictList = (param) => api1.getDictTree({setCode: param,}).then((res) => res.data.data);
//获取组织树
const getOrgTree = () => {
api.getOrgTreeInfo().then((res) => {
store.commit("getOrgtreeList", res.data.data);
});
};
</script>
<style lang="scss">
//.ant-modal {
//
// .ant-modal-content {
// background-image: linear-gradient(
// 180deg, rgba(103, 64, 255, .2), rgba(166, 168, 255, 0), rgba(166, 168, 255, 0)) !important;
// border-radius: 4px;
//
// .ant-modal-body {
// .ant-btn {
// border-radius: 8px;
// width: 100px;
// height: 40px;
// }
//
// .ant-btn-primary {
// background: #4ea6ff;
// color: #fff;
// }
// }
// }
//}
#app {
// font-family: MicrosoftYaHei, Microsoft YaHei, Avenir, Helvetica, Arial,
// sans-serif;
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB,
Microsoft YaHei, Arial, sans-serif;
-webkit-font-smoothing: antialiased;