role.vue 7.6 KB

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