代码优化

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