|
@@ -4,17 +4,22 @@
|
|
|
:style="{background:false?'none':'rgba(0, 0, 0, 0.3)'}"
|
|
|
:class="{'toast-active':visible}"
|
|
|
>
|
|
|
- <div class="toast-con bind-con" :style="{minWidth:'505px'}">
|
|
|
+ <div class="toast-con bind-con" :style="{minWidth:'600px'}">
|
|
|
<div class="t-header ">
|
|
|
<span>{{lang==='en'?'Invite collaborator':'分配协作'}}</span>
|
|
|
<i class="iconfont icon-cuowu" @click="handleClick"></i>
|
|
|
</div>
|
|
|
- <div class="binding-con" style="height:150px">
|
|
|
- <div class="binding-body" style="width:450px;top:25px">
|
|
|
- <div class="toclient">{{lang==='en'?'Add collaborator':'分配场景给用户'}}</div>
|
|
|
+ <div class="binding-con" :style="{height:(Math.ceil(auth.length/4)*30 + 140)+'px'}">
|
|
|
+ <div class="binding-body cooperation">
|
|
|
+ <div class="toclient">{{lang==='en'?'Add collaborator':`分配${cooType === 'scene'?'场景':'相机'}给用户`}}</div>
|
|
|
<div class="b-input" >
|
|
|
<input v-model="userName" :placeholder="lang==='en'?'User name':'请输入用户账号'" type="text">
|
|
|
</div>
|
|
|
+
|
|
|
+ <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>
|
|
|
+ <ul class="auth-list">
|
|
|
+ <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>
|
|
|
+ </ul>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -32,10 +37,13 @@ import toastZH from '@/store/language/cn/toast'
|
|
|
import toastEN from '@/store/language/en/toast'
|
|
|
|
|
|
export default {
|
|
|
- props: ['sceneNum', 'visible'],
|
|
|
+ props: ['sceneNum', 'visible', 'cooType'],
|
|
|
data () {
|
|
|
return {
|
|
|
+ lock: true,
|
|
|
userName: '',
|
|
|
+ selectAll: false,
|
|
|
+ auth: [],
|
|
|
lang: localStorage.getItem('language'),
|
|
|
toastCode: localStorage.getItem('language') === 'en' ? toastEN : toastZH
|
|
|
}
|
|
@@ -44,15 +52,95 @@ export default {
|
|
|
|
|
|
},
|
|
|
watch: {
|
|
|
+ selectAll: function (newVal) {
|
|
|
+ if (!this.lock) {
|
|
|
+ this.auth.forEach(item => {
|
|
|
+ item.hasAuth = newVal
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
visible: function (newVal) {
|
|
|
+ if (newVal) {
|
|
|
+ this.selectAll = true
|
|
|
+ this.getResoureList()
|
|
|
+ // this.getResoureByNum()
|
|
|
+ }
|
|
|
this.userName = ''
|
|
|
this.lang = localStorage.getItem('language')
|
|
|
this.toastCode = this.lang === 'en' ? toastEN : toastZH
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- handleClick () {
|
|
|
- this.$emit('closePoint')
|
|
|
+ selectItem (item, i) {
|
|
|
+ item.hasAuth = !item.hasAuth
|
|
|
+ this.$set(this.auth, i, item)
|
|
|
+ this.lock = true
|
|
|
+ this.selectAll = true
|
|
|
+
|
|
|
+ this.auth.forEach(sub => {
|
|
|
+ if (!sub.hasAuth) {
|
|
|
+ this.selectAll = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleClick (type = '') {
|
|
|
+ this.$emit('closePoint', type)
|
|
|
+ },
|
|
|
+ async getResoureByNum () {
|
|
|
+ let token = localStorage.getItem('token')
|
|
|
+ let url = this.cooType === 'scene' ? '/user/scene/cooperation/sceneResourceBySceneNum' : '/user/camera/sceneResourceByCameraId'
|
|
|
+ let params = this.cooType === 'scene' ? {
|
|
|
+ sceneNum: this.sceneNum
|
|
|
+ } : {
|
|
|
+ cameraId: this.sceneNum
|
|
|
+ }
|
|
|
+
|
|
|
+ let res = await this.$http({
|
|
|
+ method: 'post',
|
|
|
+ headers: {
|
|
|
+ token
|
|
|
+ },
|
|
|
+ data: params,
|
|
|
+ url: url
|
|
|
+ })
|
|
|
+
|
|
|
+ if (res.data.code !== 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let data = res.data.data || []
|
|
|
+ setTimeout(() => {
|
|
|
+ let tmp = this.auth.map(item => {
|
|
|
+ item.hasAuth = true
|
|
|
+ data.forEach(sub => {
|
|
|
+ if (item.id === sub.id) {
|
|
|
+ item.hasAuth = true
|
|
|
+ } else {
|
|
|
+ item.hasAuth = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ this.auth = tmp
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async getResoureList () {
|
|
|
+ let token = localStorage.getItem('token')
|
|
|
+
|
|
|
+ let res = await this.$http({
|
|
|
+ method: 'post',
|
|
|
+ headers: {
|
|
|
+ token
|
|
|
+ },
|
|
|
+ url: '/user/scene/cooperation/sceneResourceList'
|
|
|
+ })
|
|
|
+ if (res.data.code !== 0) {
|
|
|
+ return this.handleClick()
|
|
|
+ }
|
|
|
+ let tmp = res.data.data.map(item => {
|
|
|
+ item.hasAuth = true
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ this.auth = tmp
|
|
|
},
|
|
|
async addCooperation () {
|
|
|
let token = localStorage.getItem('token')
|
|
@@ -60,24 +148,44 @@ export default {
|
|
|
if (!this.userName) {
|
|
|
return this.$toast.show('error', `${this.lang === 'en' ? 'Please enter user name.' : '请输入用户账号'}`)
|
|
|
}
|
|
|
+ let resourceIds = []
|
|
|
+
|
|
|
+ this.auth.forEach(item => {
|
|
|
+ if (item.hasAuth) {
|
|
|
+ resourceIds.push(item.id)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (resourceIds.length <= 0) {
|
|
|
+ return this.$toast.show('error', `${this.lang === 'en' ? 'Please select at least one.' : '请至少勾选一项权限'}`)
|
|
|
+ }
|
|
|
+
|
|
|
+ let url = this.cooType === 'scene' ? '/user/scene/cooperation/save' : '/user/camera/saveCooperationUser'
|
|
|
+ let params = {
|
|
|
+ userName: this.userName,
|
|
|
+ resourceIds: resourceIds.join(',')
|
|
|
+ }
|
|
|
+
|
|
|
+ this.cooType === 'scene' ? (params['sceneNum'] = this.sceneNum) : (params['cameraId'] = this.sceneNum)
|
|
|
|
|
|
let result = await this.$http({
|
|
|
method: 'post',
|
|
|
- data: {
|
|
|
- userName: this.userName,
|
|
|
- sceneNum: this.sceneNum
|
|
|
- },
|
|
|
+ data: params,
|
|
|
headers: {
|
|
|
token
|
|
|
},
|
|
|
- url: '/user/scene/cooperation/save'
|
|
|
+ url: url
|
|
|
})
|
|
|
let data = result.data
|
|
|
if (data.code === 0) {
|
|
|
- this.handleClick()
|
|
|
+ this.handleClick('getList')
|
|
|
this.$toast.show('success', this.toastCode['44'])
|
|
|
+ } else if (data.code === 3004) {
|
|
|
+ this.handleClick()
|
|
|
} else {
|
|
|
- return this.$toast.show('warn', this.toastCode[data.code])
|
|
|
+ return this.$toast.show('warn', this.toastCode[data.code], () => {
|
|
|
+ return false
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|