index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div class="l_box box">
  3. <div class="l_top adfacjb">
  4. <!-- <div class="lt_l">{{item.alias||item.board||''}}</div> -->
  5. <div class="lt_l">{{ item.id || '' }}</div>
  6. <div class="lt_r adfac">
  7. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/8a203ba4-2e9e-4379-89ec-dc7fc9caa3d4.png" v-if="item.state === 1"></image>
  8. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/5ed3a1fc-9a05-4f13-8449-fd3183b00355.png" v-else-if="item.state === 0"></image>
  9. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/c6d13477-ae1d-4f52-b835-3411a57fc4d7.png" v-if="item.state === 1"></image>
  10. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/e26bd236-46db-4283-a1f7-9dd3b4f8ef33.png" v-else-if="item.state === 0"></image>
  11. <div class="ltr_zt" :class="{ zx: item.state === 1, lx: item.state === 0 }">{{ item.state === 1 ? '在线' : '离线' }}</div>
  12. </div>
  13. </div>
  14. <div class="l_content">
  15. <div class="lc_role adfac">
  16. <image class="lcr_l" :src="item.agent.avatar || 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/b755d53e-c307-4a59-ac2a-2690c326f980.png'"></image>
  17. <div class="lcr_r">
  18. <p>{{ item.agent.agentName || '' }}</p>
  19. <div class="text">角色模板:{{ item.roleModelName || '' }}</div>
  20. <div class="text">绑定时间:{{ item.createDate || '' }}</div>
  21. </div>
  22. </div>
  23. <div class="lc_info" v-if="showInfo">
  24. <u--text :lines="3" :text="item.agent.systemPrompt || ''" size="24rpx" color="#7C8592" lineHeight="40rpx"></u--text>
  25. </div>
  26. <div class="lc_btns adfac">
  27. <!-- <div class="lcb_pre" @tap="editRole(item)">角色编辑</div> -->
  28. <div class="lcb_pre" @tap="dislogRecord(item)">对话记录</div>
  29. <div class="lcb_pre" @tap="changeWifi(item)">配置网络</div>
  30. <div class="lcb_pre" @tap="unbindDevice(item)">解绑设备</div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. var xBlufi = require('@/utils/blufi/xBlufi.js');
  37. export default {
  38. props: {
  39. item: {
  40. typeof: Object
  41. },
  42. showInfo: {
  43. typeof: Boolean,
  44. default: false
  45. }
  46. },
  47. data() {
  48. return {
  49. isBluetoothOpen: false,
  50. connectedId: '',
  51. };
  52. },
  53. methods: {
  54. dislogRecord(item) {
  55. uni.navigateTo({
  56. url: `/pagesHome/dialogRecord?agentId=${item.agentId}&deviceId=${item.id}`
  57. });
  58. },
  59. editRole(item) {
  60. this.$emit('editRole');
  61. uni.navigateTo({
  62. url: `/pagesRole/addRole?agentId=${item.agentId}&deviceId=${item.id}`
  63. });
  64. },
  65. changeWifi(item) {
  66. uni.navigateTo({
  67. url: '/pagesMy/wifiSearch'
  68. });
  69. },
  70. unbindDevice(item) {
  71. uni.showModal({
  72. title: '温馨提示',
  73. content: '确定要解绑该设备吗?',
  74. success: (res) => {
  75. if (res.confirm) {
  76. this.$api
  77. .post('/device/unbind', {
  78. deviceId: item.id
  79. })
  80. .then(async (res) => {
  81. if (res.data.code !== 0) return this.$showToast(res.data.msg);
  82. this.$showToast('解绑成功');
  83. xBlufi.notifyConnectBle({
  84. isStart: false,
  85. deviceId: item.id,
  86. });
  87. xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
  88. this.connectedId = item.id;
  89. console.log(this.connectedId, 'this.connectedId');
  90. const ready = await this.ensureBtReady();
  91. console.log(ready, 'ready');
  92. if (!ready) return;
  93. await this.closeBluetooth();
  94. setTimeout(() => {
  95. this.$emit('unbindSuccess');
  96. }, 1000);
  97. });
  98. }
  99. }
  100. });
  101. },
  102. ensureBtReady() {
  103. return new Promise((resolve) => {
  104. uni.openBluetoothAdapter({
  105. success: () => {
  106. this.isBluetoothOpen = true;
  107. resolve(true);
  108. },
  109. fail: (err) => {
  110. // 已初始化时不算错误
  111. if (err.errMsg && err.errMsg.includes('already opened')) {
  112. this.isBluetoothOpen = true;
  113. resolve(true);
  114. return;
  115. }
  116. if (err.errMsg && err.errMsg.includes('fail')) {
  117. this.$showModal('请先到系统设置中打开蓝牙');
  118. }
  119. resolve(false);
  120. }
  121. });
  122. });
  123. },
  124. closeBluetooth() {
  125. // 2.1 断开设备
  126. if (this.connectedId) {
  127. uni.closeBLEConnection({
  128. deviceId: this.connectedId,
  129. success: () => {
  130. console.log('断开连接成功');
  131. },
  132. fail: () => {
  133. /* 已断开或其它异常不用提示 */
  134. }
  135. });
  136. this.connectedId = '';
  137. }
  138. // 2.2 关闭适配器
  139. if (this.isBluetoothOpen) {
  140. uni.closeBluetoothAdapter({
  141. success: () => {
  142. console.log('关闭蓝牙适配器成功');
  143. },
  144. fail: () => {
  145. /* 同样可吞掉 */
  146. }
  147. });
  148. this.isBluetoothOpen = false;
  149. }
  150. },
  151. funListenDeviceMsgEvent: function (options) {
  152. let that = this;
  153. switch (options.type) {
  154. case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
  155. that.connected = options.result;
  156. if (!options.result) {
  157. console.log(options, 'options:关闭蓝牙');
  158. }
  159. break;
  160. }
  161. }
  162. }
  163. };
  164. </script>
  165. <style scoped lang="less">
  166. .box {
  167. position: relative;
  168. width: calc(100% - 60rpx);
  169. background: #ffffff;
  170. box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(0, 0, 0, 0.04);
  171. border-radius: 32rpx;
  172. border: 1rpx solid #d9f159;
  173. box-sizing: border-box;
  174. }
  175. .l_box {
  176. width: 100%;
  177. padding: 49rpx 30rpx 40rpx;
  178. margin-top: 20rpx;
  179. .l_top {
  180. .lt_l {
  181. font-family: PingFang-SC, PingFang-SC;
  182. font-weight: bold;
  183. font-size: 32rpx;
  184. color: #111111;
  185. line-height: 40rpx;
  186. }
  187. .lt_r {
  188. image {
  189. width: 42rpx;
  190. height: 42rpx;
  191. margin-right: 34rpx;
  192. }
  193. .ltr_zt {
  194. font-family: PingFangSC, PingFang SC;
  195. font-weight: 400;
  196. font-size: 26rpx;
  197. line-height: 37rpx;
  198. padding-left: 22rpx;
  199. position: relative;
  200. &::before {
  201. content: '';
  202. width: 12rpx;
  203. height: 12rpx;
  204. border-radius: 50%;
  205. position: absolute;
  206. left: 0;
  207. top: 50%;
  208. margin-top: -6rpx;
  209. }
  210. &.zx {
  211. color: #1b50ff;
  212. &::before {
  213. background: #1b50ff;
  214. }
  215. }
  216. &.lx {
  217. color: #c7c7c7;
  218. &::before {
  219. background: #c7c7c7;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. .l_content {
  226. border-top: 1rpx solid #e2e2e2;
  227. margin-top: 37rpx;
  228. padding-top: 36rpx;
  229. overflow: hidden;
  230. .lc_role {
  231. .lcr_l {
  232. width: 148rpx;
  233. height: 148rpx;
  234. border-radius: 50%;
  235. }
  236. .lcr_r {
  237. width: calc(100% - 148rpx);
  238. padding-left: 30rpx;
  239. box-sizing: border-box;
  240. p {
  241. font-family: PingFang-SC, PingFang-SC;
  242. font-weight: bold;
  243. font-size: 32rpx;
  244. color: #111111;
  245. line-height: 32rpx;
  246. overflow: hidden;
  247. white-space: nowrap;
  248. text-overflow: ellipsis;
  249. }
  250. .text {
  251. font-family: PingFangSC, PingFang SC;
  252. font-weight: 400;
  253. font-size: 24rpx;
  254. color: #7c8592;
  255. line-height: 24rpx;
  256. margin-top: 24rpx;
  257. }
  258. }
  259. }
  260. .lc_info {
  261. margin-top: 36rpx;
  262. font-family: PingFangSC, PingFang SC;
  263. font-weight: 400;
  264. font-size: 24rpx;
  265. color: #7c8592;
  266. line-height: 40rpx;
  267. }
  268. .lc_btns {
  269. margin-top: 62rpx;
  270. margin-left: -1rpx;
  271. overflow: hidden;
  272. .lcb_pre {
  273. width: calc(100% / 3);
  274. height: 37rpx;
  275. border-left: 1rpx solid #72832b;
  276. font-family: PingFang-SC, PingFang-SC;
  277. font-weight: bold;
  278. font-size: 26rpx;
  279. color: #72832b;
  280. line-height: 37rpx;
  281. text-align: center;
  282. }
  283. }
  284. }
  285. }
  286. </style>