index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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.notifyStartDiscoverBle({
  84. 'isStart': false
  85. })
  86. xBlufi.notifyConnectBle({
  87. isStart: false,
  88. deviceId: item.id,
  89. });
  90. xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
  91. this.connectedId = item.id;
  92. console.log(this.connectedId, 'this.connectedId');
  93. const ready = await this.ensureBtReady();
  94. console.log(ready, 'ready');
  95. if (!ready) return;
  96. await this.closeBluetooth();
  97. setTimeout(() => {
  98. this.$emit('unbindSuccess');
  99. }, 1000);
  100. });
  101. }
  102. }
  103. });
  104. },
  105. ensureBtReady() {
  106. return new Promise((resolve) => {
  107. uni.openBluetoothAdapter({
  108. success: () => {
  109. this.isBluetoothOpen = true;
  110. resolve(true);
  111. },
  112. fail: (err) => {
  113. // 已初始化时不算错误
  114. if (err.errMsg && err.errMsg.includes('already opened')) {
  115. this.isBluetoothOpen = true;
  116. resolve(true);
  117. return;
  118. }
  119. if (err.errMsg && err.errMsg.includes('fail')) {
  120. this.$showModal('请先到系统设置中打开蓝牙');
  121. }
  122. resolve(false);
  123. }
  124. });
  125. });
  126. },
  127. closeBluetooth() {
  128. // 2.1 断开设备
  129. if (this.connectedId) {
  130. console.log('断开连接', this.connectedId);
  131. uni.closeBLEConnection({
  132. deviceId: this.connectedId,
  133. success: () => {
  134. console.log('断开连接成功');
  135. },
  136. fail: (err) => {
  137. console.log('断开连接失败',err);
  138. }
  139. });
  140. this.connectedId = '';
  141. }
  142. // 2.2 关闭适配器
  143. if (this.isBluetoothOpen) {
  144. uni.closeBluetoothAdapter({
  145. success: () => {
  146. console.log('关闭蓝牙适配器成功');
  147. },
  148. fail: (err) => {
  149. console.log('关闭适配器',err)
  150. }
  151. });
  152. this.isBluetoothOpen = false;
  153. }
  154. },
  155. funListenDeviceMsgEvent: function (options) {
  156. let that = this;
  157. switch (options.type) {
  158. case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
  159. that.connected = options.result;
  160. if (!options.result) {
  161. console.log(options, 'options:关闭蓝牙');
  162. }
  163. break;
  164. }
  165. }
  166. }
  167. };
  168. </script>
  169. <style scoped lang="less">
  170. .box {
  171. position: relative;
  172. width: calc(100% - 60rpx);
  173. background: #ffffff;
  174. box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(0, 0, 0, 0.04);
  175. border-radius: 32rpx;
  176. border: 1rpx solid #d9f159;
  177. box-sizing: border-box;
  178. }
  179. .l_box {
  180. width: 100%;
  181. padding: 49rpx 30rpx 40rpx;
  182. margin-top: 20rpx;
  183. .l_top {
  184. .lt_l {
  185. font-family: PingFang-SC, PingFang-SC;
  186. font-weight: bold;
  187. font-size: 32rpx;
  188. color: #111111;
  189. line-height: 40rpx;
  190. }
  191. .lt_r {
  192. image {
  193. width: 42rpx;
  194. height: 42rpx;
  195. margin-right: 34rpx;
  196. }
  197. .ltr_zt {
  198. font-family: PingFangSC, PingFang SC;
  199. font-weight: 400;
  200. font-size: 26rpx;
  201. line-height: 37rpx;
  202. padding-left: 22rpx;
  203. position: relative;
  204. &::before {
  205. content: '';
  206. width: 12rpx;
  207. height: 12rpx;
  208. border-radius: 50%;
  209. position: absolute;
  210. left: 0;
  211. top: 50%;
  212. margin-top: -6rpx;
  213. }
  214. &.zx {
  215. color: #1b50ff;
  216. &::before {
  217. background: #1b50ff;
  218. }
  219. }
  220. &.lx {
  221. color: #c7c7c7;
  222. &::before {
  223. background: #c7c7c7;
  224. }
  225. }
  226. }
  227. }
  228. }
  229. .l_content {
  230. border-top: 1rpx solid #e2e2e2;
  231. margin-top: 37rpx;
  232. padding-top: 36rpx;
  233. overflow: hidden;
  234. .lc_role {
  235. .lcr_l {
  236. width: 148rpx;
  237. height: 148rpx;
  238. border-radius: 50%;
  239. }
  240. .lcr_r {
  241. width: calc(100% - 148rpx);
  242. padding-left: 30rpx;
  243. box-sizing: border-box;
  244. p {
  245. font-family: PingFang-SC, PingFang-SC;
  246. font-weight: bold;
  247. font-size: 32rpx;
  248. color: #111111;
  249. line-height: 32rpx;
  250. overflow: hidden;
  251. white-space: nowrap;
  252. text-overflow: ellipsis;
  253. }
  254. .text {
  255. font-family: PingFangSC, PingFang SC;
  256. font-weight: 400;
  257. font-size: 24rpx;
  258. color: #7c8592;
  259. line-height: 24rpx;
  260. margin-top: 24rpx;
  261. }
  262. }
  263. }
  264. .lc_info {
  265. margin-top: 36rpx;
  266. font-family: PingFangSC, PingFang SC;
  267. font-weight: 400;
  268. font-size: 24rpx;
  269. color: #7c8592;
  270. line-height: 40rpx;
  271. }
  272. .lc_btns {
  273. margin-top: 62rpx;
  274. margin-left: -1rpx;
  275. overflow: hidden;
  276. .lcb_pre {
  277. width: calc(100% / 3);
  278. height: 37rpx;
  279. border-left: 1rpx solid #72832b;
  280. font-family: PingFang-SC, PingFang-SC;
  281. font-weight: bold;
  282. font-size: 26rpx;
  283. color: #72832b;
  284. line-height: 37rpx;
  285. text-align: center;
  286. }
  287. }
  288. }
  289. }
  290. </style>