role.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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/05/29/2f26eb7e-0b3d-428f-9d1a-4e86ccd416fb.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/05/29/d3ebb319-374c-43db-bd49-64e31c83f12e.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="board"
  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/05/29/18082f18-2b67-4c43-9403-b421644d047a.png',
  87. 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/f896a46a-78ce-46ae-bf0b-6bb61e6503ab.png',
  88. 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/de98766e-49fd-419b-90b2-366108c8f56e.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. })
  114. },
  115. addDevice(){
  116. this.$refs.bdRef.show = true;
  117. },
  118. addRole(){
  119. uni.navigateTo({
  120. url:'/pagesRole/addRole?type=2'
  121. })
  122. },
  123. deleteRole(item,e){
  124. if(e.index===0){
  125. this.list.forEach((d, i) => {
  126. this.$refs['swipeAction' + i][0].closeHandler();
  127. })
  128. uni.navigateTo({
  129. url:`/pagesRole/addRole?agentId=${item.id}&type=2`
  130. })
  131. }else if(e.index===1){
  132. let that = this;
  133. uni.showModal({
  134. content:'删除角色设备将自动解绑需重新添加,您确定删除吗?',
  135. success: (res) => {
  136. if(res.confirm){
  137. that.$api.del('/agent/'+item.id).then(res=>{
  138. if(res.data.code!==0) return that.$showToast(res.data.msg)
  139. that.list.forEach((d, i) => {
  140. that.$refs['swipeAction' + i][0].closeHandler();
  141. })
  142. that.getAgentList();
  143. })
  144. }
  145. }
  146. })
  147. }
  148. },
  149. showDetail(item){
  150. uni.navigateTo({
  151. url:'/pagesRole/roleDetail?agentId='+item.id
  152. })
  153. },
  154. toBindDevice(item){
  155. this.agentId = item.id;
  156. this.show = true;
  157. this.getDeviceList();
  158. // if(item.deviceCount>0){
  159. // uni.showModal({
  160. // title:'温馨提示',
  161. // content:'当前角色已绑定设备,是否继续配置设备?',
  162. // success: (res) => {
  163. // if(res.confirm){
  164. // this.show = true;
  165. // }
  166. // }
  167. // })
  168. // }else this.show = true
  169. },
  170. confirm(e){
  171. this.show = false;
  172. this.deviceId = e.value[0].id;
  173. this.$api.post('/agent/agentSetDevice',{agentId:this.agentId,deviceId:this.deviceId}).then(res=>{
  174. if(res.data.code!==0) return this.$showToast(res.data.msg)
  175. this.$showToast('配置成功')
  176. setTimeout(()=>{
  177. this.getAgentList();
  178. },1000)
  179. })
  180. },
  181. }
  182. }
  183. </script>
  184. <style>
  185. .u-swipe-action-item__right__button__wrapper {
  186. font-size: 28rpx;
  187. font-weight: 400;
  188. color: #FFFFFF;
  189. letter-spacing: 2rpx;
  190. padding: 0 26rpx;
  191. }
  192. .swipe-action {
  193. width: 100%;
  194. }
  195. .u-swipe-action {
  196. z-index: 100 !important;
  197. }
  198. </style>
  199. <style scoped lang="less">
  200. ::v-deep .list .u-swipe-action-item{
  201. margin-top: 60rpx;
  202. }
  203. ::v-deep .list .swipe-action{
  204. border: none !important;
  205. }
  206. .tabPage{
  207. background: #FFFFFF;
  208. padding-bottom: 192rpx;
  209. box-sizing: border-box;
  210. .query{
  211. margin-top: 20rpx;
  212. width: 100%;
  213. padding-left: 30rpx;
  214. box-sizing: border-box;
  215. .ql{
  216. width: calc(100% - 230rpx);
  217. height: 80rpx;
  218. background: #F6F6F8;
  219. border-radius: 40rpx;
  220. padding: 26rpx 36rpx;
  221. box-sizing: border-box;
  222. image{
  223. width: 28rpx;
  224. height: 28rpx;
  225. }
  226. input{
  227. font-family: PingFangSC, PingFang SC;
  228. font-weight: 400;
  229. font-size: 26rpx;
  230. color: #222222;
  231. line-height: 40rpx;
  232. padding-left: 20rpx;
  233. }
  234. }
  235. .qr{
  236. width: 204rpx;
  237. height: 80rpx;
  238. background: #D9F159;
  239. border-radius: 45rpx 0rpx 0rpx 45rpx;
  240. font-family: PingFang-SC, PingFang-SC;
  241. font-weight: bold;
  242. font-size: 28rpx;
  243. color: #111111;
  244. line-height: 80rpx;
  245. text-align: center;
  246. }
  247. }
  248. .list{
  249. padding: 0 30rpx;
  250. overflow-y: auto;
  251. .l_item{
  252. width: 100%;
  253. .li_l{
  254. width: calc(100% - 200rpx);
  255. image{
  256. width: 116rpx;
  257. height: 116rpx;
  258. border-radius: 50%;
  259. }
  260. .lil_info{
  261. width: calc(100% - 116rpx);
  262. padding-left: 23rpx;
  263. p{
  264. font-family: PingFang-SC, PingFang-SC;
  265. font-weight: bold;
  266. font-size: 32rpx;
  267. color: #111111;
  268. line-height: 32rpx;
  269. margin-bottom: 16rpx;
  270. }
  271. }
  272. }
  273. .li_r{
  274. width: 160rpx;
  275. height: 64rpx;
  276. background: #D9F159;
  277. border-radius: 16rpx;
  278. font-family: PingFangSC, PingFang SC;
  279. font-weight: 400;
  280. font-size: 24rpx;
  281. color: #111111;
  282. line-height: 64rpx;
  283. text-align: center;
  284. letter-spacing: 2rpx;
  285. }
  286. }
  287. }
  288. .empty{
  289. image{
  290. width: 64rpx;
  291. height: 66rpx;
  292. }
  293. p{
  294. font-family: PingFangSC, PingFang SC;
  295. font-weight: 400;
  296. font-size: 30rpx;
  297. color: #A6A6A6;
  298. line-height: 42rpx;
  299. text-align: center;
  300. margin-top: 30rpx;
  301. }
  302. .zt_btn{
  303. width: calc(100% - 140rpx);
  304. margin: 230rpx 70rpx 0;
  305. }
  306. }
  307. .ph{
  308. color: #A6A6A6;
  309. }
  310. }
  311. </style>