role.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. if(!uni.getStorageSync('token')) return
  94. this.getAgentList();
  95. },
  96. methods:{
  97. queryRole(){
  98. if(!this.isLogin()) return
  99. this.list = this.originList.filter(l=>l.agentName.indexOf(this.keyword)>-1);
  100. },
  101. getAgentList(){
  102. this.$api.get('/agent/list').then(res=>{
  103. if(res.data.code!==0) return
  104. this.list = res.data.data;
  105. this.list.forEach((l,i)=>{
  106. l.img = this.roleAvatars[i%3];
  107. })
  108. this.originList = JSON.parse(JSON.stringify(this.list));
  109. })
  110. },
  111. getDeviceList(){
  112. this.$api.get(`/device/bindOther/${this.agentId}`).then(res=>{
  113. if(res.data.code!==0) return
  114. this.deviceList = [res.data.data];
  115. if(res.data.data.length>0) this.show = true;
  116. else this.$showToast('暂无可绑定的设备')
  117. })
  118. },
  119. addDevice(){
  120. this.$refs.bdRef.show = true;
  121. },
  122. addRole(){
  123. if(!this.isLogin()) return
  124. uni.navigateTo({
  125. url:'/pagesRole/addRole?type=2'
  126. })
  127. },
  128. deleteRole(item,e){
  129. if(e.index===0){
  130. this.list.forEach((d, i) => {
  131. this.$refs['swipeAction' + i][0].closeHandler();
  132. })
  133. uni.navigateTo({
  134. url:`/pagesRole/addRole?agentId=${item.id}&type=2`
  135. })
  136. }else if(e.index===1){
  137. let that = this;
  138. uni.showModal({
  139. content:'删除角色设备将自动解绑需重新添加,您确定删除吗?',
  140. success: (res) => {
  141. if(res.confirm){
  142. that.$api.del('/agent/'+item.id).then(res=>{
  143. if(res.data.code!==0) return that.$showToast(res.data.msg)
  144. that.list.forEach((d, i) => {
  145. that.$refs['swipeAction' + i][0].closeHandler();
  146. })
  147. that.getAgentList();
  148. })
  149. }
  150. }
  151. })
  152. }
  153. },
  154. showDetail(item){
  155. uni.navigateTo({
  156. url:'/pagesRole/roleDetail?agentId='+item.id
  157. })
  158. },
  159. toBindDevice(item){
  160. this.agentId = item.id;
  161. this.getDeviceList();
  162. // if(item.deviceCount>0){
  163. // uni.showModal({
  164. // title:'温馨提示',
  165. // content:'当前角色已绑定设备,是否继续配置设备?',
  166. // success: (res) => {
  167. // if(res.confirm){
  168. // this.show = true;
  169. // }
  170. // }
  171. // })
  172. // }else this.show = true
  173. },
  174. confirm(e){
  175. this.show = false;
  176. this.deviceId = e.value[0].id;
  177. this.$api.post('/agent/agentSetDevice',{agentId:this.agentId,deviceId:this.deviceId}).then(res=>{
  178. if(res.data.code!==0) return this.$showToast(res.data.msg)
  179. this.$showToast('配置成功')
  180. setTimeout(()=>{
  181. this.getAgentList();
  182. },1000)
  183. })
  184. },
  185. }
  186. }
  187. </script>
  188. <style>
  189. .u-swipe-action-item__right__button__wrapper {
  190. font-size: 28rpx;
  191. font-weight: 400;
  192. color: #FFFFFF;
  193. letter-spacing: 2rpx;
  194. padding: 0 26rpx;
  195. }
  196. .swipe-action {
  197. width: 100%;
  198. }
  199. .u-swipe-action {
  200. z-index: 100 !important;
  201. }
  202. </style>
  203. <style scoped lang="less">
  204. ::v-deep .list .u-swipe-action-item{
  205. margin-top: 60rpx;
  206. }
  207. ::v-deep .list .swipe-action{
  208. border: none !important;
  209. }
  210. .tabPage{
  211. background: #FFFFFF;
  212. padding-bottom: 192rpx;
  213. box-sizing: border-box;
  214. .query{
  215. margin-top: 20rpx;
  216. width: 100%;
  217. padding-left: 30rpx;
  218. box-sizing: border-box;
  219. .ql{
  220. width: calc(100% - 230rpx);
  221. height: 80rpx;
  222. background: #F6F6F8;
  223. border-radius: 40rpx;
  224. padding: 26rpx 36rpx;
  225. box-sizing: border-box;
  226. image{
  227. width: 28rpx;
  228. height: 28rpx;
  229. }
  230. input{
  231. font-family: PingFangSC, PingFang SC;
  232. font-weight: 400;
  233. font-size: 26rpx;
  234. color: #222222;
  235. line-height: 40rpx;
  236. padding-left: 20rpx;
  237. }
  238. }
  239. .qr{
  240. width: 204rpx;
  241. height: 80rpx;
  242. background: #D9F159;
  243. border-radius: 45rpx 0rpx 0rpx 45rpx;
  244. font-family: PingFang-SC, PingFang-SC;
  245. font-weight: bold;
  246. font-size: 28rpx;
  247. color: #111111;
  248. line-height: 80rpx;
  249. text-align: center;
  250. }
  251. }
  252. .list{
  253. padding: 0 30rpx;
  254. overflow-y: auto;
  255. .l_item{
  256. width: 100%;
  257. .li_l{
  258. width: calc(100% - 200rpx);
  259. image{
  260. width: 116rpx;
  261. height: 116rpx;
  262. border-radius: 50%;
  263. }
  264. .lil_info{
  265. width: calc(100% - 116rpx);
  266. padding-left: 23rpx;
  267. p{
  268. font-family: PingFang-SC, PingFang-SC;
  269. font-weight: bold;
  270. font-size: 32rpx;
  271. color: #111111;
  272. line-height: 32rpx;
  273. margin-bottom: 16rpx;
  274. }
  275. }
  276. }
  277. .li_r{
  278. width: 160rpx;
  279. height: 64rpx;
  280. background: #D9F159;
  281. border-radius: 16rpx;
  282. font-family: PingFangSC, PingFang SC;
  283. font-weight: 400;
  284. font-size: 24rpx;
  285. color: #111111;
  286. line-height: 64rpx;
  287. text-align: center;
  288. letter-spacing: 2rpx;
  289. }
  290. }
  291. }
  292. .empty{
  293. image{
  294. width: 64rpx;
  295. height: 66rpx;
  296. }
  297. p{
  298. font-family: PingFangSC, PingFang SC;
  299. font-weight: 400;
  300. font-size: 30rpx;
  301. color: #A6A6A6;
  302. line-height: 42rpx;
  303. text-align: center;
  304. margin-top: 30rpx;
  305. }
  306. .zt_btn{
  307. width: calc(100% - 140rpx);
  308. margin: 230rpx 70rpx 0;
  309. }
  310. }
  311. .ph{
  312. color: #A6A6A6;
  313. }
  314. }
  315. </style>