Compare commits

..

No commits in common. "68f90340427faf18068245b0baeb88e90ce4a504" and "43cc89dc156ecfc36360a29f78cc164258aed7ae" have entirely different histories.

7 changed files with 36 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

22
utils/permission.js Normal file
View File

@ -0,0 +1,22 @@
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);
}
},
});
};