This commit is contained in:
Aiden 2024-10-18 10:19:37 +08:00
parent 43cc89dc15
commit 90fecfc8c9
7 changed files with 22 additions and 36 deletions

View File

@ -3,7 +3,6 @@ import App from "./App.vue";
import uviewPlus from "uview-plus";
import globalComponents from "./components";
import VConsole from "vconsole";
import permission from "../utils/permission.js";
if (import.meta.env.VITE_APP_MODE === "dev") {
new VConsole();
@ -11,7 +10,6 @@ if (import.meta.env.VITE_APP_MODE === "dev") {
export function createApp() {
const app = createSSRApp(App);
globalComponents(app);
permission(app);
app.use(uviewPlus);
return {
app,

View File

@ -74,7 +74,7 @@
<script setup>
import { ref, reactive, onBeforeMount } from "vue";
import { closeWebview } from "../../../utils/index.js";
import { closeWebview, hasPermission } from "../../../utils/index.js";
import { onLoad } from "@dcloudio/uni-app";
import useToast from "@/hooks/toast/useToast.js";

View File

@ -87,6 +87,7 @@
:loading="loading"
:disabled="isButtonDisabled"
@click="doneSet"
v-if="hasPermission('APP-scanAdd')"
>
{{ buttonText }}</up-button
>
@ -98,7 +99,7 @@ import { ref, reactive, onBeforeMount } from "vue";
import useToast from "@/hooks/toast/useToast.js";
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { creChangepainting, add } from "@/api/login.js";
import { closeWebview } from "../../../utils/index";
import { closeWebview, hasPermission } from "../../../utils/index";
const { showMessage } = useToast();
const loading = ref(false);

View File

@ -245,10 +245,10 @@ const logining = async () => {
loading.value = false;
};
const getBtngetRules = async () => {
const res = await getRules();
const res = await getRules({});
if (res.status === 0) {
const ruleBtn =
res.data.data.MyButtonAuths?.map((button) => button.Url) || [];
const ruleBtn = res.data.MyButtonAuths?.map((button) => button.Url) || [];
console.log(123, ruleBtn);
uni.setStorageSync("ruleBtn", ruleBtn);
} else {
showMessage({ type: "error", message: res.msg });

View File

@ -43,6 +43,7 @@
@click="doneSet"
:disabled="isButtonDisabled"
:loading="loading"
v-if="hasPermission('APP-scanEnteringwarehouse')"
>{{ buttonText }}</up-button
>
</view>
@ -53,7 +54,7 @@ import { ref, reactive, onBeforeMount } from "vue";
import useToast from "@/hooks/toast/useToast.js";
import { onLoad } from "@dcloudio/uni-app";
import { freebox, bind, check_freebox, cancel } from "@/api/login.js";
import { closeWebview } from "../../../utils/index";
import { closeWebview, hasPermission } from "../../../utils/index";
const { showMessage } = useToast();
const loading = ref(false);
const isButtonDisabled = ref(false);
@ -142,12 +143,12 @@ const check = async () => {
}
};
const runTimeEnv = () => {
if (plus) {
const currentWebView = plus.webview.getWebviewById("wv");
return currentWebView.RunTime === "app";
} else {
return false;
}
try {
if (plus) {
const currentWebView = plus.webview.getWebviewById("wv");
return currentWebView.RunTime === "app";
}
} catch (e) {}
};
</script>

View File

@ -24,3 +24,11 @@ export const OAorMc = () => {
return "";
}
};
export const hasPermission = (userPermission) => {
let userPermissionList = Array.isArray(userPermission)
? userPermission
: [userPermission];
// 当前用户的权限列表
let permissionList = Local.get("ruleBtn") ? Local.get("ruleBtn") : [];
return userPermissionList.some((e) => permissionList.includes(e));
};

View File

@ -1,22 +0,0 @@
export default (app) => {
// 按钮权限/show-btn
app.directive("permission", {
beforeMount(el, binding) {
const btnList = uni.getStorageSync("ruleBtn")
? uni.getStorageSync("ruleBtn")
: [];
if (
(binding.value &&
btnList.length > 0 &&
!btnList.includes(binding.value)) ||
btnList.length == 0
) {
// 解决进入页面按钮会闪一下再消失问题
el.style.display = "none";
setTimeout(() => {
el.parentNode.removeChild(el);
}, 0);
}
},
});
};