role.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="tabPage" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='角色' :showback="false" bgColor='transparent'></cus-header>
  4. <div class="query adfacjb">
  5. <div class="ql adfac">
  6. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/cecb5744-d3be-4f61-a165-dc7458a83cff.png"></image>
  7. <input type="text" v-model="keyword" placeholder="搜索" placeholder-class="ph" @confirm="queryRole">
  8. </div>
  9. <div class="qr" @tap="addRole"> + 新增角色</div>
  10. </div>
  11. <template v-if="list.length">
  12. <div class="list" :style="{'height':'calc(100vh - '+(mt+156)+'px)'}">
  13. <u-swipe-action>
  14. <u-swipe-action-item v-for="(item, index) in list" :key="index"
  15. :options="options" @click="e=>deleteRole(item,e)" :ref="'swipeAction' + index" :threshold="5"
  16. >
  17. <view class="swipe-action u-border-top u-border-bottom">
  18. <view class="swipe-action__content">
  19. <div class="l_item adfacjb" @tap.stop="showDetail(item)">
  20. <div class="li_l adfac">
  21. <image :src="item.avatar||item.img"></image>
  22. <div class="lil_info">
  23. <p>{{item.agentName}}</p>
  24. <div class="tip">
  25. <u--text :lines="2" :text="item.systemPrompt" size="24rpx" color="#A6A6A6" :bold="true" lineHeight="40rpx"></u--text>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="li_r" @tap.stop="toBindDevice(item)">配置到设备</div>
  30. </div>
  31. </view>
  32. </view>
  33. </u-swipe-action-item>
  34. </u-swipe-action>
  35. </div>
  36. </template>
  37. <template v-else>
  38. <div class="empty adffcacjc" :style="{'height':'calc(100vh - '+(mt+156)+'px)'}">
  39. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/6efdf230-f26b-4e2e-818c-d89e762030ec.png"></image>
  40. <p>暂未创建角色</p>
  41. </div>
  42. </template>
  43. <cus-tabbar :tabbarIndex="1"></cus-tabbar>
  44. <bind-device ref="bdRef"></bind-device>
  45. <u-picker :itemHeight="88" title="设备" :show="show" :columns="deviceList" keyName="id"
  46. @cancel="show=false" @confirm="confirm" :immediateChange="true" style="height: 500rpx;">
  47. </u-picker>
  48. </view>
  49. </template>
  50. <script>
  51. import cusTabbar from '@/components/CusTabbar/index.vue'
  52. import bindDevice from '@/components/bindDevice/index.vue'
  53. export default {
  54. components:{
  55. cusTabbar,
  56. bindDevice
  57. },
  58. data(){
  59. return {
  60. list:[],
  61. originList:[],
  62. deviceList:[],
  63. show:false,
  64. options: [
  65. {
  66. text: '编辑',
  67. icon: 'edit-pen',
  68. iconSize:'32rpx',
  69. style: {
  70. backgroundColor: '#252525'
  71. }
  72. },
  73. {
  74. text: '删除',
  75. icon: 'trash',
  76. iconSize:'32rpx',
  77. style: {
  78. backgroundColor: '#f56c6c'
  79. }
  80. },
  81. ],
  82. keyword:'',
  83. agentId: '',
  84. deviceId: '',
  85. roleAvatars:[
  86. 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/2d6893bf-04db-4f9e-8d1a-08ed920f452e.png',
  87. 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/650d8bd8-674b-4149-b655-ed7e1957da2b.png',
  88. 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/053ef795-a135-48bd-9417-994de3c51dcf.png'
  89. ]
  90. }
  91. },
  92. onShow() {
  93. this.getAgentList();
  94. },
  95. methods:{
  96. queryRole(){
  97. this.list = this.originList.filter(l=>l.agentName.indexOf(this.keyword)>-1);
  98. },
  99. getAgentList(){
  100. this.$api.get('/agent/list').then(res=>{
  101. if(res.data.code!==0) return this.$showToast(res.data.msg)
  102. this.list = res.data.data;
  103. this.list.forEach((l,i)=>{
  104. l.img = this.roleAvatars[i%3];
  105. })
  106. this.originList = JSON.parse(JSON.stringify(this.list));
  107. })
  108. },
  109. getDeviceList(){
  110. this.$api.get(`/device/bindOther/${this.agentId}`).then(res=>{
  111. if(res.data.code!==0) return this.$showToast(res.data.msg)
  112. this.deviceList = [res.data.data];
  113. if(res.data.data.length>0) this.show = true;
  114. else this.$showToast('暂无已绑定的设备')
  115. })
  116. },
  117. addDevice(){
  118. this.$refs.bdRef.show = true;
  119. },
  120. addRole(){
  121. uni.navigateTo({
  122. url:'/pagesRole/addRole?type=2'
  123. })
  124. },
  125. deleteRole(item,e){
  126. if(e.index===0){
  127. this.list.forEach((d, i) => {
  128. this.$refs['swipeAction' + i][0].closeHandler();
  129. })
  130. uni.navigateTo({
  131. url:`/pagesRole/addRole?agentId=${item.id}&type=2`
  132. })
  133. }else if(e.index===1){
  134. let that = this;
  135. uni.showModal({
  136. content:'删除角色设备将自动解绑需重新添加,您确定删除吗?',
  137. success: (res) => {
  138. if(res.confirm){
  139. that.$api.del('/agent/'+item.id).then(res=>{
  140. if(res.data.code!==0) return that.$showToast(res.data.msg)
  141. that.list.forEach((d, i) => {
  142. that.$refs['swipeAction' + i][0].closeHandler();
  143. })
  144. that.getAgentList();
  145. })
  146. }
  147. }
  148. })
  149. }
  150. },
  151. showDetail(item){
  152. uni.navigateTo({
  153. url:'/pagesRole/roleDetail?agentId='+item.id
  154. })
  155. },
  156. toBindDevice(item){
  157. this.agentId = item.id;
  158. this.getDeviceList();
  159. // if(item.deviceCount>0){
  160. // uni.showModal({
  161. // title:'温馨提示',
  162. // content:'当前角色已绑定设备,是否继续配置设备?',
  163. // success: (res) => {
  164. // if(res.confirm){
  165. // this.show = true;
  166. // }
  167. // }
  168. // })
  169. // }else this.show = true
  170. },
  171. confirm(e){
  172. this.show = false;
  173. this.deviceId = e.value[0].id;
  174. this.$api.post('/agent/agentSetDevice',{agentId:this.agentId,deviceId:this.deviceId}).then(res=>{
  175. if(res.data.code!==0) return this.$showToast(res.data.msg)
  176. this.$showToast('配置成功')
  177. setTimeout(()=>{
  178. this.getAgentList();
  179. },1000)
  180. })
  181. },
  182. }
  183. }
  184. </script>
  185. <style>
  186. .u-swipe-action-item__right__button__wrapper {
  187. font-size: 28rpx;
  188. font-weight: 400;
  189. color: #FFFFFF;
  190. letter-spacing: 2rpx;
  191. padding: 0 26rpx;
  192. }
  193. .swipe-action {
  194. width: 100%;
  195. }
  196. .u-swipe-action {
  197. z-index: 100 !important;
  198. }
  199. </style>
  200. <style scoped lang="less">
  201. ::v-deep .list .u-swipe-action-item{
  202. margin-top: 60rpx;
  203. }
  204. ::v-deep .list .swipe-action{
  205. border: none !important;
  206. }
  207. .tabPage{
  208. background: #FFFFFF;
  209. padding-bottom: 192rpx;
  210. box-sizing: border-box;
  211. .query{
  212. margin-top: 20rpx;
  213. width: 100%;
  214. padding-left: 30rpx;
  215. box-sizing: border-box;
  216. .ql{
  217. width: calc(100% - 230rpx);
  218. height: 80rpx;
  219. background: #F6F6F8;
  220. border-radius: 40rpx;
  221. padding: 26rpx 36rpx;
  222. box-sizing: border-box;
  223. image{
  224. width: 28rpx;
  225. height: 28rpx;
  226. }
  227. input{
  228. font-family: PingFangSC, PingFang SC;
  229. font-weight: 400;
  230. font-size: 26rpx;
  231. color: #222222;
  232. line-height: 40rpx;
  233. padding-left: 20rpx;
  234. }
  235. }
  236. .qr{
  237. width: 204rpx;
  238. height: 80rpx;
  239. background: #D9F159;
  240. border-radius: 45rpx 0rpx 0rpx 45rpx;
  241. font-family: PingFang-SC, PingFang-SC;
  242. font-weight: bold;
  243. font-size: 28rpx;
  244. color: #111111;
  245. line-height: 80rpx;
  246. text-align: center;
  247. }
  248. }
  249. .list{
  250. padding: 0 30rpx;
  251. overflow-y: auto;
  252. .l_item{
  253. width: 100%;
  254. .li_l{
  255. width: calc(100% - 200rpx);
  256. image{
  257. width: 116rpx;
  258. height: 116rpx;
  259. border-radius: 50%;
  260. }
  261. .lil_info{
  262. width: calc(100% - 116rpx);
  263. padding-left: 23rpx;
  264. p{
  265. font-family: PingFang-SC, PingFang-SC;
  266. font-weight: bold;
  267. font-size: 32rpx;
  268. color: #111111;
  269. line-height: 32rpx;
  270. margin-bottom: 16rpx;
  271. }
  272. }
  273. }
  274. .li_r{
  275. width: 160rpx;
  276. height: 64rpx;
  277. background: #D9F159;
  278. border-radius: 16rpx;
  279. font-family: PingFangSC, PingFang SC;
  280. font-weight: 400;
  281. font-size: 24rpx;
  282. color: #111111;
  283. line-height: 64rpx;
  284. text-align: center;
  285. letter-spacing: 2rpx;
  286. }
  287. }
  288. }
  289. .empty{
  290. image{
  291. width: 64rpx;
  292. height: 66rpx;
  293. }
  294. p{
  295. font-family: PingFangSC, PingFang SC;
  296. font-weight: 400;
  297. font-size: 30rpx;
  298. color: #A6A6A6;
  299. line-height: 42rpx;
  300. text-align: center;
  301. margin-top: 30rpx;
  302. }
  303. .zt_btn{
  304. width: calc(100% - 140rpx);
  305. margin: 230rpx 70rpx 0;
  306. }
  307. }
  308. .ph{
  309. color: #A6A6A6;
  310. }
  311. }
  312. </style>