cooperation.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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)*30 + 140)+'px'}">
  13. <div class="binding-body cooperation">
  14. <template >
  15. <div class="toclient">{{lang==='en'?'Collaborator':`协作用户`}}</div>
  16. <div class="b-input" >
  17. <input v-model="userName" :placeholder="lang==='en'?'User name':'请输入用户账号'" type="text">
  18. </div>
  19. </template>
  20. <!-- <template v-else>
  21. <div class="toclient">{{lang==='en'?'Collaborator':`协作用户`}}</div>
  22. <div class="b-input" >
  23. {{cooName}}
  24. </div>
  25. </template> -->
  26. <div class="toclient"><span>{{lang==='en'?'Permission':'协作权限'}}</span><div @click="handleSelectAll"><span :class="{check_active:selectAll}" class="fdcheck">{{lang==='en'?'All':'全选'}}</span></div></div>
  27. <ul class="auth-list">
  28. <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>
  29. </ul>
  30. </div>
  31. </div>
  32. <div class="bind-btn coo-btn" >
  33. <template v-if="!cooName">
  34. <span class="default" @click="handleClick">{{i18n.t('common.cancle')}}</span>
  35. <span @click="addCooperation">{{i18n.t('common.save')}}</span>
  36. </template>
  37. <template v-else>
  38. <span class="default" @click="unbind">{{ i18n.t('manage.cancleCollaborator') }}</span>
  39. <span @click="addCooperation">{{ i18n.t('common.save') }}</span>
  40. </template>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import toastZH from '@/store/language/cn/toast'
  47. import toastEN from '@/store/language/en/toast'
  48. import temp from '../../page/navs/temp.vue'
  49. import { i18n } from '@/lang'
  50. export default {
  51. components: { temp },
  52. props: ['sceneNum', 'ids', 'cooName', 'visible', 'cooType', 'getListData'],
  53. data () {
  54. return {
  55. i18n,
  56. lock: true,
  57. userName: '',
  58. auth: [],
  59. lang: localStorage.getItem('language'),
  60. toastCode: localStorage.getItem('language') === 'en' ? toastEN : toastZH
  61. }
  62. },
  63. computed: {
  64. selectAll () {
  65. return this.auth.filter(item => !item.hasAuth).length === 0
  66. }
  67. },
  68. watch: {
  69. visible: function (newVal) {
  70. if (newVal) {
  71. this.getResoureList()
  72. }
  73. this.userName = this.cooName || ''
  74. this.lang = localStorage.getItem('language')
  75. this.toastCode = this.lang === 'en' ? toastEN : toastZH
  76. }
  77. },
  78. mounted () {
  79. },
  80. methods: {
  81. async unbind () {
  82. let token = localStorage.getItem('token')
  83. let url = this.cooType === 'scene' ? '/user/scene/cooperation/delete' : '/user/camera/deleteCooperationUser'
  84. let params = this.cooType === 'scene' ? {
  85. sceneNum: this.sceneNum
  86. } : {
  87. cameraId: this.sceneNum
  88. }
  89. let result = await this.$http({
  90. method: 'post',
  91. headers: {
  92. token
  93. },
  94. data: params,
  95. url: url
  96. })
  97. let data = result.data
  98. if (data.code === 0) {
  99. this.handleClick('getList')
  100. this.$toast.show('success', this.toastCode['45'])
  101. } else {
  102. return this.$toast.show('warn', this.toastCode[data.code], () => {})
  103. }
  104. },
  105. handleSelectAll () {
  106. // if (this.cooName) {
  107. // return
  108. // }
  109. this.lock = false
  110. let isSelected = !this.selectAll
  111. this.auth.forEach(item => {
  112. item.hasAuth = isSelected
  113. })
  114. },
  115. selectItem (item, i) {
  116. // if (this.cooName) {
  117. // this.userName = this.cooName
  118. // return
  119. // }
  120. item.hasAuth = !item.hasAuth
  121. this.$set(this.auth, i, item)
  122. this.lock = true
  123. },
  124. handleClick (type = '') {
  125. this.$emit('closePoint', type)
  126. },
  127. async getResoureByNum () {
  128. let token = localStorage.getItem('token')
  129. let url = this.cooType === 'scene' ? '/user/scene/cooperation/findSceneResource' : '/user/camera/sceneResourceByCameraId'
  130. let params = this.cooType === 'scene' ? {
  131. sceneNum: this.sceneNum
  132. } : {
  133. cameraId: this.sceneNum
  134. }
  135. let res = await this.$http({
  136. method: 'post',
  137. headers: {
  138. token
  139. },
  140. data: params,
  141. url: url
  142. })
  143. if (res.data.code !== 0) {
  144. return
  145. }
  146. let data = res.data.data || []
  147. setTimeout(() => {
  148. let arr = data.map(sub => sub.id)
  149. let tmp = this.auth.map(item => {
  150. item.hasAuth = true
  151. if (arr.length > 0) {
  152. item.hasAuth = arr.indexOf(item.id) > -1
  153. }
  154. return item
  155. })
  156. this.auth = tmp
  157. })
  158. },
  159. async getResoureList () {
  160. let token = localStorage.getItem('token')
  161. let res = await this.$http({
  162. method: 'post',
  163. headers: {
  164. token
  165. },
  166. url: '/user/scene/cooperation/sceneResourceList',
  167. data: this.getListData || {}
  168. })
  169. if (res.data.code !== 0) {
  170. return this.handleClick()
  171. }
  172. let { include, exclude } = res.data.data
  173. let filterKeyWords = exclude.map(item => item.keyWord)
  174. let list = include.filter(item => filterKeyWords.indexOf(item.keyWord) === -1)
  175. let tmp = list.map(item => {
  176. item.hasAuth = true
  177. return item
  178. })
  179. this.auth = tmp
  180. this.cooName && this.getResoureByNum()
  181. },
  182. async addCooperation () {
  183. let token = localStorage.getItem('token')
  184. if (!this.userName) {
  185. return this.$toast.show('error', `${this.lang === 'en' ? 'Please enter user name.' : '请输入用户账号'}`)
  186. }
  187. let resourceIds = []
  188. this.auth.forEach(item => {
  189. if (item.hasAuth) {
  190. resourceIds.push(item.id)
  191. }
  192. })
  193. if (resourceIds.length <= 0) {
  194. return this.$toast.show('warn', `${this.lang === 'en' ? 'Please select at least one.' : '请至少勾选一项权限'}`)
  195. }
  196. let url = this.cooType === 'scene' ? '/user/scene/cooperation/save' : '/user/camera/saveCooperationUser'
  197. let params = {
  198. userName: this.userName,
  199. resourceIds: resourceIds.join(',')
  200. }
  201. if (this.ids) {
  202. this.cooType === 'scene' ? (params['sceneNum'] = this.ids) : (params['ids'] = this.ids)
  203. } else {
  204. this.cooType === 'scene' ? (params['sceneNum'] = this.sceneNum) : (params['cameraId'] = this.sceneNum)
  205. }
  206. let result = await this.$http({
  207. method: 'post',
  208. data: params,
  209. headers: {
  210. token
  211. },
  212. url: url
  213. })
  214. let data = result.data
  215. if (data.code === 0) {
  216. this.handleClick('getList')
  217. this.$toast.show('success', this.toastCode['44'])
  218. } else if (data.code === 3004) {
  219. this.handleClick()
  220. } else {
  221. return this.$toast.show('warn', this.toastCode[data.code], () => {
  222. return false
  223. })
  224. }
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. @import "./style.scss";
  231. </style>