cooperation.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div
  3. class="toast-layout"
  4. :style="{background:false?'none':'rgba(0, 0, 0, 0.3)'}"
  5. :class="{'toast-active':visible}"
  6. >
  7. <div class="toast-con bind-con" :style="{minWidth:'600px'}">
  8. <div class="t-header ">
  9. <span>{{lang==='en'?'Invite collaborator':'分配协作'}}</span>
  10. <i class="iconfont icon-cuowu" @click="handleClick"></i>
  11. </div>
  12. <div class="binding-con" :style="{height:Math.ceil(auth.length/4)*62+'px'}">
  13. <div class="binding-body cooperation">
  14. <div class="toclient">{{lang==='en'?'Add collaborator':`分配${cooType === 'scene'?'场景':'相机'}给用户`}}</div>
  15. <div class="b-input" >
  16. <input v-model="userName" :placeholder="lang==='en'?'User name':'请输入用户账号'" type="text">
  17. </div>
  18. <div class="toclient"><span>{{lang==='en'?'Assign Permission':'分配权限'}}</span><div @click="lock=false,selectAll=!selectAll"><span :class="{check_active:selectAll}" class="fdcheck">{{lang==='en'?'All':'全选'}}</span></div></div>
  19. <ul class="auth-list">
  20. <li v-for="(item,i) in auth" :key="i"><span @click="selectItem(item,i)" class="fdcheck" :class="{check_active:item.hasAuth}">{{lang==='en'?item.keyWord:item.name}}</span></li>
  21. </ul>
  22. </div>
  23. </div>
  24. <div class="bind-btn coo-btn" >
  25. <span @click="addCooperation">{{lang==='en'?'OK':'确定'}}</span>
  26. <span class="default" @click="handleClick">{{lang==='en'?'Cancel':'取消'}}</span>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import toastZH from '@/store/language/cn/toast'
  33. import toastEN from '@/store/language/en/toast'
  34. export default {
  35. props: ['sceneNum', 'visible', 'cooType'],
  36. data () {
  37. return {
  38. lock: true,
  39. userName: '',
  40. selectAll: false,
  41. auth: [],
  42. lang: localStorage.getItem('language'),
  43. toastCode: localStorage.getItem('language') === 'en' ? toastEN : toastZH
  44. }
  45. },
  46. computed: {
  47. },
  48. watch: {
  49. selectAll: function (newVal) {
  50. if (!this.lock) {
  51. this.auth.forEach(item => {
  52. item.hasAuth = newVal
  53. })
  54. }
  55. },
  56. visible: function (newVal) {
  57. if (newVal) {
  58. this.selectAll = true
  59. this.getResoureList()
  60. this.getResoureByNum()
  61. }
  62. this.userName = ''
  63. this.lang = localStorage.getItem('language')
  64. this.toastCode = this.lang === 'en' ? toastEN : toastZH
  65. }
  66. },
  67. methods: {
  68. selectItem (item, i) {
  69. item.hasAuth = !item.hasAuth
  70. this.$set(this.auth, i, item)
  71. this.lock = true
  72. this.selectAll = true
  73. this.auth.forEach(sub => {
  74. if (!sub.hasAuth) {
  75. this.selectAll = false
  76. }
  77. })
  78. },
  79. handleClick (type = '') {
  80. this.$emit('closePoint', type)
  81. },
  82. async getResoureByNum () {
  83. let token = localStorage.getItem('token')
  84. let url = this.cooType === 'scene' ? '/user/scene/cooperation/sceneResourceBySceneNum' : '/user/camera/sceneResourceByCameraId'
  85. let params = this.cooType === 'scene' ? {
  86. sceneNum: this.sceneNum
  87. } : {
  88. cameraId: this.sceneNum
  89. }
  90. let res = await this.$http({
  91. method: 'post',
  92. headers: {
  93. token
  94. },
  95. data: params,
  96. url: url
  97. })
  98. if (res.data.code !== 0) {
  99. return
  100. }
  101. let data = res.data.data || []
  102. setTimeout(() => {
  103. let tmp = this.auth.map(item => {
  104. item.hasAuth = true
  105. data.forEach(sub => {
  106. if (item.id === sub.id) {
  107. item.hasAuth = true
  108. } else {
  109. item.hasAuth = false
  110. }
  111. })
  112. return item
  113. })
  114. this.auth = tmp
  115. })
  116. },
  117. async getResoureList () {
  118. let token = localStorage.getItem('token')
  119. let res = await this.$http({
  120. method: 'post',
  121. headers: {
  122. token
  123. },
  124. url: '/user/scene/cooperation/sceneResourceList'
  125. })
  126. if (res.data.code !== 0) {
  127. return this.handleClick()
  128. }
  129. this.auth = res.data.data
  130. },
  131. async addCooperation () {
  132. let token = localStorage.getItem('token')
  133. if (!this.userName) {
  134. return this.$toast.show('error', `${this.lang === 'en' ? 'Please enter user name.' : '请输入用户账号'}`)
  135. }
  136. let resourceIds = []
  137. this.auth.forEach(item => {
  138. if (item.hasAuth) {
  139. resourceIds.push(item.id)
  140. }
  141. })
  142. if (resourceIds.length <= 0) {
  143. return this.$toast.show('error', `${this.lang === 'en' ? 'Please select at least one.' : '请至少勾选一项权限'}`)
  144. }
  145. let url = this.cooType === 'scene' ? '/user/scene/cooperation/save' : '/user/camera/saveCooperationUser'
  146. let params = {
  147. userName: this.userName,
  148. resourceIds: resourceIds.join(',')
  149. }
  150. this.cooType === 'scene' ? (params['sceneNum'] = this.sceneNum) : (params['cameraId'] = this.sceneNum)
  151. let result = await this.$http({
  152. method: 'post',
  153. data: params,
  154. headers: {
  155. token
  156. },
  157. url: url
  158. })
  159. let data = result.data
  160. if (data.code === 0) {
  161. this.handleClick('getList')
  162. this.$toast.show('success', this.toastCode['44'])
  163. } else if (data.code === 3004) {
  164. this.handleClick()
  165. } else {
  166. return this.$toast.show('warn', this.toastCode[data.code], () => {
  167. return false
  168. })
  169. }
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="scss" scoped>
  175. @import "./style.scss";
  176. </style>