device.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='设备管理'></cus-header>
  4. <template v-if="list.length">
  5. <div class="list" :style="{'height':'calc(100vh - '+(mt+100)+'px)'}">
  6. <u-list>
  7. <u-list-item v-for="(item, index) in list" :key="index">
  8. <device-box :item="item" @unbindSuccess="unbindSuccess"></device-box>
  9. </u-list-item>
  10. </u-list>
  11. </div>
  12. </template>
  13. <template v-else>
  14. <div class="empty adffcacjc" :style="{'height':'calc(100vh - '+(mt+100)+'px)'}">
  15. <image src="http://106.54.209.120:8188/static/empty_device.png"></image>
  16. <p>暂无绑定设备</p>
  17. </div>
  18. </template>
  19. <div class="btns adfacjb">
  20. <div class="zt_btn" @tap="scanBindDevice">扫码绑定设备</div>
  21. <div class="zt_btn" @tap="wifiBindDevice">配网并绑定设备</div>
  22. </div>
  23. </view>
  24. </template>
  25. <script>
  26. import deviceBox from '@/components/deviceBox/index.vue'
  27. export default {
  28. components:{
  29. deviceBox
  30. },
  31. data(){
  32. return {
  33. list:[]
  34. }
  35. },
  36. async onShow() {
  37. await this.getAgentModelList()
  38. this.getList();
  39. },
  40. methods:{
  41. getAgentModelList(){
  42. return new Promise((resolve,reject)=>{
  43. this.$api.get('/agent/template').then(res=>{
  44. if(res.data.code!==0) return this.$showToast(res.data.msg)
  45. if(res.data.data.length){
  46. let map = new Map();
  47. res.data.data.forEach(l=>{
  48. map.set(l.systemPrompt,l)
  49. })
  50. this.modelMap = map;
  51. }
  52. resolve()
  53. })
  54. })
  55. },
  56. getList(){
  57. this.$api.get(`/device/bind/${null}`).then(res=>{
  58. if(res.data.code!==0) return this.$showToast(res.data.msg)
  59. this.list = res.data.data;
  60. this.list.forEach(l=>{
  61. l.roleModelName = this.modelMap.get(l.agent.systemPrompt).agentName;
  62. })
  63. })
  64. },
  65. scanBindDevice(){
  66. let that = this;
  67. uni.scanCode({
  68. success: (res) => {
  69. let result = JSON.parse(res.result);
  70. if(res.errMsg==='scanCode:ok'){
  71. that.$api.post('/device/bindAdd',{
  72. ...result,
  73. "type": "",
  74. "userId": 0,
  75. "agentId": ""
  76. }).then(res=>{
  77. if(res.data.code!==0) return that.$showToast(res.data.msg)
  78. that.$showToast('绑定成功')
  79. setTimeout(()=>{
  80. this.getList();
  81. },1500)
  82. })
  83. }
  84. }
  85. })
  86. },
  87. wifiBindDevice(){
  88. uni.navigateTo({
  89. url:'/pagesMy/deviceAdd'
  90. })
  91. },
  92. unbindSuccess(){
  93. this.getList();
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped lang="less">
  99. .page{
  100. background: #FFFFFF;
  101. padding: 0 21rpx 172rpx;
  102. box-sizing: border-box;
  103. .box{
  104. position: relative;
  105. width: calc(100% - 60rpx);
  106. background: #FFFFFF;
  107. box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(0,0,0,0.04);
  108. border-radius: 32rpx;
  109. border: 1rpx solid #D9F159;
  110. box-sizing: border-box;
  111. }
  112. .list{
  113. position: relative;
  114. ::v-deep .u-list{
  115. width: 100%;
  116. height: 100% !important;
  117. }
  118. ::v-deep .u-list-item{
  119. width: 100%;
  120. }
  121. .l_box{
  122. width: 100%;
  123. padding: 49rpx 30rpx 40rpx;
  124. margin-top: 20rpx;
  125. .l_top{
  126. .lt_l{
  127. font-family: PingFang-SC, PingFang-SC;
  128. font-weight: bold;
  129. font-size: 32rpx;
  130. color: #111111;
  131. line-height: 40rpx;
  132. }
  133. .lt_r{
  134. image{
  135. width: 42rpx;
  136. height: 42rpx;
  137. margin-right: 34rpx;
  138. }
  139. .ltr_zt{
  140. font-family: PingFangSC, PingFang SC;
  141. font-weight: 400;
  142. font-size: 26rpx;
  143. line-height: 37rpx;
  144. padding-left: 22rpx;
  145. position: relative;
  146. &::before{
  147. content: '';
  148. width: 12rpx;
  149. height: 12rpx;
  150. border-radius: 50%;
  151. position: absolute;
  152. left: 0;
  153. top: 50%;
  154. margin-top: -6rpx;
  155. }
  156. &.zx{
  157. color: #1B50FF;
  158. &::before{
  159. background: #1B50FF;
  160. }
  161. }
  162. &.lx{
  163. color: #C7C7C7;
  164. &::before{
  165. background: #C7C7C7;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. .l_content{
  172. border-top: 1rpx solid #E2E2E2;
  173. margin-top: 37rpx;
  174. padding-top: 36rpx;
  175. overflow: hidden;
  176. .lc_role{
  177. .lcr_l{
  178. width: 148rpx;
  179. height: 148rpx;
  180. border-radius: 50%;
  181. }
  182. .lcr_r{
  183. width: calc(100% - 148rpx);
  184. padding-left: 30rpx;
  185. box-sizing: border-box;
  186. p{
  187. font-family: PingFang-SC, PingFang-SC;
  188. font-weight: bold;
  189. font-size: 32rpx;
  190. color: #111111;
  191. line-height: 32rpx;
  192. overflow: hidden;
  193. white-space: nowrap;
  194. text-overflow: ellipsis;
  195. }
  196. .text{
  197. font-family: PingFangSC, PingFang SC;
  198. font-weight: 400;
  199. font-size: 24rpx;
  200. color: #7C8592;
  201. line-height: 24rpx;
  202. margin-top: 24rpx;
  203. }
  204. }
  205. }
  206. .lc_btns{
  207. margin-top: 62rpx;
  208. margin-left: -1rpx;
  209. overflow: hidden;
  210. .lcb_pre{
  211. width: calc(100% / 3);
  212. height: 37rpx;
  213. border-left: 1rpx solid #72832B;
  214. font-family: PingFang-SC, PingFang-SC;
  215. font-weight: bold;
  216. font-size: 26rpx;
  217. color: #72832B;
  218. line-height: 37rpx;
  219. text-align: center;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. .empty{
  226. image{
  227. width: 64rpx;
  228. height: 66rpx;
  229. }
  230. p{
  231. font-family: PingFangSC, PingFang SC;
  232. font-weight: 400;
  233. font-size: 30rpx;
  234. color: #A6A6A6;
  235. line-height: 42rpx;
  236. text-align: center;
  237. margin-top: 30rpx;
  238. }
  239. }
  240. .btns{
  241. width: calc(100% - 60rpx);
  242. position: fixed;
  243. left: 20rpx;
  244. bottom: 64rpx;
  245. .zt_btn{
  246. width: calc(50% - 15rpx);
  247. }
  248. }
  249. }
  250. </style>