role.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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.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="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. this.getDeviceList();
  95. },
  96. methods:{
  97. queryRole(){
  98. this.list = this.originList.filter(l=>l.agentName.indexOf(this.keyword)>-1);
  99. },
  100. getAgentList(){
  101. this.$api.get('/agent/list').then(res=>{
  102. if(res.data.code!==0) return this.$showToast(res.data.msg)
  103. this.list = res.data.data;
  104. this.list.forEach((l,i)=>{
  105. l.img = this.roleAvatars[i%3];
  106. })
  107. this.originList = JSON.parse(JSON.stringify(this.list));
  108. })
  109. },
  110. getDeviceList(){
  111. this.$api.get(`/device/bindOther/null`).then(res=>{
  112. if(res.data.code!==0) return this.$showToast(res.data.msg)
  113. this.deviceList = [res.data.data];
  114. })
  115. },
  116. addDevice(){
  117. this.$refs.bdRef.show = true;
  118. },
  119. addRole(){
  120. uni.navigateTo({
  121. url:'/pagesRole/addRole?type=2'
  122. })
  123. },
  124. deleteRole(item,e){
  125. if(e.index===0){
  126. this.list.forEach((d, i) => {
  127. this.$refs['swipeAction' + i][0].closeHandler();
  128. })
  129. uni.navigateTo({
  130. url:`/pagesRole/addRole?agentId=${item.id}&type=2`
  131. })
  132. }else if(e.index===1){
  133. let that = this;
  134. uni.showModal({
  135. content:'删除角色设备将自动解绑需重新添加,您确定删除吗?',
  136. success: (res) => {
  137. if(res.confirm){
  138. that.$api.del('/agent/'+item.id).then(res=>{
  139. if(res.data.code!==0) return that.$showToast(res.data.msg)
  140. that.list.forEach((d, i) => {
  141. that.$refs['swipeAction' + i][0].closeHandler();
  142. })
  143. that.getAgentList();
  144. })
  145. }
  146. }
  147. })
  148. }
  149. },
  150. showDetail(item){
  151. uni.navigateTo({
  152. url:'/pagesRole/roleDetail?agentId='+item.id
  153. })
  154. },
  155. toBindDevice(item){
  156. this.agentId = item.id;
  157. this.show = true;
  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. }
  259. .lil_info{
  260. width: calc(100% - 116rpx);
  261. padding-left: 23rpx;
  262. p{
  263. font-family: PingFang-SC, PingFang-SC;
  264. font-weight: bold;
  265. font-size: 32rpx;
  266. color: #111111;
  267. line-height: 32rpx;
  268. margin-bottom: 16rpx;
  269. }
  270. }
  271. }
  272. .li_r{
  273. width: 160rpx;
  274. height: 64rpx;
  275. background: #D9F159;
  276. border-radius: 16rpx;
  277. font-family: PingFangSC, PingFang SC;
  278. font-weight: 400;
  279. font-size: 24rpx;
  280. color: #111111;
  281. line-height: 64rpx;
  282. text-align: center;
  283. letter-spacing: 2rpx;
  284. }
  285. }
  286. }
  287. .empty{
  288. image{
  289. width: 64rpx;
  290. height: 66rpx;
  291. }
  292. p{
  293. font-family: PingFangSC, PingFang SC;
  294. font-weight: 400;
  295. font-size: 30rpx;
  296. color: #A6A6A6;
  297. line-height: 42rpx;
  298. text-align: center;
  299. margin-top: 30rpx;
  300. }
  301. .zt_btn{
  302. width: calc(100% - 140rpx);
  303. margin: 230rpx 70rpx 0;
  304. }
  305. }
  306. .ph{
  307. color: #A6A6A6;
  308. }
  309. }
  310. </style>