role.vue 6.9 KB

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