index.vue 8.4 KB

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