index.vue 8.6 KB

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