Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes-pad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ximai
mes-pad
Commits
ef1a018a
Commit
ef1a018a
authored
Mar 20, 2024
by
张海景
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:修改打印加上连接失败提示
parent
842bae6b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
32 deletions
+57
-32
index.vue
pages/index/index.vue
+2
-2
$u.mixin.js
store/$u.mixin.js
+55
-30
No files found.
pages/index/index.vue
View file @
ef1a018a
...
...
@@ -2,7 +2,7 @@
<view
class=
"common-container"
>
<!--
<u-button
@
click=
"handleTest"
>
跳转测试
</u-button>
-->
<view
class=
"header"
>
<image
mode=
"widthFix"
class=
"header-logo"
style=
"width:
10
0px; margin: 10px auto; display: block"
src=
"/static/logo.png"
></image>
<image
mode=
"widthFix"
class=
"header-logo"
style=
"width:
8
0px; margin: 10px auto; display: block"
src=
"/static/logo.png"
></image>
<TabHeader></TabHeader>
<view
class=
"setting-body"
@
click=
"handleUserTaped"
>
<u-icon
name=
"list"
size=
"45"
class=
"setting-icon"
></u-icon>
...
...
@@ -303,7 +303,7 @@ export default {
}
.header
{
width
:
11
0px
;
width
:
9
0px
;
background-color
:
#132138
;
color
:
aliceblue
;
font-size
:
25px
;
...
...
store/$u.mixin.js
View file @
ef1a018a
import
{
mapState
}
from
'vuex'
import
{
mapState
}
from
'vuex'
import
store
from
"@/store"
import
io
from
'@hyoga/uni-socket.io'
;
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
let
$uStoreKey
=
[];
try
{
$uStoreKey
=
store
.
state
?
Object
.
keys
(
store
.
state
)
:
[];
}
catch
(
e
)
{
try
{
$uStoreKey
=
store
.
state
?
Object
.
keys
(
store
.
state
)
:
[];
}
catch
(
e
)
{
}
module
.
exports
=
{
beforeCreate
()
{
// 将vuex方法挂在到$u中
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
this
.
$u
.
vuex
=
(
name
,
value
)
=>
{
this
.
$store
.
commit
(
'$uStore'
,
{
name
,
value
})
}
},
beforeCreate
()
{
// 将vuex方法挂在到$u中
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
this
.
$u
.
vuex
=
(
name
,
value
)
=>
{
this
.
$store
.
commit
(
'$uStore'
,
{
name
,
value
})
}
},
data
()
{
return
{
pdfSocket
:
null
pdfSocket
:
null
,
socketConnect
:
false
,
}
},
computed
:
{
// 将vuex的state中的所有变量,解构到全局混入的mixin中
...
mapState
(
$uStoreKey
)
},
methods
:
{
createSocket
()
{
computed
:
{
// 将vuex的state中的所有变量,解构到全局混入的mixin中
...
mapState
(
$uStoreKey
)
},
methods
:
{
createSocket
(
params
)
{
this
.
pdfSocket
=
io
(
this
.
vuex_printerHostUrl
,
{
transports
:
[
'websocket'
],
auth
:
{
...
...
@@ -39,23 +43,44 @@ module.exports = {
},
});
this
.
pdfSocket
.
on
(
'connect'
,
()
=>
{
globalThis
.
c
onnect
=
true
;
this
.
socketC
onnect
=
true
;
// console.log('连接成功444');
this
.
printPdfSocket
(
params
)
// TODO: Do something for your project
});
this
.
pdfSocket
.
on
(
'clients'
,
(
clients
)
=>
{
globalThis
.
clients
=
clients
;
this
.
socketConnect
=
clients
;
console
.
log
(
clients
,
'clients'
);
});
this
.
pdfSocket
.
on
(
'printerList'
,
(
printerList
)
=>
{
globalThis
.
printerList
=
printerList
;
console
.
log
(
printerList
,
'printerList'
);
//
globalThis.printerList = printerList;
//
console.log(printerList, 'printerList');
});
this
.
pdfSocket
.
on
(
"success"
,
(
res
)
=>
{
console
.
log
(
res
,
'打印成功'
)
})
this
.
pdfSocket
.
on
(
"error"
,
(
res
)
=>
{
console
.
log
(
res
,
'打印失败'
)
})
this
.
pdfSocket
.
on
(
"disconnect"
,
()
=>
{
this
.
socketConnect
=
false
;
console
.
log
(
'打印机断开'
)
})
setTimeout
(()
=>
{
if
(
!
this
.
socketConnect
)
{
console
.
log
(
'连接失败'
)
this
.
$u
.
toast
(
'打印机连接失败'
)
}
},
1000
)
},
printPdfSocket
(
params
)
{
// console.log(this.pdfSocket, 'pdfSocket')
if
(
!
this
.
pdfSocket
)
{
this
.
createSocket
()
if
(
!
this
.
socketConnect
)
{
this
.
createSocket
(
params
)
return
}
this
.
$u
.
api
.
getPrintDown
(
params
)
...
...
@@ -70,6 +95,6 @@ module.exports = {
});
}
});
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment