代码优化

This commit is contained in:
BianLzhaoMin 2024-08-27 16:15:01 +08:00
parent eca75347ce
commit ab57988c81
1 changed files with 564 additions and 531 deletions

View File

@ -31,8 +31,7 @@
<view <view
v-for="(part, index) in isUsingList" v-for="(part, index) in isUsingList"
:key="index" :key="index"
@click="jumpUrl(part.iconMark)" @click="jumpUrl(part.iconMark)">
>
<image :src="`/static/${part.iconMark}.png`" mode=""></image> <image :src="`/static/${part.iconMark}.png`" mode=""></image>
<span>{{ part.iconName }}</span> <span>{{ part.iconName }}</span>
</view> </view>
@ -45,9 +44,14 @@
<span>退料申请</span> <span>退料申请</span>
</view> --> </view> -->
</view> </view>
<h4 style="width: 90%; margin: 3vh auto;">待办事项</h4> <h4 style="width: 90%; margin: 3vh auto">待办事项</h4>
<view class="wait-do"> <view class="wait-do">
<view class="llsp" @click="jumpUrl('fetchExam')"> <view
class="llsp"
@click="jumpUrl('fetchExam')"
v-if="
store.includes('service:auditing') || store.includes('*')
">
<h4>{{ waitList.leaseNum }}</h4> <h4>{{ waitList.leaseNum }}</h4>
<h5>领料待审批</h5> <h5>领料待审批</h5>
</view> </view>
@ -64,16 +68,26 @@
<h5>试验检验待审核</h5> <h5>试验检验待审核</h5>
</view> </view>
</view> </view>
<h4 style="width: 90%; margin: 3vh auto; display: flex; justify-content: space-between; align-items: center;"> <h4
style="
width: 90%;
margin: 3vh auto;
display: flex;
justify-content: space-between;
align-items: center;
">
<span>通知公告</span> <span>通知公告</span>
<text @click="seeMore" style="color: #5297FF; font-weight: normal; font-size: 12px;">查看更多>></text> <text
@click="seeMore"
style="color: #5297ff; font-weight: normal; font-size: 12px"
>查看更多>></text
>
</h4> </h4>
<view <view
class="single-notice" class="single-notice"
v-for="(notice, index) in noticeList" v-for="(notice, index) in noticeList"
:key="index" :key="index"
@click="noticeDetail(notice.noticeId)" @click="noticeDetail(notice.noticeId)">
>
<view class="notice-lef"> <view class="notice-lef">
<image src="/static/notice.png" mode=""></image> <image src="/static/notice.png" mode=""></image>
</view> </view>
@ -82,27 +96,21 @@
<h5>{{ notice.createTime }}</h5> <h5>{{ notice.createTime }}</h5>
</view> </view>
</view> </view>
<uni-popup <uni-popup ref="popup" type="center" :mask-click="false">
ref="popup"
type="center"
:mask-click="false"
>
<view class="popup"> <view class="popup">
<view class="pop-top"> <view class="pop-top">
<h4>公告({{ unreadIndex + 1 }}/{{ unreadList.length }})</h4> <h4>公告({{ unreadIndex + 1 }}/{{ unreadList.length }})</h4>
<uni-icons <uni-icons
style="color: #AAAAAA; font-weight: bold;" style="color: #aaaaaa; font-weight: bold"
type="closeempty" type="closeempty"
@click="closePopup" @click="closePopup">
>
</uni-icons> </uni-icons>
</view> </view>
<view <view
class="unread-notice" class="unread-notice"
v-for="(list, index) in unreadList" v-for="(list, index) in unreadList"
:key="index" :key="index"
v-show="index == unreadIndex" v-show="index == unreadIndex">
>
<view class="tit"> <view class="tit">
{{ list.noticeTitle }} {{ list.noticeTitle }}
</view> </view>
@ -114,8 +122,7 @@
<view <view
class="read-one" class="read-one"
v-show="unreadIndex < unreadList.length - 1" v-show="unreadIndex < unreadList.length - 1"
@click="readOneNotice(list.noticeId)" @click="readOneNotice(list.noticeId)">
>
我知道了 我知道了
</view> </view>
</view> </view>
@ -125,202 +132,228 @@
</template> </template>
<script> <script>
import store from "../../store/user";
export default { export default {
data() { data() {
return { return {
showLoading: false, showLoading: false,
username: uni.getStorageSync('userInfo').username, username: uni.getStorageSync("userInfo").username,
noticeList: [], noticeList: [],
todayDatas: { todayDatas: {
dayLeaseNum: '', dayLeaseNum: "",
dayBackNum: '', dayBackNum: "",
dayInputNum: '', dayInputNum: "",
dayOutNum: '' dayOutNum: "",
}, },
waitList: { waitList: {
lldsp: '', lldsp: "",
tldsp: '', tldsp: "",
bfdsh: '', bfdsh: "",
sydsh: '' sydsh: "",
}, },
isUsingList: [], isUsingList: [],
percent: '', percent: "",
unreadList: [], unreadList: [],
unreadIndex: 0 unreadIndex: 0,
} store: store.state.permissions || [],
};
}, },
methods: { methods: {
seeMore() { seeMore() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/moreNotice/moreNotice' url: "/pages/moreNotice/moreNotice",
}) });
}, },
noticeDetail(id) { noticeDetail(id) {
console.log(id); console.log(id);
uni.navigateTo({ uni.navigateTo({
url: `/pages/noticeDetail/noticeDetail?noticeId=${id}` url: `/pages/noticeDetail/noticeDetail?noticeId=${id}`,
}) });
}, },
jumpUrl(path) { jumpUrl(path) {
uni.navigateTo({ uni.navigateTo({
url: `/pages/${path}/${path}` url: `/pages/${path}/${path}`,
}) });
}, },
extractTextFromHTML(htmlString) { extractTextFromHTML(htmlString) {
return htmlString.replace(/<[^>]*>/g, ''); return htmlString.replace(/<[^>]*>/g, "");
}, },
openPopup() { openPopup() {
this.$refs.popup.open() this.$refs.popup.open();
}, },
closePopup() { closePopup() {
let that = this let that = this;
let noticeArr = [] let noticeArr = [];
that.unreadList.forEach(item => { that.unreadList.forEach((item) => {
noticeArr.push(item.noticeId) noticeArr.push(item.noticeId);
}) });
console.log(noticeArr); console.log(noticeArr);
that.uploadUnNotice(noticeArr) that.uploadUnNotice(noticeArr);
that.$refs.popup.close() that.$refs.popup.close();
}, },
readOneNotice(noticeId) { readOneNotice(noticeId) {
let that = this let that = this;
let noticeArr = [] let noticeArr = [];
noticeArr.push(noticeId) noticeArr.push(noticeId);
that.uploadUnNotice(noticeArr) that.uploadUnNotice(noticeArr);
that.unreadIndex++ that.unreadIndex++;
}, },
uploadUnNotice(arr) { uploadUnNotice(arr) {
let that = this let that = this;
that.$api.index.uploadNotice({ that.$api.index
.uploadNotice({
noticeId: arr, noticeId: arr,
userId: uni.getStorageSync('userInfo').userid userId: uni.getStorageSync("userInfo").userid,
}).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
}) })
} .then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
},
}, },
onShow() { onShow() {
console.log(uni.getStorageSync('token')); console.log(uni.getStorageSync("token"));
console.log(uni.getStorageSync('userInfo')); console.log(uni.getStorageSync("userInfo"));
let that = this let that = this;
that.unreadIndex = 0 that.unreadIndex = 0;
that.noticeList = [] that.noticeList = [];
// //
that.$api.index.noticeCont().then(res => { that.$api.index
.noticeCont()
.then((res) => {
console.log(res); console.log(res);
if (res.data.code == 200) { if (res.data.code == 200) {
that.noticeList = res.data.data.slice(0, 5) that.noticeList = res.data.data.slice(0, 5);
} else if (res.data.code == 401) { } else if (res.data.code == 401) {
uni.showToast({ uni.showToast({
icon: 'none', icon: "none",
title: '登录状态已过期,请重新登录!', title: "登录状态已过期,请重新登录!",
success: () => { success: () => {
uni.removeStorageSync('token') uni.removeStorageSync("token");
uni.removeStorageSync('userInfo') uni.removeStorageSync("userInfo");
uni.reLaunch({ uni.reLaunch({
url: '/pages/login/login' url: "/pages/login/login",
}) });
},
});
} }
}) })
} .catch((err) => {
}).catch(err => {
console.log(err); console.log(err);
}) });
// //
that.$api.index.waitDo().then(res => { that.$api.index
.waitDo()
.then((res) => {
console.log(res); console.log(res);
if (res.data.code == 200) { if (res.data.code == 200) {
that.waitList = res.data.data that.waitList = res.data.data;
} }
}).catch(err => {
console.log(err);
}) })
.catch((err) => {
console.log(err);
});
// //
that.$api.index.keyData().then(res => { that.$api.index
.keyData()
.then((res) => {
console.log(res); console.log(res);
if (res.data.code == 200) { if (res.data.code == 200) {
that.todayDatas = res.data.data that.todayDatas = res.data.data;
} }
}).catch(err => {
console.log(err);
}) })
.catch((err) => {
console.log(err);
});
// //
that.$api.authManage.fetchIsUsing({ that.$api.authManage
userId: uni.getStorageSync('userInfo').userid .fetchIsUsing({
}).then(res => { userId: uni.getStorageSync("userInfo").userid,
})
.then((res) => {
console.log(res); console.log(res);
if (res.data.code == 200) { if (res.data.code == 200) {
that.isUsingList = res.data.data that.isUsingList = res.data.data;
console.log(that.isUsingList); console.log(that.isUsingList);
} }
}).catch(err => {
console.log(err);
}) })
.catch((err) => {
console.log(err);
});
// //
let dept = uni.getStorageSync('userInfo').sysUser.dept.ancestors let dept = uni.getStorageSync("userInfo").sysUser.dept.ancestors;
if (dept == null) { if (dept == null) {
uni.setStorageSync('companyName', '') uni.setStorageSync("companyName", "");
} else { } else {
that.$api.index.fetchCompanyName({ that.$api.index
ancestors: dept .fetchCompanyName({
}).then(res => { ancestors: dept,
console.log(res);
if (res.data.code == 200) uni.setStorageSync('companyName', res.data.msg)
}).catch(err => {
console.log(err);
}) })
.then((res) => {
console.log(res);
if (res.data.code == 200)
uni.setStorageSync("companyName", res.data.msg);
})
.catch((err) => {
console.log(err);
});
} }
// //
that.$api.index.fetchNotice().then(res => { that.$api.index
.fetchNotice()
.then((res) => {
console.log(res); console.log(res);
if (res.data.code == 200) { if (res.data.code == 200) {
if (res.data.data.length != 0) { if (res.data.data.length != 0) {
res.data.data.forEach(item => { res.data.data.forEach((item) => {
item.noticeContent = that.extractTextFromHTML(item.noticeContent) item.noticeContent = that.extractTextFromHTML(
}) item.noticeContent
that.unreadList = res.data.data );
});
that.unreadList = res.data.data;
console.log(that.unreadList); console.log(that.unreadList);
that.openPopup() that.openPopup();
} else { } else {
console.log('无未读公告'); console.log("无未读公告");
} }
} else { } else {
uni.showToast({ uni.showToast({
icon: 'none', icon: "none",
title: res.data.msg title: res.data.msg,
}) });
} }
}).catch(err => {
console.log(err);
}) })
.catch((err) => {
console.log(err);
});
}, },
onNavigationBarButtonTap(e) { onNavigationBarButtonTap(e) {
console.log(e); console.log(e);
if (e.text == '权限') { if (e.text == "权限") {
uni.navigateTo({ uni.navigateTo({
url: '/pages/authManage/authManage' url: "/pages/authManage/authManage",
}) });
} else if (e.text == '扫一扫') { } else if (e.text == "扫一扫") {
uni.scanCode({ uni.scanCode({
success: (res) => { success: (res) => {
console.log(res); console.log(res);
const fixedRes = res.result.split('=')[1] const fixedRes = res.result.split("=")[1];
console.log(fixedRes); console.log(fixedRes);
uni.navigateTo({ uni.navigateTo({
url: `/pages/indexScan/indexScan?scan=${fixedRes}` url: `/pages/indexScan/indexScan?scan=${fixedRes}`,
}) });
} },
}) });
}
}
} }
},
};
</script> </script>
<style lang="scss"> <style lang="scss">
body { body {
background: url('/static/bgd.png'); background: url("/static/bgd.png");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
} }
@ -369,13 +402,13 @@
border-radius: 15rpx 15rpx 0 0; border-radius: 15rpx 15rpx 0 0;
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(2px); backdrop-filter: blur(2px);
border: 1px solid #B3D3FF; border: 1px solid #b3d3ff;
padding: 1.3vh 0; padding: 1.3vh 0;
display: flex; display: flex;
view { view {
width: 25%; width: 25%;
height: 100%; height: 100%;
border-right: 1px solid #CDE2FF; border-right: 1px solid #cde2ff;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-around; justify-content: space-around;
@ -438,22 +471,22 @@
} }
} }
.llsp { .llsp {
background: url('/static/llsp.png'); background: url("/static/llsp.png");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
} }
.tlsp { .tlsp {
background: url('/static/tlsp.png'); background: url("/static/tlsp.png");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
} }
.bfsh { .bfsh {
background: url('/static/bfsh.png'); background: url("/static/bfsh.png");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
} }
.sysh { .sysh {
background: url('/static/sysh.png'); background: url("/static/sysh.png");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
} }
@ -461,7 +494,7 @@
.single-notice { .single-notice {
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;
border-bottom: 1px solid #DEE3EA; border-bottom: 1px solid #dee3ea;
box-sizing: border-box; box-sizing: border-box;
padding: 20rpx 5%; padding: 20rpx 5%;
display: flex; display: flex;
@ -488,7 +521,7 @@
} }
h5 { h5 {
font-size: 12px; font-size: 12px;
color: #8F9298; color: #8f9298;
font-weight: normal; font-weight: normal;
} }
} }
@ -499,7 +532,7 @@
background-color: #fff; background-color: #fff;
border-radius: 15rpx; border-radius: 15rpx;
overflow-y: auto; overflow-y: auto;
background: linear-gradient(#D9E7FE, #fff, #fff, #fff); background: linear-gradient(#d9e7fe, #fff, #fff, #fff);
.pop-top { .pop-top {
width: 100%; width: 100%;
height: 5vh; height: 5vh;
@ -538,7 +571,7 @@
box-sizing: border-box; box-sizing: border-box;
border-radius: 15rpx; border-radius: 15rpx;
padding: 10rpx 0; padding: 10rpx 0;
background-color: #3788FF; background-color: #3788ff;
color: #fff; color: #fff;
} }
} }