role.vue 7.1 KB

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