system-phone 1.2.80-socket-10 → 1.2.80-socket-12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "system-phone",
3
- "version": "1.2.80-socket-10",
3
+ "version": "1.2.80-socket-12",
4
4
  "description": "手机模块 前端组件",
5
5
  "author": "何宁社 <524395609@qq.com>",
6
6
  "license": "ISC",
@@ -1,245 +1,245 @@
1
- <template>
2
- <div style="height: 7%">
3
- <tools-page :need-back="!isMenu" :title="titleName" @back="back('返回')" > </tools-page>
4
- </div>
5
- <div id="app" :class="{'auto':isMenu,'app-height':!isMenu}">
6
- <div class="row" style="overflow-y: scroll;">
7
- <route v-ref:route> </route>
8
- </div>
9
- <tab-bar @select-item="onClickTabBarItem" v-show="isMenu">
10
- </tab-bar>
11
- </div>
12
- </template>
13
-
14
- <script>
15
- import Vue from 'vue'
16
- export default {
17
- title: 'app',
18
- data: function () {
19
- return {
20
- item: 0,
21
- isMenu:true,
22
- beforeName:'主界面',
23
- titleName:'待办工作',
24
- backthis:'',
25
- safe:false,
26
- beforetabs:[],
27
- iftabbar:'',
28
- lockReconnect: false, // 避免重复连接
29
- timeout: 10000, // 10秒发一次心跳
30
- connectNumber: 10, // 重连次数
31
- timeoutObj: null,
32
- serverTimeoutObj: null
33
- }
34
- },
35
- ready(){
36
-
37
- Vue.prototype.$connectNumber = this.connectNumber
38
- this.initWebSocket()
39
- },
40
- methods: {
41
- // 清除
42
- reset () {
43
- clearTimeout(this.timeoutObj)
44
- clearTimeout(this.serverTimeoutObj)
45
- },
46
- // 发送心跳
47
- start () {
48
- // 重置
49
- Vue.prototype.$connectNumber = this.connectNumber
50
- this.timeoutObj = setTimeout(() => {
51
- this.$socket.send('ping')
52
- console.log('ping!')
53
- this.serverTimeoutObj = setTimeout(() => {
54
- this.$socket.close()
55
- }, this.timeout)
56
- }, this.timeout)
57
- },
58
- // 重连
59
- reconnect () {
60
- if (this.lockReconnect) return
61
- if (this.$connectNumber <= 0) {
62
- this.showMessage('连接已断开,将无法接收消息,请重新登录', ['confirm']).then((res) => {
63
- if (res === 'confirm') {
64
- this.$androidUtil.setPreference('f_repairman_id', 'x')
65
- this.$androidUtil.setPreference('f_repairman_name', 'x')
66
- this.beforetabs = []
67
- this.$back()
68
- }
69
- })
70
- return
71
- }
72
- this.$connectNumber--
73
- setTimeout(() => {
74
- console.log('连接异常,尝试重新连接。。。。')
75
- this.initWebSocket()
76
- this.lockReconnect = false
77
- }, 1000 * 60)
78
- },
79
- // 初始化
80
- initWebSocket () {
81
- console.log("初始化")
82
- console.log(this.$androidUtil.getProxyUrl())
83
- let wshttp = `${this.$androidUtil.getProxyUrl()}`
84
- let pathhttp = wshttp.substring(7)
85
-
86
- let path = `ws://${pathhttp}ws?token=${Vue.user.id}`
87
- console.log(path)
88
- console.log("9999999999999999999999999")
89
- try {
90
- if ('WebSocket' in window) {
91
- // 创建对象
92
- Vue.prototype.$socket = new WebSocket(path)
93
- } else {
94
- this.$showMessage('您的浏览器不支持websocket的协议,建议使用新版谷歌浏览器,请勿使用IE浏览器,360浏览器请使用极速模式,不要使用兼容模式!"')
95
- }
96
- } catch (e) {
97
- this.reconnect()
98
- }
99
-
100
- this.$socket.onopen = this.onOpen // 连接成功
101
- this.$socket.onmessage = this.onMessage // 收到消息时回调
102
- this.$socket.onclose = this.onClose // 连接关闭时回调
103
- this.$socket.onerror = this.onError // 通讯异常
104
- },
105
- // 通讯异常
106
- onError () {
107
- this.reconnect()
108
- },
109
- // 连接成功
110
- onOpen () {
111
- console.log('webSocket连接成功')
112
- this.start()
113
- },
114
- // 收到消息时回调函数
115
- onMessage (event) {
116
- if (event.data === 'pong') {
117
- this.reset()
118
- this.start()
119
- return
120
- }
121
- // if (event.type === 'apply-task') {
122
- // console.log("aaa")
123
- // }
124
- console.log("555555555555")
125
- console.log(event)
126
- let data = JSON.parse(event.data)
127
- if (data.type === 'dot-task') {
128
- HostApp.voicePromptOnce('dadian.mp3')
129
- }
130
- this.$broadcast('onMessage', data)
131
- this.$showMessage(data.message)
132
- },
133
- // 关闭连接时回调函数
134
- onClose () {
135
- console.log('webSocket连接断开')
136
- this.reset()
137
- this.reconnect()
138
- },
139
- back(flag){
140
- if(this.safe && flag == '返回' ){
141
- this.$showMessage('此返回所录入内容将无法找回!', ['confirm', 'cancel']).then((res) => {
142
- if (res === 'confirm') {
143
- this.safe = false
144
- this.delback()
145
- this.backthis.$back()
146
- }
147
- })
148
- }else{
149
- this.delback()
150
- this.safe = false
151
- this.backthis.$back()
152
- }
153
- },
154
- delback(){
155
- // 先确认出 前一个组件的名字
156
- var title = this.beforeName
157
- var beforetitle = '主界面'
158
- var j = -1
159
- for(var i = 0;i<this.beforetabs.length;i++){
160
- if(this.beforetabs[i].titleName == title){
161
- beforetitle = this.beforetabs[i].beforeName
162
- this.backthis =this.beforetabs[i].backthis
163
- this.safe = this.beforetabs[i].safe
164
- j = i
165
- break;
166
- }
167
- }
168
- this.beforetabs.splice(j + 1, 1)
169
- this.beforeName = beforetitle
170
- this.titleName = title
171
- // 判断是否 显示底层导航
172
- if(this.iftabbar == this.titleName){
173
- this.isMenu = true
174
- }
175
- },
176
- onClickTabBarItem(titlefg) {
177
- var param = titlefg.link
178
- if(titlefg.name == '退出系统'){
179
- this.$showMessage('即将返回登陆界面!', ['confirm', 'cancel']).then((res) => {
180
- if (res === 'confirm') {
181
- this.$androidUtil.setPreference('f_repairman_id', 'x')
182
- this.$androidUtil.setPreference('f_repairman_name', 'x')
183
- this.$back()
184
- }
185
- })
186
- }else{
187
- if(this.beforeName == titlefg.name){
188
- return
189
- }
190
- this.titleName = titlefg.name
191
- this.beforeName = titlefg.name
192
- let data = {
193
- sourcet: '竖屏'
194
- }
195
- // if(titlefg.name == '待办工单'){
196
- // param = param+'V'
197
- // }
198
- this.$refs.route.init(param,data)
199
- }
200
- }
201
- },
202
- events: {
203
- 'gotoson': function (prpdata) {
204
- // 事件回调内的 `this` 自动绑定到注册它的实例上
205
- // safe 返回事件是否进行判断后再返回
206
- // 每进入一次,beforetabs 数组添加 返回 删除
207
- this.backthis = prpdata._this
208
- this.safe = prpdata.safe
209
- this.isMenu = false
210
- // 记录本次跳转
211
- var beforedata = {
212
- beforeName: this.titleName,
213
- titleName: prpdata.title,
214
- backthis:prpdata._this,
215
- safe:prpdata.safe
216
- }
217
- this.beforetabs.push(beforedata)
218
- if( this.beforetabs.length == 1){
219
- this.iftabbar = beforedata.beforeName
220
- }
221
- // 写入跳转后 前后组件名字
222
- this.beforeName = this.titleName
223
- this.titleName = prpdata.title
224
-
225
- console.log('进入子组件,通知外层组件,我已经进入')
226
- },
227
- 'confirm': function () {
228
- // 提交处理返回事件
229
- this.back('提交')
230
- },
231
- 'backarrdel': function () {
232
- this.delback()
233
- },
234
- 'gologin': function () {
235
- this.beforetabs = []
236
- this.$back()
237
- }
238
- }
239
- }
240
- </script>
241
- <style scoped>
242
- .app-height{
243
- height: 93%;
244
- }
245
- </style>
1
+ <template>
2
+ <div style="height: 7%">
3
+ <tools-page :need-back="!isMenu" :title="titleName" @back="back('返回')" > </tools-page>
4
+ </div>
5
+ <div id="app" :class="{'auto':isMenu,'app-height':!isMenu}">
6
+ <div class="row" :style="isMenu?'overflow-y: scroll;overflow-x: hidden;height:80vh':'overflow-y: scroll;overflow-x: hidden;'">
7
+ <route v-ref:route> </route>
8
+ </div>
9
+ <tab-bar @select-item="onClickTabBarItem" v-show="isMenu">
10
+ </tab-bar>
11
+ </div>
12
+ </template>
13
+
14
+ <script>
15
+ import Vue from 'vue'
16
+ export default {
17
+ title: 'app',
18
+ data: function () {
19
+ return {
20
+ item: 0,
21
+ isMenu:true,
22
+ beforeName:'主界面',
23
+ titleName:'待办工作',
24
+ backthis:'',
25
+ safe:false,
26
+ beforetabs:[],
27
+ iftabbar:'',
28
+ lockReconnect: false, // 避免重复连接
29
+ timeout: 10000, // 10秒发一次心跳
30
+ connectNumber: 10, // 重连次数
31
+ timeoutObj: null,
32
+ serverTimeoutObj: null
33
+ }
34
+ },
35
+ ready(){
36
+
37
+ Vue.prototype.$connectNumber = this.connectNumber
38
+ this.initWebSocket()
39
+ },
40
+ methods: {
41
+ // 清除
42
+ reset () {
43
+ clearTimeout(this.timeoutObj)
44
+ clearTimeout(this.serverTimeoutObj)
45
+ },
46
+ // 发送心跳
47
+ start () {
48
+ // 重置
49
+ Vue.prototype.$connectNumber = this.connectNumber
50
+ this.timeoutObj = setTimeout(() => {
51
+ this.$socket.send('ping')
52
+ console.log('ping!')
53
+ this.serverTimeoutObj = setTimeout(() => {
54
+ this.$socket.close()
55
+ }, this.timeout)
56
+ }, this.timeout)
57
+ },
58
+ // 重连
59
+ reconnect () {
60
+ if (this.lockReconnect) return
61
+ if (this.$connectNumber <= 0) {
62
+ this.showMessage('连接已断开,将无法接收消息,请重新登录', ['confirm']).then((res) => {
63
+ if (res === 'confirm') {
64
+ this.$androidUtil.setPreference('f_repairman_id', 'x')
65
+ this.$androidUtil.setPreference('f_repairman_name', 'x')
66
+ this.beforetabs = []
67
+ this.$back()
68
+ }
69
+ })
70
+ return
71
+ }
72
+ this.$connectNumber--
73
+ setTimeout(() => {
74
+ console.log('连接异常,尝试重新连接。。。。')
75
+ this.initWebSocket()
76
+ this.lockReconnect = false
77
+ }, 1000 * 60)
78
+ },
79
+ // 初始化
80
+ initWebSocket () {
81
+ console.log("初始化")
82
+ console.log(this.$androidUtil.getProxyUrl())
83
+ let wshttp = `${this.$androidUtil.getProxyUrl()}`
84
+ let pathhttp = wshttp.substring(7)
85
+
86
+ let path = `ws://${pathhttp}ws?token=${Vue.user.id}`
87
+ console.log(path)
88
+ console.log("9999999999999999999999999")
89
+ try {
90
+ if ('WebSocket' in window) {
91
+ // 创建对象
92
+ Vue.prototype.$socket = new WebSocket(path)
93
+ } else {
94
+ this.$showMessage('您的浏览器不支持websocket的协议,建议使用新版谷歌浏览器,请勿使用IE浏览器,360浏览器请使用极速模式,不要使用兼容模式!"')
95
+ }
96
+ } catch (e) {
97
+ this.reconnect()
98
+ }
99
+
100
+ this.$socket.onopen = this.onOpen // 连接成功
101
+ this.$socket.onmessage = this.onMessage // 收到消息时回调
102
+ this.$socket.onclose = this.onClose // 连接关闭时回调
103
+ this.$socket.onerror = this.onError // 通讯异常
104
+ },
105
+ // 通讯异常
106
+ onError () {
107
+ this.reconnect()
108
+ },
109
+ // 连接成功
110
+ onOpen () {
111
+ console.log('webSocket连接成功')
112
+ this.start()
113
+ },
114
+ // 收到消息时回调函数
115
+ onMessage (event) {
116
+ if (event.data === 'pong') {
117
+ this.reset()
118
+ this.start()
119
+ return
120
+ }
121
+ // if (event.type === 'apply-task') {
122
+ // console.log("aaa")
123
+ // }
124
+ console.log("555555555555")
125
+ console.log(event)
126
+ let data = JSON.parse(event.data)
127
+ if (data.type === 'dot-task') {
128
+ HostApp.voicePromptOnce('dadian.mp3')
129
+ }
130
+ this.$broadcast('onMessage', data)
131
+ this.$showMessage(data.message)
132
+ },
133
+ // 关闭连接时回调函数
134
+ onClose () {
135
+ console.log('webSocket连接断开')
136
+ this.reset()
137
+ this.reconnect()
138
+ },
139
+ back(flag){
140
+ if(this.safe && flag == '返回' ){
141
+ this.$showMessage('此返回所录入内容将无法找回!', ['confirm', 'cancel']).then((res) => {
142
+ if (res === 'confirm') {
143
+ this.safe = false
144
+ this.delback()
145
+ this.backthis.$back()
146
+ }
147
+ })
148
+ }else{
149
+ this.delback()
150
+ this.safe = false
151
+ this.backthis.$back()
152
+ }
153
+ },
154
+ delback(){
155
+ // 先确认出 前一个组件的名字
156
+ var title = this.beforeName
157
+ var beforetitle = '主界面'
158
+ var j = -1
159
+ for(var i = 0;i<this.beforetabs.length;i++){
160
+ if(this.beforetabs[i].titleName == title){
161
+ beforetitle = this.beforetabs[i].beforeName
162
+ this.backthis =this.beforetabs[i].backthis
163
+ this.safe = this.beforetabs[i].safe
164
+ j = i
165
+ break;
166
+ }
167
+ }
168
+ this.beforetabs.splice(j + 1, 1)
169
+ this.beforeName = beforetitle
170
+ this.titleName = title
171
+ // 判断是否 显示底层导航
172
+ if(this.iftabbar == this.titleName){
173
+ this.isMenu = true
174
+ }
175
+ },
176
+ onClickTabBarItem(titlefg) {
177
+ var param = titlefg.link
178
+ if(titlefg.name == '退出系统'){
179
+ this.$showMessage('即将返回登陆界面!', ['confirm', 'cancel']).then((res) => {
180
+ if (res === 'confirm') {
181
+ this.$androidUtil.setPreference('f_repairman_id', 'x')
182
+ this.$androidUtil.setPreference('f_repairman_name', 'x')
183
+ this.$back()
184
+ }
185
+ })
186
+ }else{
187
+ if(this.beforeName == titlefg.name){
188
+ return
189
+ }
190
+ this.titleName = titlefg.name
191
+ this.beforeName = titlefg.name
192
+ let data = {
193
+ sourcet: '竖屏'
194
+ }
195
+ // if(titlefg.name == '待办工单'){
196
+ // param = param+'V'
197
+ // }
198
+ this.$refs.route.init(param,data)
199
+ }
200
+ }
201
+ },
202
+ events: {
203
+ 'gotoson': function (prpdata) {
204
+ // 事件回调内的 `this` 自动绑定到注册它的实例上
205
+ // safe 返回事件是否进行判断后再返回
206
+ // 每进入一次,beforetabs 数组添加 返回 删除
207
+ this.backthis = prpdata._this
208
+ this.safe = prpdata.safe
209
+ this.isMenu = false
210
+ // 记录本次跳转
211
+ var beforedata = {
212
+ beforeName: this.titleName,
213
+ titleName: prpdata.title,
214
+ backthis:prpdata._this,
215
+ safe:prpdata.safe
216
+ }
217
+ this.beforetabs.push(beforedata)
218
+ if( this.beforetabs.length == 1){
219
+ this.iftabbar = beforedata.beforeName
220
+ }
221
+ // 写入跳转后 前后组件名字
222
+ this.beforeName = this.titleName
223
+ this.titleName = prpdata.title
224
+
225
+ console.log('进入子组件,通知外层组件,我已经进入')
226
+ },
227
+ 'confirm': function () {
228
+ // 提交处理返回事件
229
+ this.back('提交')
230
+ },
231
+ 'backarrdel': function () {
232
+ this.delback()
233
+ },
234
+ 'gologin': function () {
235
+ this.beforetabs = []
236
+ this.$back()
237
+ }
238
+ }
239
+ }
240
+ </script>
241
+ <style scoped>
242
+ .app-height{
243
+ height: 93%;
244
+ }
245
+ </style>