index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view id="networkComponent">
  3. <view class="query-max-big-box">
  4. <view class="query-input-box">
  5. <input class="query-input" v-model="queryParams.searchValue"
  6. style="width:150rpx;" :maxlength="10"
  7. type="text" placeholder="输入名称" placeholder-style="color:#999;">
  8. </view>
  9. <view class="query-input-box">
  10. <picker @change="typeListChange" :value="typeListIndex" :range="typeList">
  11. <view style="width:130rpx;" class="query-input"
  12. :class="!typeName?'query-input-placeholder':''">
  13. {{typeName?typeName:'选择类型'}}
  14. </view>
  15. </picker>
  16. </view>
  17. <view class="query-button-one" @click="handleQuery">查询</view>
  18. <view class="query-button-two" @click="resetQuery">重置</view>
  19. <view class="query-button-three" @click="addButton">新增</view>
  20. </view>
  21. <view class="list-max-big-box">
  22. <view class="list-max-big-null" v-if="!dataList[0]">暂无数据</view>
  23. <view class="for-list-max-big-box" @click="clickButton(item)"
  24. v-for="(item,index) in dataList" :key="index">
  25. <view class="for-item-text-box">
  26. <view class="name-box">{{item.moduleName}}</view>
  27. <view class="num-box">
  28. {{item.moduleType==1?'HTTP服务':
  29. (item.moduleType==2?'TCP服务':
  30. (item.moduleType==3?'MQTT服务':
  31. (item.moduleType==4?'MQTT客户端':'')))}}
  32. </view>
  33. </view>
  34. <view class="for-text" v-if="item.publicIp&&item.publicPort">
  35. <view>本地地址:</view>
  36. <view>{{item.publicIp}}:{{item.publicPort}}</view>
  37. </view>
  38. <view class="for-text" v-if="item.localIp&&item.localPort">
  39. <view>公网地址:</view>
  40. <view>{{item.localIp}}:{{item.localPort}}</view>
  41. </view>
  42. <view class="for-text">
  43. <view>说明:</view>
  44. <view>{{item.remark}}</view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="pagination-max-big-box">
  49. <view class="pagination-button" @click="paginationButton(1)"
  50. :class="queryParams.page == 1 ? 'pagination-color':''">上一页</view>
  51. <view class="pagination-num">{{queryParams.page}}/{{pages}}</view>
  52. <view class="pagination-button" @click="paginationButton(2)"
  53. :class="queryParams.page == pages || queryParams.page > pages ? 'pagination-color':''">下一页</view>
  54. </view>
  55. <view class="info-positon-max-big-box" v-if="shadeType">
  56. <view class="info-positon-big-box">
  57. <view class="info-positon-title">详情</view>
  58. <view class="info-positon-box">
  59. <view class="info-positon-text-box">
  60. <view class="info-positon-one">名称:</view>
  61. <view class="info-positon-two">{{shadeData.moduleName}}</view>
  62. </view>
  63. <view class="info-positon-text-box">
  64. <view class="info-positon-one">类型:</view>
  65. <view class="info-positon-two">
  66. {{shadeData.moduleType==1?'HTTP服务':
  67. (shadeData.moduleType==2?'TCP服务':
  68. (shadeData.moduleType==3?'MQTT服务':
  69. (shadeData.moduleType==4?'MQTT客户端':'')))}}
  70. </view>
  71. </view>
  72. <view class="info-positon-text-box" v-if="shadeData.moduleType == 1 || shadeData.moduleType == 2 || shadeData.moduleType == 3">
  73. <view class="info-positon-one">本地地址:</view>
  74. <view class="info-positon-two">{{shadeData.localIp}}</view>
  75. </view>
  76. <view class="info-positon-text-box" v-if="shadeData.moduleType == 1 || shadeData.moduleType == 2 || shadeData.moduleType == 3">
  77. <view class="info-positon-one">本地端口:</view>
  78. <view class="info-positon-two">{{shadeData.localPort}}</view>
  79. </view>
  80. <view class="info-positon-text-box" v-if="shadeData.moduleType">
  81. <view class="info-positon-one">{{shadeData.moduleType==4?'远程地址':'公网地址'}}:</view>
  82. <view class="info-positon-two">{{shadeData.publicIp}}</view>
  83. </view>
  84. <view class="info-positon-text-box" v-if="shadeData.moduleType">
  85. <view class="info-positon-one">{{shadeData.moduleType==4?'远程端口':'公网端口'}}:</view>
  86. <view class="info-positon-two">{{shadeData.publicPort}}</view>
  87. </view>
  88. <view class="info-positon-text-box" v-if="shadeData.moduleType == 1 || shadeData.moduleType == 4">
  89. <view class="info-positon-one">{{shadeData.moduleType==4?'用户名:':'认证key:'}}:</view>
  90. <view class="info-positon-two">{{shadeData.authKey}}</view>
  91. </view>
  92. <view class="info-positon-text-box" v-if="shadeData.moduleType == 1 || shadeData.moduleType == 4">
  93. <view class="info-positon-one">{{shadeData.moduleType==4?'密码:':'密匙:'}}:</view>
  94. <view class="info-positon-two">{{shadeData.authPassword}}</view>
  95. </view>
  96. <view class="info-positon-text-box" v-if="shadeData.moduleType==2">
  97. <view class="info-positon-one">粘拆包:</view>
  98. <view class="info-positon-two">
  99. {{shadeData.dataPacket==0?'不处理':
  100. (shadeData.dataPacket==1?'分隔符':
  101. (shadeData.dataPacket==2?'自定义脚本':
  102. (shadeData.dataPacket==3?'固定长度':
  103. (shadeData.dataPacket==4?'长度字段':''))))}}
  104. </view>
  105. </view>
  106. <view class="info-positon-text-box" v-if="shadeData.moduleType==2 && shadeData.dataPacket!==0">
  107. <view class="info-positon-one">粘拆包字符:</view>
  108. <view class="info-positon-two">{{shadeData.dataPacketContent}}</view>
  109. </view>
  110. <view class="info-positon-text-box" v-if="shadeData.moduleType==4">
  111. <view class="info-positon-one">订阅前缀:</view>
  112. <view class="info-positon-two">{{shadeData.prefix}}</view>
  113. </view>
  114. <view class="info-positon-text-box" v-if="shadeData.moduleType==3 || shadeData.moduleType==4">
  115. <view class="info-positon-one">消息长度:</view>
  116. <view class="info-positon-two">{{shadeData.messageLength}}</view>
  117. </view>
  118. <view class="info-positon-text-box" v-if="shadeData.params[0]">
  119. <view class="info-positon-one">自定义参数:</view>
  120. <view class="info-positon-three" v-for="(item,index) in shadeData.params">
  121. <view>key:{{item.key}}</view>
  122. <view>value:{{item.value}}</view>
  123. </view>
  124. </view>
  125. <view class="info-positon-text-box">
  126. <view class="info-positon-one">说明:</view>
  127. <view class="info-positon-two">{{ shadeData.remark }}</view>
  128. </view>
  129. </view>
  130. <view class="info-positon-button-box">
  131. <view @click="shadeOff">关闭</view>
  132. </view>
  133. </view>
  134. </view>
  135. </view>
  136. </template>
  137. <script>
  138. import { itoNetworkList,itoNetworkDelete } from '@/api/index.js'
  139. export default {
  140. data() {
  141. return {
  142. //分类下拉列表
  143. typeDataList:[
  144. {name:'HTTP服务',value:1},
  145. {name:'TCP服务',value:2},
  146. {name:'MQTT服务',value:3},
  147. {name:'MQTT客户端',value:4}
  148. ],
  149. typeList:['HTTP服务','TCP服务','MQTT服务','MQTT客户端'],
  150. typeListIndex:0,
  151. typeName:'',
  152. //列表数据
  153. dataList:[],
  154. pages:0,
  155. queryParams:{
  156. page:1,
  157. pageSize:10,
  158. searchValue:'',
  159. moduleType:'',
  160. },
  161. //弹窗相关
  162. shadeType:false,
  163. shadeData:{},
  164. }
  165. },
  166. onLoad(option) {
  167. },
  168. onShow(){
  169. this.getList();
  170. },
  171. methods: {
  172. //新增
  173. addButton(){
  174. uni.navigateTo({
  175. url: '/pages/networkComponent/addPage',
  176. });
  177. },
  178. //关闭弹窗
  179. shadeOff(){
  180. this.$set(this,'shadeType',false);
  181. this.$set(this,'shadeData',{});
  182. },
  183. //选中分类
  184. typeListChange(event){
  185. this.$set(this,'typeListIndex',event.target.value);
  186. this.$set(this,'typeName',this.typeDataList[event.target.value].name);
  187. this.$set(this.queryParams,'moduleType',this.typeDataList[event.target.value].value);
  188. },
  189. //查询按钮
  190. handleQuery(){
  191. this.$set(this.queryParams,'page',1);
  192. this.getList();
  193. },
  194. //重置按钮
  195. resetQuery(){
  196. this.$set(this,'typeListIndex',0);
  197. this.$set(this,'typeName','');
  198. this.$set(this,'queryParams',{
  199. page:1,
  200. pageSize:10,
  201. searchValue:'',
  202. moduleType:'',
  203. });
  204. this.getList();
  205. },
  206. //翻页
  207. paginationButton(type){
  208. if(type == 1){
  209. if(this.queryParams.page != 1){
  210. this.queryParams.page--
  211. this.getList();
  212. }
  213. }else if(type == 2){
  214. if(this.queryParams.page != this.pages && this.queryParams.page < this.pages){
  215. this.queryParams.page++
  216. this.getList();
  217. }
  218. }
  219. },
  220. //消息列表
  221. async getList(){
  222. const {data} = await itoNetworkList(this.queryParams);
  223. if(data.code==200){
  224. this.$set(this,'pages',data.data.pages);
  225. this.$set(this,'dataList',data.data.records);
  226. }
  227. },
  228. //点击事件
  229. clickButton(item){
  230. let self = this;
  231. uni.showActionSheet({
  232. itemList: ['详情','编辑','删除'],
  233. success (res) {
  234. if(res.tapIndex == 0){
  235. //详情
  236. let newData = JSON.parse(JSON.stringify(item));
  237. if(newData.params){
  238. let obj = newData.params?JSON.parse(newData.params):{};
  239. let list = [];
  240. Object.keys(obj).forEach((key)=>{
  241. const value = obj[key];
  242. list.push({
  243. key:key,
  244. value:value
  245. })
  246. })
  247. newData.params = list[0]?list:[];
  248. }else{
  249. newData.params = [];
  250. }
  251. self.$set(self,'shadeData',newData);
  252. self.$set(self,'shadeType',true);
  253. }if(res.tapIndex == 1){
  254. //编辑
  255. uni.navigateTo({
  256. url:'/pages/networkComponent/addPage?item='+encodeURIComponent(JSON.stringify(item))
  257. });
  258. }else if(res.tapIndex == 2){
  259. //删除
  260. uni.showModal({
  261. title:'警告',
  262. content:'是否确认删除"'+item.moduleName+'"',
  263. showCancel: true,
  264. cancelColor:'#999999,',
  265. confirmColor: '#FF6666',
  266. success: (res) => {
  267. if(res.confirm){
  268. self.itoNetworkDelete(item);
  269. }
  270. },
  271. fail: (res) => {}
  272. })
  273. }
  274. },
  275. fail (res) {
  276. }
  277. });
  278. },
  279. //删除
  280. async itoNetworkDelete(item){
  281. let self = this;
  282. const {data} = await itoNetworkDelete({id:item.id});
  283. if(data.code==200){
  284. uni.showToast({
  285. mask: true,
  286. icon: "none",
  287. position: "center",
  288. title: data.message,
  289. duration: 2000
  290. });
  291. setTimeout(function(){
  292. self.resetQuery();
  293. },1800);
  294. }
  295. },
  296. },
  297. }
  298. </script>
  299. <style lang="stylus" scoped>
  300. #networkComponent{
  301. flex:1;
  302. display: flex;
  303. flex-direction: column;
  304. overflow: hidden;
  305. .query-max-big-box{
  306. height:80rpx;
  307. background-color: #fff;
  308. display: flex;
  309. font-size:28rpx;
  310. .query-input-box{
  311. display: flex;
  312. margin:10rpx 0 0 10rpx;
  313. .query-input{
  314. padding:0 20rpx;
  315. height:60rpx;
  316. line-height:60rpx;
  317. font-size:26rpx;
  318. border-radius:8rpx;
  319. border:1px solid #dedede;
  320. }
  321. .query-input-placeholder{
  322. color: #999 !important;
  323. }
  324. }
  325. .query-button-one{
  326. margin:10rpx 0 0 10rpx;
  327. background-color: #0183FA;
  328. color:#fff;
  329. border-radius:8rpx;
  330. width:110rpx;
  331. height:62rpx;
  332. line-height:62rpx;
  333. text-align: center;
  334. font-size:28rpx;
  335. }
  336. .query-button-two{
  337. margin:10rpx;
  338. background-color: #999;
  339. color:#fff;
  340. border-radius:8rpx;
  341. width:110rpx;
  342. height:62rpx;
  343. line-height:62rpx;
  344. text-align: center;
  345. font-size:28rpx;
  346. }
  347. .query-button-three{
  348. margin:10rpx 10rpx 0 0;
  349. background-color: #409EFF;
  350. color:#fff;
  351. border-radius:8rpx;
  352. width:110rpx;
  353. height:62rpx;
  354. line-height:62rpx;
  355. text-align: center;
  356. font-size:28rpx;
  357. }
  358. }
  359. .list-max-big-box{
  360. flex:1;
  361. overflow-x: hidden;
  362. overflow-y: scroll;
  363. margin:20rpx;
  364. .list-max-big-null{
  365. font-size:28rpx;
  366. text-align:center;
  367. line-height:100rpx;
  368. color:#999;
  369. }
  370. .for-list-max-big-box{
  371. background-color: #fff;
  372. color:#333;
  373. font-size:28rpx;
  374. margin-bottom:20rpx;
  375. padding:20rpx;
  376. border-radius:16rpx;
  377. .for-item-text-box{
  378. display: flex;
  379. .name-box{
  380. flex:1;
  381. line-height:50rpx;
  382. display:block;
  383. overflow:hidden;
  384. text-overflow:ellipsis;
  385. white-space:nowrap;
  386. }
  387. .num-box{
  388. text-align: center;
  389. width:200rpx;
  390. line-height:50rpx;
  391. }
  392. .colorA{
  393. color:#14AE10;
  394. }
  395. .colorB{
  396. color:#FF6666;
  397. }
  398. }
  399. .for-text{
  400. display: flex;
  401. view{
  402. font-size:28rpx;
  403. line-height:50rpx;
  404. }
  405. view:nth-child(1){
  406. width:160rpx;
  407. }
  408. view:nth-child(2){
  409. width:590rpx;
  410. font-size:28rpx;
  411. line-height:40rpx;
  412. padding:5rpx 0;
  413. word-wrap: break-word;
  414. }
  415. }
  416. }
  417. }
  418. .pagination-max-big-box{
  419. height:80rpx;
  420. background-color: #fff;
  421. display: flex;
  422. .pagination-button{
  423. margin:10rpx;
  424. border-radius:8rpx;
  425. width:140rpx;
  426. height:60rpx;
  427. line-height:60rpx;
  428. text-align: center;
  429. font-size:28rpx;
  430. background-color:#0183FA;
  431. color:#fff;
  432. }
  433. .pagination-num{
  434. flex:1;
  435. text-align: center;
  436. line-height:80rpx;
  437. }
  438. .pagination-color{
  439. background-color: #dedede;
  440. }
  441. }
  442. .info-positon-max-big-box{
  443. z-index:100;
  444. position: absolute;
  445. bottom:0;
  446. left:0;
  447. width:100%;
  448. height:100%;
  449. background-color: rgba(0,0,0,0.6);
  450. .info-positon-big-box{
  451. width:80%;
  452. height:80%;
  453. margin-left:10%;
  454. margin-top:10%;
  455. border-radius:16rpx;
  456. display: flex;
  457. flex-direction:column;
  458. overflow: hidden;
  459. background-color: #fff;
  460. .info-positon-title{
  461. height:80rpx;
  462. line-height:80rpx;
  463. text-align: center;
  464. font-size:32rpx;
  465. border-bottom:1px solid #dedede;
  466. }
  467. .info-positon-box{
  468. flex:1;
  469. overflow-x: hidden;
  470. overflow-y: scroll;
  471. .info-positon-text-box{
  472. .info-positon-one{
  473. padding:0 20rpx;
  474. font-size:28rpx;
  475. line-height:60rpx;
  476. background-color: #dedede
  477. }
  478. .info-positon-two{
  479. padding:10rpx 40rpx;
  480. word-wrap: break-word;
  481. line-height:30rpx;
  482. font-size:28rpx;
  483. }
  484. .info-positon-three{
  485. padding:10rpx 40rpx;
  486. border-bottom:1px solid #dedede;
  487. view{
  488. word-wrap: break-word;
  489. line-height:40rpx;
  490. font-size:28rpx;
  491. }
  492. }
  493. }
  494. }
  495. .info-positon-button-box{
  496. border-top:1px solid #dedede;
  497. view{
  498. background-color: #999;
  499. color:#fff;
  500. text-align: center;
  501. line-height:60rpx;
  502. height:60rpx;
  503. font-size:28rpx;
  504. width:160rpx;
  505. margin:10rpx auto;
  506. border-radius:12rpx;
  507. }
  508. }
  509. }
  510. }
  511. }
  512. </style>