home.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="home">
  3. <u-sticky bgColor="#f5f7fa" class="main-sticky">
  4. <view class="data-panel">
  5. <view class="lane-selector">
  6. <u-cell-group :border="false" >
  7. <u-cell
  8. @click="showPopup('popupLane')"
  9. value="切换"
  10. center
  11. :isLink="true"
  12. arrowDirection="down"
  13. >
  14. <span slot="title" class="lane-line">
  15. {{currentLane.name}}
  16. <span :class="isConnect?'status_1':'status_0'"></span>
  17. </span>
  18. </u-cell>
  19. </u-cell-group>
  20. </view>
  21. <view class="status-cards">
  22. <view class="status-card">
  23. <view class="label">品种</view>
  24. <view class="value kind">{{ currentData.materialName || ' ' }}</view>
  25. </view>
  26. <view class="status-card">
  27. <view class="label">预装数</view>
  28. <view class="value">{{ currentData.number || '0'}}</view>
  29. </view>
  30. <view class="status-card">
  31. <view class="label">已装数</view>
  32. <view class="value highlight">{{ currentData.hasNum || '0' }}</view>
  33. </view>
  34. </view>
  35. </view>
  36. </u-sticky>
  37. <!-- 订单列表区域 -->
  38. <view class="order-list">
  39. <view class="section-title">
  40. <span>包装任务</span>
  41. <view>
  42. <u-button style="height:64rpx;padding:0 40rpx" type="primary" shape="circle" @click="toAdd">新增</u-button>
  43. </view>
  44. </view>
  45. <view class="order-cards">
  46. <view
  47. v-for="order in orders"
  48. :key="order.id"
  49. class="order-card"
  50. >
  51. <view class="order-header">
  52. <span class="lane">{{ order.lane }}车道</span>
  53. <span class="time">{{ order.roadName }}</span>
  54. </view>
  55. <view class="order-content">
  56. <view class="info-row">
  57. <span class="label">品种:</span>
  58. <span class="value">{{ order.materialName }}</span>
  59. </view>
  60. <view class="info-row">
  61. <span class="label">客户:</span>
  62. <span class="value">{{ order.companyName }}</span>
  63. </view>
  64. <view class="info-row">
  65. <span class="label">车号:</span>
  66. <span class="value">{{ order.vehicle }}</span>
  67. </view>
  68. <view class="info-row">
  69. <span class="label">装车数量:</span>
  70. <span class="value highlight">{{ order.number }}吨</span>
  71. </view>
  72. <view class="info-row">
  73. <span class="label">下单时间:</span>
  74. <span class="value">{{ order.setDate }}</span>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <Bars></Bars>
  81. <PopupSelect ref="popupLane" :option="laneOption" @onConfirm="onConfirm" />
  82. </view>
  83. </template>
  84. <script>
  85. import PopupSelect from '../../components/popup-select/index.vue'
  86. import Bars from '../../components/tabBar/tabBar.vue';
  87. import { getOrder,getLaneList } from '../../api/order'
  88. export default {
  89. components: {
  90. Bars,
  91. PopupSelect
  92. },
  93. data() {
  94. return {
  95. ws:null,
  96. wsUrl:'',
  97. currentData:{},
  98. orders:[],
  99. currentLane:{
  100. name:'',
  101. id:''
  102. },
  103. isConnect:false,
  104. laneOption:[],
  105. }
  106. },
  107. watch: {
  108. },
  109. computed: {
  110. },
  111. onShow() {
  112. this.getList()
  113. },
  114. onLoad(options) {
  115. uni.hideTabBar()
  116. this.getLaneList()
  117. // this.connectSocket()
  118. },
  119. beforeUnmount() {
  120. this.ws.close(); // 组件销毁前关闭连接
  121. },
  122. methods: {
  123. //连接车道ws
  124. connectSocket(){
  125. console.log(this.wsUrl);
  126. this.isConnect = false
  127. if(!this.wsUrl) return
  128. if(this.ws){
  129. this.ws.close(); // 组件销毁前关闭连接
  130. }
  131. // 创建 WebSocket 连接(替换为你的服务端地址)
  132. this.ws = new WebSocket(this.wsUrl);
  133. // 监听连接成功
  134. this.ws.onopen = () => {
  135. this.isConnect = true
  136. console.log('WebSocket 连接已建立');
  137. };
  138. // 监听消息接收
  139. this.ws.onmessage = (event) => {
  140. console.log('1111111111111111',event);
  141. this.currentData = JSON.parse(event.data)
  142. };
  143. // 监听错误
  144. this.ws.onerror = (error) => {
  145. console.error('WebSocket 错误:', error);
  146. };
  147. // 监听连接关闭
  148. this.ws.onclose = () => {
  149. console.log('WebSocket 连接已关闭');
  150. setTimeout(() => this.connectSocket(), 3000); // 3秒后重连
  151. };
  152. },
  153. //去新增订单
  154. toAdd(){
  155. uni.navigateTo({ url: `/pages/other/addOrder?name=${this.currentLane.name}&id=${this.currentLane.id}` })
  156. },
  157. //显示选择
  158. showPopup(refs) {
  159. this.$refs[refs].showPicker = true
  160. },
  161. //获取车道
  162. getLaneList(){
  163. getLaneList().then(res=>{
  164. if(res.statusCode === 200){
  165. this.laneOption = res.data.data.map(item=>{
  166. return {
  167. text:item.roadName,
  168. value:item.roadCode,
  169. ...item
  170. }
  171. })
  172. if(this.laneOption.length){
  173. this.currentLane.name = this.laneOption[0].text
  174. this.currentLane.id = this.laneOption[0].value
  175. this.wsUrl = this.laneOption[0].monitorAddress
  176. this.connectSocket()
  177. }
  178. }
  179. })
  180. },
  181. //获取包装任务
  182. getList(){
  183. let data = {
  184. }
  185. getOrder().then(res=>{
  186. if(res.statusCode === 200){
  187. this.orders = res.data.data.records
  188. }
  189. })
  190. },
  191. //车道确定
  192. onConfirm(value) {
  193. console.log(value);
  194. if (value.value && value.value !== this.currentLane.id) {
  195. this.currentLane.name = value.text
  196. this.currentLane.id = value.value
  197. this.wsUrl = value.monitorAddress
  198. this.connectSocket()
  199. }
  200. },
  201. }
  202. }
  203. </script>
  204. <style scope>
  205. /* #ifndef APP-NVUE */
  206. page {
  207. background-color: #f5f7fa;
  208. }
  209. /* #endif */
  210. </style>
  211. <style lang="scss" scoped>
  212. .main-sticky{
  213. padding: 24rpx;
  214. }
  215. .loading-status {
  216. padding: 32rpx;
  217. background-color: #f5f7fa;
  218. min-height: 100vh;
  219. }
  220. .data-panel {
  221. background: white;
  222. border-radius: 24rpx;
  223. padding: 32rpx;
  224. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.1);
  225. }
  226. .lane-selector {
  227. margin:-32rpx -32rpx 32rpx;
  228. }
  229. .lane-selector :deep(.el-select) {
  230. width: 100%;
  231. }
  232. .status-cards {
  233. display: grid;
  234. grid-template-columns: repeat(3, 1fr);
  235. gap: 24rpx;
  236. }
  237. .status-card {
  238. background: #f8f9fb;
  239. display: flex;
  240. flex-direction: column;
  241. border-radius: 16rpx;
  242. padding: 24rpx;
  243. text-align: center;
  244. }
  245. .status-card .label {
  246. font-size: 28rpx;
  247. color: #666;
  248. margin-bottom: 16rpx;
  249. }
  250. .status-card .value {
  251. font-size: 36rpx;
  252. font-weight: bold;
  253. color: #333;
  254. flex: 1;
  255. display:flex;
  256. align-items: center;
  257. justify-content: center;
  258. flex-direction: column;
  259. }
  260. .status-card .kind{
  261. font-size: 28rpx;
  262. }
  263. .status-card .value.highlight {
  264. color: #409eff;
  265. }
  266. .order-list {
  267. margin: 24rpx;
  268. }
  269. .section-title {
  270. display: flex;
  271. justify-content: space-between;
  272. align-items: center;
  273. font-size: 32rpx;
  274. font-weight: bold;
  275. margin-bottom: 24rpx;
  276. color: #333;
  277. }
  278. .order-cards {
  279. display: flex;
  280. flex-direction: column;
  281. gap: 12px;
  282. }
  283. .order-card {
  284. background: white;
  285. border-radius: 24rpx;
  286. padding: 32rpx;
  287. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.1);
  288. }
  289. .order-header {
  290. display: flex;
  291. justify-content: space-between;
  292. margin-bottom: 24rpx;
  293. padding-bottom: 16rpx;
  294. border-bottom: 1px solid #eee;
  295. }
  296. .order-header .lane {
  297. font-weight: bold;
  298. color: #409eff;
  299. }
  300. .order-header .time {
  301. color: #999;
  302. }
  303. .info-row {
  304. display: flex;
  305. margin-bottom: 16rpx;
  306. }
  307. .info-row .label {
  308. color: #666;
  309. width: 160rpx;
  310. }
  311. .info-row .value {
  312. color: #333;
  313. flex: 1;
  314. }
  315. .info-row .value.highlight {
  316. color: #409eff;
  317. font-weight: bold;
  318. }
  319. .lane-line{
  320. display: flex;
  321. gap: 20rpx;
  322. align-items: center;
  323. }
  324. .status_1{
  325. width: 32rpx;
  326. height: 32rpx;
  327. border-radius: 50%;
  328. background: #19be6b;
  329. }
  330. .status_0{
  331. width: 32rpx;
  332. height: 32rpx;
  333. border-radius: 50%;
  334. background: #fa3534;
  335. }
  336. </style>