<template>
<el-dialog
:visible.sync="dialogVisible"
:title="`${title[operateType]}范围子规则`"
width="500"
:close-on-click-modal="false"
>
<el-form
:model="ruleForm"
:rules="rules"
ref="ruleFormRef"
label-width="100px"
class="base-ruleForm"
label-position="top"
size="mini"
:disabled="operateType == 'detail'"
>
<el-form-item label="规则名称" prop="nameCn">
<el-input v-model="ruleForm.nameCn"></el-input>
</el-form-item>
<el-form-item label="描述" prop="description">
<el-input
v-model="ruleForm.description"
type="textarea"
rows="3"
show-word-limit
maxlength="200"
></el-input>
</el-form-item>
</el-form>
<el-form
:model="customRuleForm"
:rules="customRules"
:inline="true"
ref="customRuleFormRef"
label-width="100px"
class="custom-ruleForm"
label-position="top"
size="mini"
:disabled="operateType == 'detail'"
>
<el-form-item label="发送人类型" prop="fromTypeList">
<el-select
v-model="customRuleForm.fromTypeList"
multiple
@change="dealSelectAll('fromTypeList')"
>
<el-option
v-for="opt in filterOptions.FromTypeEnum"
:key="opt.code"
:label="opt.info"
:value="opt.code"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="接收人类型" prop="toTypeList">
<el-select
v-model="customRuleForm.toTypeList"
multiple
@change="dealSelectAll('toTypeList')"
>
<el-option
v-for="opt in filterOptions.ToTypeEnum"
:key="opt.code"
:label="opt.info"
:value="opt.code"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="消息类型" prop="msgTypeList">
<el-select v-model="customRuleForm.msgTypeList" multiple>
<el-option
v-for="opt in filterOptions.MsgTypeEnum"
:key="opt.code"
:label="opt.info"
:value="opt.code"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="聊天类型" prop="chatTypeList">
<el-select
v-model="customRuleForm.chatTypeList"
multiple
@change="changeChatTypeList(false)"
>
<el-option
v-for="opt in filterOptions.ChatTypeEnum"
:key="opt.code"
:label="opt.info"
:value="opt.code"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="群聊群主" prop="roomOwnerIdList">
<el-select
v-model="customRuleForm.roomOwnerIdList"
multiple
filterable
remote
:remote-method="searchRoomOwner"
:popper-append-to-body="false"
>
<div
v-infinite-scroll="loadMoreRoomOwner"
:infinite-scroll-disabled="
roomOwnerIdScroll.loading || roomOwnerIdScroll.noMore
"
:infinite-scroll-distance="20"
style="max-height: 240px; overflow: auto"
>
<el-option
v-for="opt in filterOptions.RoomOwnerIdListEnum"
:key="opt.ownerId"
:label="opt.ownerName"
:value="opt.ownerId"
>
</el-option>
<div v-if="roomOwnerIdScroll.loading" class="loading-text">
加载中...
</div>
<div
v-if="!roomOwnerIdScroll.loading && !roomOwnerIdScroll.noMore"
class="loading-text"
>
下拉加载更多...
</div>
<div v-if="roomOwnerIdScroll.noMore" class="loading-text">
没有更多了
</div>
</div>
</el-select>
</el-form-item>
<el-form-item label="群主员工所属部门" prop="roomOwnerDeptList">
<el-select
v-model="customRuleForm.roomOwnerDeptList"
multiple
filterable
remote
:remote-method="searchDepts"
:popper-append-to-body="false"
>
<div
v-infinite-scroll="loadMoreDepts"
:infinite-scroll-disabled="
roomOwnerDeptScroll.loading || roomOwnerDeptScroll.noMore
"
:infinite-scroll-distance="20"
style="max-height: 240px; overflow: auto"
>
<el-option
v-for="opt in filterOptions.RoomOwnerDeptListEnum"
:key="opt.id"
:label="opt.name"
:value="opt.id"
>
</el-option>
<div v-if="roomOwnerDeptScroll.loading" class="loading-text">
加载中...
</div>
<div
v-if="!roomOwnerDeptScroll.loading && !roomOwnerDeptScroll.noMore"
class="loading-text"
>
下拉加载更多...
</div>
<div v-if="roomOwnerDeptScroll.noMore" class="loading-text">
没有更多了
</div>
</div>
</el-select>
</el-form-item>
<el-form-item label="群聊列表" prop="roomIdList">
<el-select
v-model="customRuleForm.roomIdList"
multiple
filterable
remote
:remote-method="searchRoom"
:popper-append-to-body="false"
@change="changeRoomId(false)"
>
<div
v-infinite-scroll="loadMoreRoom"
:infinite-scroll-disabled="
roomIdScroll.loading || roomIdScroll.noMore
"
:infinite-scroll-distance="20"
style="max-height: 240px; overflow: auto"
>
<el-option
v-for="opt in filterOptions.RoomIdListEnum"
:key="opt.roomId"
:label="opt.roomName"
:value="opt.roomId"
>
</el-option>
<div v-if="roomIdScroll.loading" class="loading-text">
加载中...
</div>
<div
v-if="!roomIdScroll.loading && !roomIdScroll.noMore"
class="loading-text"
>
下拉加载更多...
</div>
<div v-if="roomIdScroll.noMore" class="loading-text">
没有更多了
</div>
</div>
</el-select>
</el-form-item>
<el-form-item label="群聊成员白名单" prop="roomExcludeList">
<el-select
v-model="customRuleForm.roomExcludeList"
multiple
filterable
remote
:remote-method="searchRoomMember"
:popper-append-to-body="false"
>
<div
v-infinite-scroll="loadMoreRoomMember"
:infinite-scroll-disabled="
roomExcludeScroll.loading || roomExcludeScroll.noMore
"
:infinite-scroll-distance="20"
style="max-height: 240px; overflow: auto"
>
<el-option
v-for="opt in filterOptions.roomExcludeListEnum"
:key="opt.qwUserId"
:label="opt.name"
:value="opt.qwUserId"
>
</el-option>
<div v-if="roomExcludeScroll.loading" class="loading-text">
加载中...
</div>
<div
v-if="!roomExcludeScroll.loading && !roomExcludeScroll.noMore"
class="loading-text"
>
下拉加载更多...
</div>
<div v-if="roomExcludeScroll.noMore" class="loading-text">
没有更多了
</div>
</div>
</el-select>
</el-form-item>
<el-form-item label="群聊关注成员" prop="roomFocueList">
<el-select
v-model="customRuleForm.roomFocueList"
multiple
filterable
remote
:remote-method="searchRoomFocusMember"
:popper-append-to-body="false"
>
<div
v-infinite-scroll="loadMoreRoomFocusMember"
:infinite-scroll-disabled="
roomFocusScroll.loading || roomFocusScroll.noMore
"
:infinite-scroll-distance="20"
style="max-height: 240px; overflow: auto"
>
<el-option
v-for="opt in filterOptions.roomFocusListEnum"
:key="opt.qwUserId"
:label="opt.name"
:value="opt.qwUserId"
>
</el-option>
<div v-if="roomFocusScroll.loading" class="loading-text">
加载中...
</div>
<div
v-if="!roomFocusScroll.loading && !roomFocusScroll.noMore"
class="loading-text"
>
下拉加载更多...
</div>
<div v-if="roomFocusScroll.noMore" class="loading-text">
没有更多了
</div>
</div>
</el-select>
</el-form-item>
<el-form-item label="员工" prop="employeeList">
<private-cloud-member-select-new
style="width: 100%"
ref="privateCloudMemberUse"
placeholder="请选择员工"
:defaultCheckedKey="defalutValue.employeeList"
mode="member"
@selectedMembers="choseEmployeeList"
/>
</el-form-item>
<el-form-item label="部门" prop="deptList">
<private-cloud-member-select-new
style="width: 100%"
ref="privateCloudDeptUse"
mode="group"
placeholder="请选择部门"
:defaultCheckedKey="defalutValue.deptList"
@selectedGroups="choseDeptList"
/>
</el-form-item>
<el-form-item label="是否启用白名单" prop="enableWhite">
<el-switch
v-model="customRuleForm.enableWhite"
:active-value="1"
:inactive-value="0"
>
</el-switch>
</el-form-item>
<el-form-item label="正则表达式" prop="textRegex" style="width: 100%">
<vue-json-editor
v-model="customRuleForm.textRegex"
style="width: 100%"
mode="code"
lang="zh"
></vue-json-editor>
</el-form-item>
</el-form>
<div class="el-form-item el-form--label-top" style="margin-bottom: 0">
<label for="" class="el-form-item__label">扩展信息</label>
<div class="el-form-item__content extra-info">
<vue-json-editor
ref="jsonRef"
v-model="ext"
style="width: 100%"
mode="code"
lang="zh"
></vue-json-editor>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button
type="primary"
@click="save"
:disabled="operateType == 'detail'"
>
确定
</el-button>
</div>
</el-dialog>
</template>
<script>
import vueJsonEditor from 'vue-json-editor'
import archivesApi from '@/api/archive/index'
import dayjs from 'dayjs'
import { debounce } from 'lodash'
export default {
components: {
vueJsonEditor,
},
props: {
type: String,
},
data() {
return {
dialogVisible: false,
ruleForm: {
nameCn: '',
description: '',
},
rules: {
nameCn: [
{ required: true, message: '请输入活动名称', trigger: 'blur' },
{ max: 20, message: '长度不能超过20个字符', trigger: 'blur' },
],
},
formConfig: [],
customRuleForm: {
fromTypeList: null,
toTypeList: null,
msgTypeList: null,
chatTypeList: null,
roomOwnerIdList: null,
roomOwnerDeptList: null,
roomIdList: null,
roomExcludeList: null,
roomFocueList: null,
employeeList: null,
deptList: null,
enableWhite: 0,
textRegex: {},
},
filterOptions: {},
customRules: {},
ext: {},
hasJsonErrorFlag: false,
defalutValue: {
employeeList: [],
deptList: [],
},
isEdit: false,
operateType: null,
editIndex: null,
groupData: [],
title: {
add: '添加',
edit: '编辑',
detail: '查看',
},
roomOwnerIdScroll: {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
},
roomIdScroll: {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
},
roomOwnerDeptScroll: {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
},
roomExcludeScroll: {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
},
roomFocusScroll: {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
},
}
},
watch: {
dialogVisible(newVal) {
if (!newVal) {
this.resetFiled()
}
},
},
mounted() {},
methods: {
// 获取筛选项
async getFilter(filter, ruleType, row = null, index) {
this.operateType = ruleType
this.isEdit = ruleType === 'edit' ? true : false
if (this.isEdit) {
this.editIndex = index
}
this.filterOptions = { ...filter }
this.resetScrollData()
if (ruleType === 'add' && row) {
this.$set(this.ruleForm, 'nameCn', row.nameCn)
await this.getOwnerDeptList(true)
} else if (row) {
this.$set(this.ruleForm, 'nameCn', row.nameCn)
this.$set(this.ruleForm, 'description', row.description)
this.customRuleForm = { ...row }
this.customRuleForm.textRegex = JSON.parse(row.textRegex)
if (row.ext) {
this.ext = JSON.parse(row.ext)
}
this.defalutValue.employeeList = row.employeeListIds?.map(
(item) => `_${item}` || []
)
this.defalutValue.deptList = row.deptList ? [...row.deptList] : []
await this.getOwnerDeptList(true)
await this.changeChatTypeList(true)
await this.changeRoomId(true)
if (row.roomOwnerIdList) {
this.handleMissingRoomOwner(row.roomOwnerIdList)
}
if (row.roomIdList) {
this.handleMissingRoom(row.roomIdList)
}
if (row.roomOwnerDeptList) {
this.handleMissingDepts(row.roomOwnerDeptList)
}
if (row.roomExcludeList) {
this.handleMissingRoomMember(row.roomExcludeList)
}
if (row.roomFocueList) {
this.handleMissingFocusMember(row.roomFocueList)
}
}
},
dealSelectAll(type) {
if (this.customRuleForm[type]?.includes(0)) {
this.customRuleForm[type] = [0]
}
},
validChatType() {
let chatType = null
if (
this.customRuleForm.chatTypeList?.includes(0) ||
this.customRuleForm.chatTypeList == null ||
this.customRuleForm.chatTypeList?.length == 0
) {
chatType = null
} else if (
this.customRuleForm.chatTypeList?.includes(2) &&
this.customRuleForm.chatTypeList?.includes(4)
) {
chatType = null
} else if (this.customRuleForm.chatTypeList?.includes(2)) {
chatType = 2
} else if (this.customRuleForm.chatTypeList?.includes(4)) {
chatType = 4
}
return chatType
},
// 获取者群主列表
async getRoomOwnerList(init = false) {
if (this.roomOwnerIdScroll.loading) return
if (init) {
this.$set(this.filterOptions, 'RoomOwnerIdListEnum', [])
this.$set(this, 'roomOwnerIdScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
}
// 单聊或者为空时直接不去请求接口
if (
this.customRuleForm.chatTypeList == null ||
this.customRuleForm.chatTypeList?.length == 0
) {
return
}
if (
this.customRuleForm.chatTypeList?.length == 2 &&
this.customRuleForm.chatTypeList?.includes(1) &&
this.customRuleForm.chatTypeList?.includes(3)
) {
return
}
if (
this.customRuleForm.chatTypeList?.length == 1 &&
(this.customRuleForm.chatTypeList?.includes(1) ||
this.customRuleForm.chatTypeList?.includes(3))
) {
return
}
let chatType = this.validChatType()
this.roomOwnerIdScroll.loading = true
const params = {
page: this.roomOwnerIdScroll.page,
pageSize: this.roomOwnerIdScroll.pageSize,
ownerName: this.roomOwnerIdScroll.name?.trim(),
chatType: chatType,
}
await archivesApi
.getRoomList(params)
.then((res) => {
if (res.data.success) {
const data = res.data.data.list
const newData = [...this.filterOptions.RoomOwnerIdListEnum, ...data]
this.$set(this.filterOptions, 'RoomOwnerIdListEnum', newData)
this.filterOptions.RoomOwnerIdListEnum =
this.filterOptions.RoomOwnerIdListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.ownerId === item.ownerId)) {
acc.push(item)
}
return acc
}, [])
this.$set(this.roomOwnerIdScroll, 'loading', false)
this.$set(this.roomOwnerIdScroll, 'total', res.data.data.total)
this.$set(this.roomOwnerIdScroll, 'pages', res.data.data.pages)
this.$set(
this.roomOwnerIdScroll,
'noMore',
this.roomOwnerIdScroll.page >= this.roomOwnerIdScroll.pages
? true
: false
)
} else {
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
},
// 加载更多群主(滚动触发)
loadMoreRoomOwner: debounce(function () {
if (!this.roomOwnerIdScroll.loading && !this.roomOwnerIdScroll.noMore) {
this.roomOwnerIdScroll.page++
this.getRoomOwnerList()
}
}, 300),
// 群主搜索
searchRoomOwner: debounce(function (query) {
this.$set(this.roomOwnerIdScroll, 'name', query)
this.$set(this.roomOwnerIdScroll, 'page', 1)
this.getRoomOwnerList(true)
}, 500),
// 处理编辑时缺失的群主选项(回显)
async handleMissingRoomOwner(ownerIds) {
// 找出当前不在列表中的群ID
const missingIds = ownerIds.filter(
(ownerId) =>
!this.filterOptions.RoomOwnerIdListEnum.some(
(opt) => opt.ownerId === ownerId
)
)
if (missingIds.length > 0) {
try {
const res = await archivesApi.getRoomList({
ownerIds: missingIds,
pageSize: 10000,
page: 1,
})
if (res.data.success) {
// 将缺失的部门添加到列表开头
this.filterOptions.RoomOwnerIdListEnum = [
...res.data.data.list,
...this.filterOptions.RoomOwnerIdListEnum,
]
this.filterOptions.RoomOwnerIdListEnum =
this.filterOptions.RoomOwnerIdListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.ownerId === item.ownerId)) {
acc.push(item)
}
return acc
}, [])
}
} catch (e) {
console.error('加载缺失群主失败', e)
}
}
},
// 获取者群聊列表
async getRoomList(init = false) {
if (this.roomIdScroll.loading) return
if (init) {
this.$set(this.filterOptions, 'RoomIdListEnum', [])
this.$set(this, 'roomIdScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
}
if (
this.customRuleForm.chatTypeList == null ||
this.customRuleForm.chatTypeList?.length == 0
) {
return
}
if (
this.customRuleForm.chatTypeList?.length == 2 &&
this.customRuleForm.chatTypeList?.includes(1) &&
this.customRuleForm.chatTypeList?.includes(3)
) {
return
}
if (
this.customRuleForm.chatTypeList?.length == 1 &&
(this.customRuleForm.chatTypeList?.includes(1) ||
this.customRuleForm.chatTypeList?.includes(3))
) {
return
}
let chatType = this.validChatType()
this.roomIdScroll.loading = true
const params = {
page: this.roomIdScroll.page,
pageSize: this.roomIdScroll.pageSize,
roomName: this.roomIdScroll.name.trim(),
chatType: chatType,
}
await archivesApi
.getRoomList(params)
.then((res) => {
if (res.data.success) {
const data = res.data.data.list
this.filterOptions.RoomIdListEnum = [
...this.filterOptions.RoomIdListEnum,
...data,
]
this.filterOptions.RoomIdListEnum =
this.filterOptions.RoomIdListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.roomId === item.roomId)) {
acc.push(item)
}
return acc
}, [])
this.$set(this.roomIdScroll, 'loading', false)
this.$set(this.roomIdScroll, 'total', res.data.data.total)
this.$set(this.roomIdScroll, 'pages', res.data.data.pages)
this.$set(
this.roomIdScroll,
'noMore',
this.roomIdScroll.page >= this.roomIdScroll.pages ? true : false
)
console.log('获取群列表roomIdScroll', this.roomIdScroll)
} else {
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
},
// 加载更多群(滚动触发)
loadMoreRoom: debounce(function () {
if (!this.roomOwnerIdScroll.loading && !this.roomOwnerIdScroll.noMore) {
this.roomIdScroll.page++
this.getRoomList()
}
}, 300),
// 群搜索
searchRoom: debounce(function (query) {
this.roomIdScroll.name = query
this.$set(this.roomIdScroll, 'name', query)
this.$set(this.roomIdScroll, 'page', 1)
this.getRoomList(true)
}, 500),
// 处理编辑时缺失的群选项(回显)
async handleMissingRoom(roomIds) {
// 找出当前不在列表中的群ID
const missingIds = roomIds.filter(
(roomId) =>
!this.filterOptions.RoomIdListEnum.some(
(opt) => opt.roomId === roomId
)
)
if (missingIds.length > 0) {
try {
const res = await archivesApi.getRoomList({
roomIds: missingIds,
pageSize: 10000,
page: 1,
})
if (res.data.success) {
// 将缺失的部门添加到列表开头
this.filterOptions.RoomIdListEnum = [
...res.data.data.list,
...this.filterOptions.RoomIdListEnum,
]
this.filterOptions.RoomIdListEnum =
this.filterOptions.RoomIdListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.roomId === item.roomId)) {
acc.push(item)
}
return acc
}, [])
}
} catch (e) {
console.error('加载缺失群主失败', e)
}
}
},
// 选择群聊类型时
changeChatTypeList(isEditInit = true) {
if (this.customRuleForm.chatTypeList?.includes(0)) {
this.$set(this.customRuleForm, 'chatTypeList', [0])
}
if (
(this.customRuleForm.chatTypeList?.length == 1 &&
(this.customRuleForm.chatTypeList.includes(1) ||
this.customRuleForm.chatTypeList.includes(3))) ||
(this.customRuleForm.chatTypeList?.length == 2 &&
this.customRuleForm.chatTypeList?.includes(1) &&
this.customRuleForm.chatTypeList?.includes(3)) ||
this.customRuleForm.chatTypeList == null ||
this.customRuleForm.chatTypeList?.length == 0
) {
this.filterOptions.RoomOwnerIdListEnum = []
this.filterOptions.RoomIdListEnum = []
this.$set(this, 'roomOwnerIdScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
this.$set(this, 'roomIdScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
} else {
this.getRoomOwnerList(true)
this.getRoomList(true)
}
if (!isEditInit) {
this.customRuleForm.roomOwnerIdList = []
this.customRuleForm.roomIdList = []
this.customRuleForm.roomExcludeList = []
this.customRuleForm.roomFocueList = []
}
},
// 选择群列表
async changeRoomId(isEditInit = true) {
await this.getRoomMemberList(true)
await this.getRoomFocusMemberList(true)
if (!isEditInit) {
this.customRuleForm.roomExcludeList = []
this.customRuleForm.roomFocueList = []
}
},
// 白名单成员
async getRoomMemberList(init = false) {
if (this.customRuleForm.roomIdList?.length) {
if (this.roomExcludeScroll.loading) return
if (init) {
this.$set(this.filterOptions, 'roomExcludeListEnum', [])
this.$set(this, 'roomExcludeScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
}
const params = {
roomIds: this.customRuleForm.roomIdList,
name: this.roomExcludeScroll.name,
page: this.roomExcludeScroll.page,
pageSize: this.roomExcludeScroll.pageSize,
}
await archivesApi
.getRoomMemberList(params)
.then((res) => {
if (res.data.success) {
// const data = res.data.data
// this.$set(this.filterOptions, 'roomExcludeListEnum', data.list)
const data = res.data.data.list
this.filterOptions.roomExcludeListEnum = [
...this.filterOptions.roomExcludeListEnum,
...data,
]
this.filterOptions.roomExcludeListEnum =
this.filterOptions.roomExcludeListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.qwUserId === item.qwUserId)) {
acc.push(item)
}
return acc
}, [])
this.$set(this.roomExcludeScroll, 'loading', false)
this.$set(this.roomExcludeScroll, 'total', res.data.data.total)
this.$set(this.roomExcludeScroll, 'pages', res.data.data.pages)
this.$set(
this.roomExcludeScroll,
'noMore',
this.roomExcludeScroll.page >= this.roomExcludeScroll.pages
? true
: false
)
} else {
this.filterOptions.roomExcludeListEnum = []
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
} else {
this.filterOptions.roomExcludeListEnum = []
}
},
// 加载更多群成员(滚动触发)
loadMoreRoomMember: debounce(function () {
if (!this.roomExcludeScroll.loading && !this.roomExcludeScroll.noMore) {
this.roomExcludeScroll.page++
this.getRoomMemberList()
}
}, 300),
// 群成员搜索
searchRoomMember: debounce(function (query) {
this.$set(this.roomExcludeScroll, 'name', query)
this.$set(this.roomExcludeScroll, 'page', 1)
this.getRoomMemberList(true)
}, 500),
// 处理编辑时缺失的群成员选项(回显)
async handleMissingRoomMember(deptIds) {
// 找出当前不在列表中的群成员ID
const missingIds = deptIds.filter(
(qwUserId) =>
!this.filterOptions.roomExcludeListEnum.some(
(opt) => opt.qwUserId === qwUserId
)
)
if (missingIds.length > 0) {
try {
await archivesApi
.getRoomMemberList({
qwUserIds: missingIds,
pageSize: 10000,
page: 1,
})
.then((res) => {
if (res.data.success) {
this.filterOptions.roomExcludeListEnum = [
...res.data.data.list,
...this.filterOptions.roomExcludeListEnum,
]
this.filterOptions.roomExcludeListEnum =
this.filterOptions.roomExcludeListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.qwUserId === item.qwUserId)) {
acc.push(item)
}
return acc
}, [])
} else {
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
} catch (e) {
console.error('加载缺失部门失败', e)
}
}
},
// 关注成员
async getRoomFocusMemberList(init = false) {
if (this.customRuleForm.roomIdList?.length) {
if (this.roomFocusScroll.loading) return
if (init) {
this.$set(this.filterOptions, 'roomFocusListEnum', [])
this.$set(this, 'roomFocusScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
}
const params = {
roomIds: this.customRuleForm.roomIdList,
name: this.roomFocusScroll.name,
page: this.roomFocusScroll.page,
pageSize: this.roomFocusScroll.pageSize,
}
await archivesApi
.getRoomMemberList(params)
.then((res) => {
if (res.data.success) {
const data = res.data.data.list
this.filterOptions.roomFocusListEnum = [
...this.filterOptions.roomFocusListEnum,
...data,
]
this.filterOptions.roomFocusListEnum =
this.filterOptions.roomFocusListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.qwUserId === item.qwUserId)) {
acc.push(item)
}
return acc
}, [])
this.$set(this.roomFocusScroll, 'loading', false)
this.$set(this.roomFocusScroll, 'total', res.data.data.total)
this.$set(this.roomFocusScroll, 'pages', res.data.data.pages)
this.$set(
this.roomFocusScroll,
'noMore',
this.roomFocusScroll.page >= this.roomFocusScroll.pages
? true
: false
)
} else {
this.filterOptions.roomFocusListEnum = []
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
} else {
this.filterOptions.roomFocusListEnum = []
}
},
// 加载更多关注成员(滚动触发)
loadMoreRoomFocusMember: debounce(function () {
if (!this.roomFocusScroll.loading && !this.roomFocusScroll.noMore) {
this.roomFocusScroll.page++
this.getRoomFocusMemberList()
}
}, 300),
// 关注成员搜索
searchRoomFocusMember: debounce(function (query) {
this.$set(this.roomFocusScroll, 'name', query)
this.$set(this.roomFocusScroll, 'page', 1)
this.getRoomFocusMemberList(true)
}, 500),
// 处理编辑时缺失的关注成员选项(回显)
async handleMissingFocusMember(deptIds) {
// 找出当前不在列表中的群成员ID
const missingIds = deptIds.filter(
(qwUserId) =>
!this.filterOptions.roomFocusListEnum.some(
(opt) => opt.qwUserId === qwUserId
)
)
if (missingIds.length > 0) {
try {
await archivesApi
.getRoomMemberList({
qwUserIds: missingIds,
pageSize: 10000,
page: 1,
})
.then((res) => {
if (res.data.success) {
this.filterOptions.roomFocusListEnum = [
...res.data.data.list,
...this.filterOptions.roomFocusListEnum,
]
this.filterOptions.roomFocusListEnum =
this.filterOptions.roomFocusListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.qwUserId === item.qwUserId)) {
acc.push(item)
}
return acc
}, [])
} else {
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
} catch (e) {
console.error('加载缺失部门失败', e)
}
}
},
// 获取群主部门
async getOwnerDeptList(init = false) {
if (this.roomOwnerDeptScroll.loading) return
this.roomOwnerDeptScroll.loading = true
if (init) {
this.$set(this.filterOptions, 'RoomOwnerDeptListEnum', [])
this.$set(this, 'roomOwnerDeptScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
}
const params = {
page: this.roomOwnerDeptScroll.page,
pageSize: this.roomOwnerDeptScroll.pageSize,
name: this.roomOwnerDeptScroll.name?.trim(),
}
await archivesApi
.getOwnerDeptList(params)
.then((res) => {
if (res.data.success) {
const data = res.data.data
this.filterOptions.RoomOwnerDeptListEnum = [
...this.filterOptions.RoomOwnerDeptListEnum,
...res.data.data.list,
]
this.filterOptions.RoomOwnerDeptListEnum =
this.filterOptions.RoomOwnerDeptListEnum.reduce((acc, item) => {
if (!acc.some((i) => i.id === item.id)) {
acc.push(item)
}
return acc
}, [])
// this.$set(this.filterOptions, 'RoomOwnerDeptListEnum', newData)
this.$set(this.roomOwnerDeptScroll, 'loading', false)
this.$set(this.roomOwnerDeptScroll, 'total', res.data.data.total)
this.$set(this.roomOwnerDeptScroll, 'pages', res.data.data.pages)
this.$set(
this.roomOwnerDeptScroll,
'noMore',
this.roomOwnerDeptScroll.page >= this.roomOwnerDeptScroll.pages
? true
: false
)
} else {
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
},
// 加载更多部门(滚动触发)
loadMoreDepts: debounce(function () {
if (
!this.roomOwnerDeptScroll.loading &&
!this.roomOwnerDeptScroll.noMore
) {
this.roomOwnerDeptScroll.page++
this.getOwnerDeptList()
}
}, 300),
// 部门搜索
searchDepts: debounce(function (query) {
this.$set(this.roomOwnerDeptScroll, 'name', query)
this.$set(this.roomOwnerDeptScroll, 'page', 1)
this.getOwnerDeptList(true)
}, 500),
// 处理编辑时缺失的部门选项(回显)
async handleMissingDepts(deptIds) {
// 找出当前不在列表中的部门ID
const missingIds = deptIds.filter(
(id) =>
!this.filterOptions.RoomOwnerDeptListEnum.some((opt) => opt.id === id)
)
if (missingIds.length > 0) {
try {
await archivesApi
.getOwnerDeptList({ nodeIds: missingIds, pageSize: 10000, page: 1 })
.then((res) => {
if (res.data.success) {
this.filterOptions.RoomOwnerDeptListEnum = [
...res.data.data.list,
...this.filterOptions.RoomOwnerDeptListEnum,
]
this.filterOptions.RoomOwnerDeptListEnum =
this.filterOptions.RoomOwnerDeptListEnum.reduce(
(acc, item) => {
if (!acc.some((i) => i.id === item.id)) {
acc.push(item)
}
return acc
},
[]
)
} else {
this.$message.error(res.data.msg || '获取失败')
}
})
.catch(() => {})
} catch (e) {
console.error('加载缺失部门失败', e)
}
}
},
// 重置滚动加载相关数据
resetScrollData() {
this.$set(this.filterOptions, 'RoomOwnerIdListEnum', [])
this.$set(this, 'roomOwnerIdScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
this.$set(this.filterOptions, 'RoomIdListEnum', [])
this.$set(this, 'roomIdScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
this.$set(this.filterOptions, 'roomExcludeListEnum', [])
this.$set(this, 'roomExcludeScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
this.$set(this.filterOptions, 'roomFocusListEnum', [])
this.$set(this, 'roomFocusScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
this.$set(this.filterOptions, 'RoomOwnerDeptListEnum', [])
this.$set(this, 'roomOwnerDeptScroll', {
page: 1,
pageSize: 50,
loading: false,
noMore: false,
name: '',
total: 0,
pages: 0,
})
},
save() {
let isPass = true
this.$refs.ruleFormRef.validate((valid) => {
if (!valid) {
isPass = false
}
})
this.$refs.customRuleFormRef.validate((valid) => {
if (!valid) {
isPass = false
}
})
console.log('筛选项验证通过', this.ext)
if (this.$refs.jsonRef.error) {
isPass = false
this.$message.error('扩展信息JSON格式错误')
return
}
if (!isPass) {
return
}
const params = {
...this.customRuleForm,
...this.ruleForm,
textRegex: JSON.stringify(this.customRuleForm.textRegex),
ext: JSON.stringify(this.ext),
}
if (this.isEdit) {
params.gmtModified = dayjs().format('YYYY-MM-DD HH:mm:ss')
this.$emit('freshData', params, this.type, this.editIndex)
} else {
params.gmtCreate = dayjs().format('YYYY-MM-DD HH:mm:ss')
this.$emit('freshData', params, this.type)
}
this.resetFiled()
this.dialogVisible = false
console.log(isPass, 'isPass')
},
// 选择员工
choseEmployeeList(val) {
const { empList = [] } = val || {}
let checkedKey = []
let checkedEmployee = []
let checkedEmployeeIds = []
if (empList && empList.length) {
// 回显使用成员id
checkedKey = checkedKey.concat(empList.map((x) => `_${x.id}`))
checkedEmployee = checkedEmployee.concat(empList.map((x) => x.qwUserId))
checkedEmployeeIds = checkedEmployeeIds.concat(empList.map((x) => x.id))
}
this.defalutValue.employeeList = checkedKey
this.customRuleForm.employeeList = checkedEmployee
this.customRuleForm.employeeListIds = checkedEmployeeIds
},
// 选择部门
choseDeptList(val) {
const { deptList = [] } = val || {}
let checkedKey = []
// 员工回显
if (deptList && deptList.length) {
checkedKey = deptList.map((x) => x.nodeId)
}
this.defalutValue.deptList = checkedKey
this.customRuleForm.deptList = checkedKey
},
resetFiled() {
this.ruleForm = {
nameCn: '',
description: '',
}
this.customRuleForm = {
fromTypeList: null,
toTypeList: null,
msgTypeList: null,
chatTypeList: null,
roomOwnerIdList: null,
roomOwnerDeptList: null,
roomIdList: null,
roomExcludeList: null,
roomFocueList: null,
employeeList: null,
deptList: null,
enableWhite: 0,
textRegex: {},
employeeListIds: null,
}
this.defalutValue = {
employeeList: [],
deptList: [],
}
this.$refs.privateCloudMemberUse.reset()
this.$refs.privateCloudDeptUse.reset()
this.$refs.ruleFormRef.resetFields()
this.$refs.customRuleFormRef.resetFields()
this.ext = {}
},
},
}
</script>
<style lang="scss" scoped>
::v-deep .el-form-item__label {
line-height: 1;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
}
.extra-info {
display: flex;
margin-bottom: 10px;
.delete-icon {
margin-left: 10px;
}
}
::v-deep .el-dialog {
height: auto;
margin-top: 8vh;
.el-dialog__body {
height: 60vh;
overflow: auto;
}
}
.custom-ruleForm {
.el-form-item {
width: 30%;
.el-select {
width: 100%;
}
}
}
::v-deep a.jsoneditor-poweredBy {
display: none;
}
.loading-text {
padding: 4px 0;
text-align: center;
color: #999;
font-size: 12px;
}
</style>
优化代码
最新发布