Signalr推送
This commit is contained in:
parent
36b729a026
commit
5239e90611
11
App.vue
11
App.vue
@ -7,6 +7,13 @@ export default {
|
|||||||
onLaunch: function () {
|
onLaunch: function () {
|
||||||
this.initApp();
|
this.initApp();
|
||||||
},
|
},
|
||||||
|
onUnload() {
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
|
||||||
|
};
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 初始化应用
|
// 初始化应用
|
||||||
initApp() {
|
initApp() {
|
||||||
@ -16,9 +23,8 @@ export default {
|
|||||||
//#ifdef H5
|
//#ifdef H5
|
||||||
this.checkLogin();
|
this.checkLogin();
|
||||||
//#endif
|
//#endif
|
||||||
// 震动实验
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
initConfig() {
|
initConfig() {
|
||||||
this.globalData.config = config;
|
this.globalData.config = config;
|
||||||
},
|
},
|
||||||
@ -31,6 +37,7 @@ export default {
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@import '@/static/scss/index.scss';
|
@import '@/static/scss/index.scss';
|
||||||
.border {
|
.border {
|
||||||
|
|||||||
212
manifest.json
212
manifest.json
@ -1,105 +1,109 @@
|
|||||||
{
|
{
|
||||||
"name" : "DOAN总装车间PDA",
|
"name": "DOAN总装车间PDA",
|
||||||
"appid" : "__UNI__EFA389B",
|
"appid": "__UNI__EFA389B",
|
||||||
"description" : "DOAN总装车间PDA",
|
"description": "DOAN总装车间PDA",
|
||||||
"versionName" : "1.5.0",
|
"versionName": "1.5.0",
|
||||||
"versionCode" : 150,
|
"versionCode": 150,
|
||||||
"transformPx" : false,
|
"transformPx": false,
|
||||||
"app-plus" : {
|
"app-plus": {
|
||||||
"usingComponents" : true,
|
"networkTimeout": {
|
||||||
"nvueCompiler" : "uni-app",
|
"request": 60000
|
||||||
"splashscreen" : {
|
},
|
||||||
"alwaysShowBeforeRender" : true,
|
"usesCleartextTraffic": true,
|
||||||
"waiting" : true,
|
"usingComponents": true,
|
||||||
"autoclose" : true,
|
"nvueCompiler": "uni-app",
|
||||||
"delay" : 0
|
"splashscreen": {
|
||||||
},
|
"alwaysShowBeforeRender": true,
|
||||||
"modules" : {},
|
"waiting": true,
|
||||||
"distribute" : {
|
"autoclose": true,
|
||||||
"android" : {
|
"delay": 0
|
||||||
"permissions" : [
|
},
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
"modules": {},
|
||||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
"distribute": {
|
||||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
"android": {
|
||||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
"permissions": [
|
||||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||||
]
|
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||||
},
|
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||||
"ios" : {
|
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||||
"dSYMs" : false
|
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||||
},
|
]
|
||||||
"sdkConfigs" : {
|
},
|
||||||
"ad" : {}
|
"ios": {
|
||||||
},
|
"dSYMs": false
|
||||||
"icons" : {
|
},
|
||||||
"android" : {
|
"sdkConfigs": {
|
||||||
"hdpi" : "unpackage/res/icons/72x72.png",
|
"ad": {}
|
||||||
"xhdpi" : "unpackage/res/icons/96x96.png",
|
},
|
||||||
"xxhdpi" : "unpackage/res/icons/144x144.png",
|
"icons": {
|
||||||
"xxxhdpi" : "unpackage/res/icons/192x192.png"
|
"android": {
|
||||||
},
|
"hdpi": "unpackage/res/icons/72x72.png",
|
||||||
"ios" : {
|
"xhdpi": "unpackage/res/icons/96x96.png",
|
||||||
"appstore" : "unpackage/res/icons/1024x1024.png",
|
"xxhdpi": "unpackage/res/icons/144x144.png",
|
||||||
"ipad" : {
|
"xxxhdpi": "unpackage/res/icons/192x192.png"
|
||||||
"app" : "unpackage/res/icons/76x76.png",
|
},
|
||||||
"app@2x" : "unpackage/res/icons/152x152.png",
|
"ios": {
|
||||||
"notification" : "unpackage/res/icons/20x20.png",
|
"appstore": "unpackage/res/icons/1024x1024.png",
|
||||||
"notification@2x" : "unpackage/res/icons/40x40.png",
|
"ipad": {
|
||||||
"proapp@2x" : "unpackage/res/icons/167x167.png",
|
"app": "unpackage/res/icons/76x76.png",
|
||||||
"settings" : "unpackage/res/icons/29x29.png",
|
"app@2x": "unpackage/res/icons/152x152.png",
|
||||||
"settings@2x" : "unpackage/res/icons/58x58.png",
|
"notification": "unpackage/res/icons/20x20.png",
|
||||||
"spotlight" : "unpackage/res/icons/40x40.png",
|
"notification@2x": "unpackage/res/icons/40x40.png",
|
||||||
"spotlight@2x" : "unpackage/res/icons/80x80.png"
|
"proapp@2x": "unpackage/res/icons/167x167.png",
|
||||||
},
|
"settings": "unpackage/res/icons/29x29.png",
|
||||||
"iphone" : {
|
"settings@2x": "unpackage/res/icons/58x58.png",
|
||||||
"app@2x" : "unpackage/res/icons/120x120.png",
|
"spotlight": "unpackage/res/icons/40x40.png",
|
||||||
"app@3x" : "unpackage/res/icons/180x180.png",
|
"spotlight@2x": "unpackage/res/icons/80x80.png"
|
||||||
"notification@2x" : "unpackage/res/icons/40x40.png",
|
},
|
||||||
"notification@3x" : "unpackage/res/icons/60x60.png",
|
"iphone": {
|
||||||
"settings@2x" : "unpackage/res/icons/58x58.png",
|
"app@2x": "unpackage/res/icons/120x120.png",
|
||||||
"settings@3x" : "unpackage/res/icons/87x87.png",
|
"app@3x": "unpackage/res/icons/180x180.png",
|
||||||
"spotlight@2x" : "unpackage/res/icons/80x80.png",
|
"notification@2x": "unpackage/res/icons/40x40.png",
|
||||||
"spotlight@3x" : "unpackage/res/icons/120x120.png"
|
"notification@3x": "unpackage/res/icons/60x60.png",
|
||||||
}
|
"settings@2x": "unpackage/res/icons/58x58.png",
|
||||||
}
|
"settings@3x": "unpackage/res/icons/87x87.png",
|
||||||
}
|
"spotlight@2x": "unpackage/res/icons/80x80.png",
|
||||||
}
|
"spotlight@3x": "unpackage/res/icons/120x120.png"
|
||||||
},
|
}
|
||||||
"quickapp" : {},
|
}
|
||||||
"mp-weixin" : {
|
}
|
||||||
"appid" : "wxccd7e2a0911b3397",
|
}
|
||||||
"setting" : {
|
},
|
||||||
"urlCheck" : false,
|
"quickapp": {},
|
||||||
"es6" : false,
|
"mp-weixin": {
|
||||||
"minified" : true,
|
"appid": "wxccd7e2a0911b3397",
|
||||||
"postcss" : true
|
"setting": {
|
||||||
},
|
"urlCheck": false,
|
||||||
"optimization" : {
|
"es6": false,
|
||||||
"subPackages" : true
|
"minified": true,
|
||||||
},
|
"postcss": true
|
||||||
"usingComponents" : true
|
},
|
||||||
},
|
"optimization": {
|
||||||
"vueVersion" : "2",
|
"subPackages": true
|
||||||
"h5" : {
|
},
|
||||||
"template" : "static/index.html",
|
"usingComponents": true
|
||||||
"devServer" : {
|
},
|
||||||
"port" : 9090,
|
"vueVersion": "2",
|
||||||
"https" : false
|
"h5": {
|
||||||
},
|
"template": "static/index.html",
|
||||||
"title" : "RuoYi-App",
|
"devServer": {
|
||||||
"router" : {
|
"port": 9090,
|
||||||
"mode" : "hash",
|
"https": false
|
||||||
"base" : "./"
|
},
|
||||||
}
|
"title": "RuoYi-App",
|
||||||
}
|
"router": {
|
||||||
}
|
"mode": "hash",
|
||||||
|
"base": "./"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@microsoft/signalr": "^8.0.7",
|
||||||
"dayjs": "^1.11.13"
|
"dayjs": "^1.11.13"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
107
pages/index.vue
107
pages/index.vue
@ -34,17 +34,19 @@
|
|||||||
</uni-grid-item>
|
</uni-grid-item>
|
||||||
</uni-grid>
|
</uni-grid>
|
||||||
</view>
|
</view>
|
||||||
|
<view ref="socketRef"></view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fail } from 'assert';
|
import { getBaseUrl } from '@/utils/baseUrl';
|
||||||
export default {
|
export default {
|
||||||
onShow() {
|
onShow() {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
socketRef:null,
|
||||||
current: 0,
|
current: 0,
|
||||||
swiperDotIndex: 0,
|
swiperDotIndex: 0,
|
||||||
bannerList: [
|
bannerList: [
|
||||||
@ -79,7 +81,7 @@ export default {
|
|||||||
name: '安灯报警',
|
name: '安灯报警',
|
||||||
icon: 'notification-filled',
|
icon: 'notification-filled',
|
||||||
url: '/pages/produceManagement/andon/alarm'
|
url: '/pages/produceManagement/andon/alarm'
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
// 物料模块
|
// 物料模块
|
||||||
materialOptions: [
|
materialOptions: [
|
||||||
@ -87,7 +89,7 @@ export default {
|
|||||||
name: '产线备料',
|
name: '产线备料',
|
||||||
icon: 'upload-filled',
|
icon: 'upload-filled',
|
||||||
url: '/pages/materialManagement/preparationByPlan/index'
|
url: '/pages/materialManagement/preparationByPlan/index'
|
||||||
},
|
}
|
||||||
// {
|
// {
|
||||||
// name: '工单备料',
|
// name: '工单备料',
|
||||||
// icon: 'upload-filled',
|
// icon: 'upload-filled',
|
||||||
@ -122,11 +124,108 @@ export default {
|
|||||||
this.$modal.showToast('模块建设中~');
|
this.$modal.showToast('模块建设中~');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
// 处理来自 renderjs 的获取存储数据请求
|
||||||
|
handleGetStorage() {
|
||||||
|
const value = getBaseUrl();
|
||||||
|
console.log('handleGetStorage', this.$refs.socketRef);
|
||||||
|
this.$refs.socketRef.receiveStorageValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- SignalR的使用 -->
|
||||||
|
<script module="socketRef" lang="renderjs">
|
||||||
|
import SignalRUtil from '@/utils/signalrUtil';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
baseUrl:"",
|
||||||
|
signalRUtil: null,
|
||||||
|
isSignalRConnected: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
initSignalR() {
|
||||||
|
this.requestStorageValue();
|
||||||
|
let baseUrl = this.baseUrl;
|
||||||
|
let url = `http://${baseUrl}/pdaHub`;
|
||||||
|
//let url = "http://192.168.50.163/pdaHub";
|
||||||
|
this.signalRUtil = new SignalRUtil(url);
|
||||||
|
this.signalRUtil
|
||||||
|
.startConnection()
|
||||||
|
.then(() => {
|
||||||
|
this.isSignalRConnected = true;
|
||||||
|
// 监听服务器发送的消息
|
||||||
|
this.signalRUtil.on('Call', (message) => {
|
||||||
|
this.showSystemAlertAndVibrate(message)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('SignalR 连接失败:', error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
stopSignalRConnection() {
|
||||||
|
if (this.isSignalRConnected && this.signalRUtil) {
|
||||||
|
this.signalRUtil
|
||||||
|
.stopConnection()
|
||||||
|
.then(() => {
|
||||||
|
this.isSignalRConnected = false;
|
||||||
|
console.log('SignalR 连接已停止');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('停止 SignalR 连接失败:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 示例:发送系统通知并震动
|
||||||
|
showSystemAlertAndVibrate(obj) {
|
||||||
|
// 发送系统通知
|
||||||
|
this.sendNativeNotification(obj);
|
||||||
|
},
|
||||||
|
// 在需要发送通知的地方调用
|
||||||
|
sendNativeNotification(obj) {
|
||||||
|
const {lineCode,askPerson,faultDict,faultContext} = obj;
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
let content = `线别:${lineCode} 报警人:${askPerson}\n报警类别:${faultDict}\n报警内容:${faultContext}`;
|
||||||
|
let options = {
|
||||||
|
cover: false,
|
||||||
|
when: new Date(),
|
||||||
|
title: '产线Andon报警'
|
||||||
|
};
|
||||||
|
let body = {
|
||||||
|
id: 'id',
|
||||||
|
key: 'key'
|
||||||
|
};
|
||||||
|
let payload = JSON.stringify(body);
|
||||||
|
plus.push.createMessage(content, payload, options);
|
||||||
|
if (plus && plus.vibration) {
|
||||||
|
plus.vibration.vibrate(3000);
|
||||||
|
} else {
|
||||||
|
console.error('震动功能不可用');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
// 向逻辑层请求存储数据
|
||||||
|
requestStorageValue() {
|
||||||
|
this.$ownerInstance.callMethod('handleGetStorage');
|
||||||
|
},
|
||||||
|
// 接收逻辑层返回的存储数据
|
||||||
|
receiveStorageValue(value) {
|
||||||
|
console.log('从存储中获取的值:', value);
|
||||||
|
this.baseUrl = value;
|
||||||
|
|
||||||
|
// 在这里可以进行后续处理
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted() {
|
||||||
|
this.initSignalR()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
page {
|
page {
|
||||||
@ -186,7 +285,7 @@ view {
|
|||||||
height: 300rpx;
|
height: 300rpx;
|
||||||
line-height: 300rpx;
|
line-height: 300rpx;
|
||||||
}
|
}
|
||||||
.card-box{
|
.card-box {
|
||||||
padding-bottom: 60px;
|
padding-bottom: 60px;
|
||||||
margin-bottom: 60px;
|
margin-bottom: 60px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -150,33 +150,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch((err) => {});
|
.catch((err) => {});
|
||||||
},
|
},
|
||||||
// 在需要发送通知的地方调用
|
|
||||||
sendNativeNotification() {
|
|
||||||
// #ifdef APP-PLUS
|
|
||||||
let content = '您有一条新的消息~';
|
|
||||||
let options = {
|
|
||||||
cover: false,
|
|
||||||
when: new Date(),
|
|
||||||
title: '通知消息'
|
|
||||||
};
|
|
||||||
let body = {
|
|
||||||
id: 'id',
|
|
||||||
key: 'key'
|
|
||||||
};
|
|
||||||
let payload = JSON.stringify(body);
|
|
||||||
plus.push.createMessage(content, payload, options);
|
|
||||||
if (plus && plus.vibration) {
|
|
||||||
plus.vibration.vibrate(3000);
|
|
||||||
} else {
|
|
||||||
console.error('震动功能不可用');
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
},
|
|
||||||
// 示例:发送系统通知并震动
|
|
||||||
showSystemAlertAndVibrate() {
|
|
||||||
// 发送系统通知
|
|
||||||
this.sendNativeNotification();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
49
utils/signalrUtil.js
Normal file
49
utils/signalrUtil.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import * as signalR from '@microsoft/signalr';
|
||||||
|
import { getToken } from '@/utils/auth'
|
||||||
|
class SignalRUtil {
|
||||||
|
constructor(url) {
|
||||||
|
console.log('SignalR 连接:',url);
|
||||||
|
this.hubConnection = new signalR.HubConnectionBuilder()
|
||||||
|
.withUrl(url)
|
||||||
|
.withAutomaticReconnect()
|
||||||
|
.configureLogging(signalR.LogLevel.Warning)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
this.hubConnection.onclose(() => {
|
||||||
|
console.log('SignalR 连接已关闭');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async startConnection() {
|
||||||
|
try {
|
||||||
|
await this.hubConnection.start();
|
||||||
|
console.log('SignalR 连接已建立');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('SignalR 连接失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
on(methodName, callback) {
|
||||||
|
this.hubConnection.on(methodName, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
async invoke(methodName, ...args) {
|
||||||
|
try {
|
||||||
|
return await this.hubConnection.invoke(methodName, ...args);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('调用 SignalR 方法失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async stopConnection() {
|
||||||
|
try {
|
||||||
|
await this.hubConnection.stop();
|
||||||
|
console.log('SignalR 连接已停止');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('停止 SignalR 连接失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SignalRUtil;
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user