guoyujia 4 luni în urmă
părinte
comite
15edb4b685
4 a modificat fișierele cu 198 adăugiri și 6 ștergeri
  1. 1 0
      package.json
  2. 17 0
      pages.json
  3. 111 0
      pages/notification/index.vue
  4. 69 6
      utils/request.js

+ 1 - 0
package.json

@@ -1,5 +1,6 @@
 {
   "dependencies": {
+    "vue-inset-loader": "^1.2.6",
     "vuex": "^4.1.0"
   }
 }

+ 17 - 0
pages.json

@@ -616,6 +616,23 @@
 				"navigationBarTitleText": "检查列表",
 				"onReachBottomDistance": 100
 			}
+		},
+		{
+			"path": "pages/notification/index",
+			"style": {
+				"navigationBarTitleText": "",
+				"enablePullDownRefresh": false,
+				"navigationStyle": "custom",
+				"app-plus": {
+					"animationType": "fade-in", // 设置fade-in淡入动画,为最合理的动画类型
+					"background": "transparent", // 背景透明
+					"backgroundColor": "transparent", // 背景透明
+					"webviewBGTransparent": true,
+					"mask": "none",
+					"popGesture": "none", // 关闭IOS屏幕左边滑动关闭当前页面的功能
+					"bounce": "none" // 将回弹属性关掉
+				}
+			}
 		}
 	],
 	"globalStyle": {

+ 111 - 0
pages/notification/index.vue

@@ -0,0 +1,111 @@
+<template>
+	<view class="informantion_mask">
+		<view class="informantion_content" @tap.stop.prevent>
+			<view class="informantion-title">
+				<p class="informantion-title-p">公告</p>
+				<span class="informantion-title-span">{{message}}</span>
+			</view>
+
+		</view>
+	</view>
+</template>
+
+<script setup>
+	import {
+		normalizeProps,
+		reactive,
+		onMounted,
+		ref,
+		getCurrentInstance
+	} from 'vue'
+	import {
+		onLoad,
+		onReady,
+		onUnload,
+		onShow,
+		onReachBottom
+	} from '@dcloudio/uni-app'
+
+	import {
+		store
+	} from '@/store/index.js'
+	const message = ref('')
+	onMounted(() => {
+		const instance = getCurrentInstance().proxy
+		const eventChannel = instance.getOpenerEventChannel();
+		eventChannel.on('notification', function(data) {
+			console.log('notification', data)
+			if (data && data.data) {
+				message.value = data.data.content;
+
+			}
+		})
+
+	})
+</script>
+
+<style lang="scss">
+	page {
+		width: 100%;
+		height: 100%;
+		background: rgba(0, 0, 0, 0.4);
+	}
+
+	.informantion_mask {
+		width: 100%;
+		height: 100%;
+		display: flex;
+		flex-direction: row;
+		justify-content: center;
+		align-items: center;
+	}
+
+	.informantion_content {
+		width: 600rpx;
+		height: 820rpx;
+		overflow: hidden;
+		border-radius: 10rpx;
+		background-color: white;
+		display: flex;
+		flex-direction: column;
+		justify-content: space-between;
+		padding-bottom: 20rpx;
+	}
+
+	.mask-header {
+		height: 400rpx;
+		position: relative;
+		background-image: url('../../static/images/bj.png');
+		background-repeat: no-repeat;
+		background-size: cover;
+
+		image {
+			width: 40rpx;
+			height: 40rpx;
+			position: absolute;
+			top: 20rpx;
+			right: 20rpx;
+		}
+	}
+
+	.informantion-title {
+		text-align: center;
+		padding: 0 40rpx;
+
+		p {
+			font-size: 35rpx;
+			font-weight: bold;
+			line-height: 80rpx;
+		}
+
+		span {
+			color: #6C6C6C;
+		}
+	}
+
+	.informantion-btn {
+		height: 93rpx;
+		width: 80%;
+		margin: 0 auto;
+	}
+</style>

+ 69 - 6
utils/request.js

@@ -1,12 +1,22 @@
-import { getToken } from '@/utils/auth'
+import {
+	getToken
+} from '@/utils/auth'
+import {
+	store
+} from '@/store/index.js'
+import globalModal from "@/components/dialog-notification/dialog-notification.vue";
 // import baseURL from '@/api/base/path.js'
 
-function request({url, data, method="GET"}) {
+function behindRequist({
+	url,
+	data,
+	method = "GET"
+}) {
 	let token = 'Bearer ' + getToken();
 	let header = {
-	    Authorization: token
+		Authorization: token
 	}
-	return new Promise((resolve, reject)=>{
+	return new Promise((resolve, reject) => {
 		const urlList = uni.getStorageSync('baseUrl')
 		uni.request({
 			url: JSON.parse(urlList).baseUrl + url,
@@ -50,5 +60,58 @@ function request({url, data, method="GET"}) {
 		})
 	})
 }
-export default {request}
-
+// 拦截请求的函数
+function request(options) {
+	return preRequest().then(() => {
+		// 前置请求成功,继续执行原请求
+		return behindRequist(options);
+	}).catch((error) => {
+		// 前置请求失败,处理错误
+		uni.showToast({
+			icon: 'none',
+			title: error.message || '前置请求失败',
+			duration: 1500
+		});
+		return Promise.reject(error);
+	});
+}
+// 前置请求函数
+function preRequest() {
+	let token = 'Bearer ' + getToken();
+	let header = {
+		Authorization: token
+	};
+	return new Promise((resolve, reject) => {
+		const urlList = uni.getStorageSync('baseUrl')
+		console.log(urlList)
+		uni.request({
+			url: JSON.parse(urlList).baseUrl + '/business/notification/getHasNotification', // 前置请求的URL
+			header,
+			method: 'GET',
+			success: (res) => {
+				console.log(res)
+				if (res.data.code == 200) {
+					uni.navigateTo({
+						url: "/pages/notification/index",
+						success: (resqust) => {
+							// 通过eventChannel向被打开页面传送数据
+							resqust.eventChannel.emit("notification", {
+								data: res.data.data[0]
+							})
+						}
+					})
+				} else {
+					// 前置请求成功,继续执行原请求
+					resolve(true);
+				}
+			},
+			fail: (err) => {
+				// 前置请求失败,不执行原请求
+				reject(err);
+			}
+		});
+	});
+}
+export default {
+	request
+}