device.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/d3ebb319-374c-43db-bd49-64e31c83f12e.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/bind',{
  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. uni.navigateTo({
  79. url:'/pagesMy/scanResult?deviceId='+res.data.data
  80. })
  81. })
  82. }
  83. }
  84. })
  85. },
  86. wifiBindDevice(){
  87. uni.navigateTo({
  88. url:'/pagesMy/deviceAdd'
  89. })
  90. },
  91. unbindSuccess(){
  92. this.getList();
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped lang="less">
  98. .page{
  99. background: #FFFFFF;
  100. padding: 0 21rpx 172rpx;
  101. box-sizing: border-box;
  102. .box{
  103. position: relative;
  104. width: calc(100% - 60rpx);
  105. background: #FFFFFF;
  106. box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(0,0,0,0.04);
  107. border-radius: 32rpx;
  108. border: 1rpx solid #D9F159;
  109. box-sizing: border-box;
  110. }
  111. .list{
  112. position: relative;
  113. ::v-deep .u-list{
  114. width: 100%;
  115. height: 100% !important;
  116. }
  117. ::v-deep .u-list-item{
  118. width: 100%;
  119. }
  120. .l_box{
  121. width: 100%;
  122. padding: 49rpx 30rpx 40rpx;
  123. margin-top: 20rpx;
  124. .l_top{
  125. .lt_l{
  126. font-family: PingFang-SC, PingFang-SC;
  127. font-weight: bold;
  128. font-size: 32rpx;
  129. color: #111111;
  130. line-height: 40rpx;
  131. }
  132. .lt_r{
  133. image{
  134. width: 42rpx;
  135. height: 42rpx;
  136. margin-right: 34rpx;
  137. }
  138. .ltr_zt{
  139. font-family: PingFangSC, PingFang SC;
  140. font-weight: 400;
  141. font-size: 26rpx;
  142. line-height: 37rpx;
  143. padding-left: 22rpx;
  144. position: relative;
  145. &::before{
  146. content: '';
  147. width: 12rpx;
  148. height: 12rpx;
  149. border-radius: 50%;
  150. position: absolute;
  151. left: 0;
  152. top: 50%;
  153. margin-top: -6rpx;
  154. }
  155. &.zx{
  156. color: #1B50FF;
  157. &::before{
  158. background: #1B50FF;
  159. }
  160. }
  161. &.lx{
  162. color: #C7C7C7;
  163. &::before{
  164. background: #C7C7C7;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. .l_content{
  171. border-top: 1rpx solid #E2E2E2;
  172. margin-top: 37rpx;
  173. padding-top: 36rpx;
  174. overflow: hidden;
  175. .lc_role{
  176. .lcr_l{
  177. width: 148rpx;
  178. height: 148rpx;
  179. border-radius: 50%;
  180. }
  181. .lcr_r{
  182. width: calc(100% - 148rpx);
  183. padding-left: 30rpx;
  184. box-sizing: border-box;
  185. p{
  186. font-family: PingFang-SC, PingFang-SC;
  187. font-weight: bold;
  188. font-size: 32rpx;
  189. color: #111111;
  190. line-height: 32rpx;
  191. overflow: hidden;
  192. white-space: nowrap;
  193. text-overflow: ellipsis;
  194. }
  195. .text{
  196. font-family: PingFangSC, PingFang SC;
  197. font-weight: 400;
  198. font-size: 24rpx;
  199. color: #7C8592;
  200. line-height: 24rpx;
  201. margin-top: 24rpx;
  202. }
  203. }
  204. }
  205. .lc_btns{
  206. margin-top: 62rpx;
  207. margin-left: -1rpx;
  208. overflow: hidden;
  209. .lcb_pre{
  210. width: calc(100% / 3);
  211. height: 37rpx;
  212. border-left: 1rpx solid #72832B;
  213. font-family: PingFang-SC, PingFang-SC;
  214. font-weight: bold;
  215. font-size: 26rpx;
  216. color: #72832B;
  217. line-height: 37rpx;
  218. text-align: center;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. .empty{
  225. image{
  226. width: 64rpx;
  227. height: 66rpx;
  228. }
  229. p{
  230. font-family: PingFangSC, PingFang SC;
  231. font-weight: 400;
  232. font-size: 30rpx;
  233. color: #A6A6A6;
  234. line-height: 42rpx;
  235. text-align: center;
  236. margin-top: 30rpx;
  237. }
  238. }
  239. .btns{
  240. width: calc(100% - 60rpx);
  241. position: fixed;
  242. left: 20rpx;
  243. bottom: 64rpx;
  244. .zt_btn{
  245. width: calc(50% - 15rpx);
  246. }
  247. }
  248. }
  249. </style>