fix:前端白名单问题调整 (#352)

* fix:修复前端白名单bug

* fix:添加保存和发布检查判断白名单设置是否有误
This commit is contained in:
chaorenluo 2024-07-17 11:25:37 +08:00 committed by GitHub
parent 9aec0fb1ea
commit 7ab790285f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 115 additions and 68 deletions

View File

@ -0,0 +1,11 @@
export const regexpMap = {
nd: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,
m: /^[1]([3-9])[0-9]{9}$/,
idcard: /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/,
strictIdcard:
/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
n: /^[0-9]+([.]{1}[0-9]+){0,1}$/,
e: /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/,
licensePlate:
/^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DFAG]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1})$/
}

View File

@ -16,6 +16,10 @@ export const getSpaceDetail = (workspaceId: string) => {
return axios.get(`/workspace/${workspaceId}`) return axios.get(`/workspace/${workspaceId}`)
} }
export const getMemberList = () => {
return axios.get('/workspace/member/list')
}
export const deleteSpace = (workspaceId: string) => { export const deleteSpace = (workspaceId: string) => {
return axios.delete(`/workspace/${workspaceId}`) return axios.delete(`/workspace/${workspaceId}`)
} }

View File

@ -31,6 +31,17 @@ const updateLogicConf = () => {
} }
} }
const updateWhiteConf = () => {
const baseConf = store.state.edit.schema.baseConf || {};
if (baseConf.passwordSwitch && !baseConf.password) {
return true;
}
if (baseConf.whitelistType!='ALL' && !baseConf.whitelist?.length) {
return true;
}
return false
}
const handlePublish = async () => { const handlePublish = async () => {
if (isPublishing.value) { if (isPublishing.value) {
return return
@ -46,6 +57,14 @@ const handlePublish = async () => {
return return
} }
if(updateWhiteConf()){
isPublishing.value = false
ElMessage.error('请检查问卷设置是否有误')
return
}
const saveData = buildData(store.state.edit.schema) const saveData = buildData(store.state.edit.schema)
if (!saveData.surveyId) { if (!saveData.surveyId) {
isPublishing.value = false isPublishing.value = false

View File

@ -63,6 +63,17 @@ const updateLogicConf = () => {
} }
} }
const updateWhiteConf = () => {
const baseConf = store.state.edit.schema.baseConf || {};
if (baseConf.passwordSwitch && !baseConf.password) {
return true;
}
if (baseConf.whitelistType!='ALL' && !baseConf.whitelist?.length) {
return true;
}
return false
}
const timerHandle = ref<NodeJS.Timeout | number | null>(null) const timerHandle = ref<NodeJS.Timeout | number | null>(null)
const triggerAutoSave = () => { const triggerAutoSave = () => {
if (autoSaveStatus.value === 'saving') { if (autoSaveStatus.value === 'saving') {
@ -114,6 +125,12 @@ const handleSave = async () => {
return return
} }
if(updateWhiteConf()){
isSaving.value = false
ElMessage.error('请检查问卷设置是否有误')
return
}
try { try {
const res: any = await saveData() const res: any = await saveData()
if (res.code === 200) { if (res.code === 200) {

View File

@ -9,16 +9,18 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, computed, defineProps, defineEmits, onMounted, nextTick } from 'vue' import { ref, computed, defineProps, defineEmits, onMounted } from 'vue'
import { useStore } from 'vuex'
import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant' import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant'
import {
getMemberList
} from '@/management/api/space'
import { ElMessage } from 'element-plus'
const props = defineProps({ const props = defineProps({
formConfig: Object, formConfig: Object,
}) })
const emit = defineEmits([FORM_CHANGE_EVENT_KEY]) const emit = defineEmits([FORM_CHANGE_EVENT_KEY])
const store = useStore();
const treeRef = ref(null) const treeRef = ref(null)
const treeData = ref([]) const treeData = ref([])
const defaultCheckedKeys = ref([]) const defaultCheckedKeys = ref([])
@ -30,57 +32,37 @@ const defaultProps = {
const handleChange = () => { const handleChange = () => {
const key = props.formConfig.key; const key = props.formConfig.key;
const userKeys = treeRef.value?.getCheckedKeys(true); const userKeys = treeRef.value?.getCheckedKeys(true);
if (userKeys.length > 100) {
ElMessage.error('最多添加100个')
return;
}
emit(FORM_CHANGE_EVENT_KEY, { key: key, value: userKeys }); emit(FORM_CHANGE_EVENT_KEY, { key: key, value: userKeys });
} }
const spaceDetail = computed(() => {
return store.state.list.spaceDetail
})
const selectCount = computed(() => { const selectCount = computed(() => {
return treeRef.value?.getCheckedKeys(true).length || 0 return treeRef.value?.getCheckedKeys(true).length || 0
}) })
const spaceMenus = computed(() => {
return store.state.list.spaceMenus
})
const getSpaceMenus = async () => { const getSpaceMenus = async () => {
await store.dispatch('list/getSpaceList') const res = await getMemberList();
spaceMenus.value.map((v) => { if (res.code != 200) {
if (v.id == "group") { ElMessage.error('获取空间成员列表失败');
const promiseList = [] }
v.children?.map((item) => { const data = res.data;
promiseList.push(store.dispatch('list/getSpaceDetail', item.id).then(() => { data.map((v) => {
const members = v.members || [];
treeData.value.push({ treeData.value.push({
id: item.id, id: v.ownerId,
label: item.name, label: v.name,
children: getChildren() children: members?.map(v => ({
}) id: v.userId,
label: v.role,
})) }))
}) })
Promise.all(promiseList).then(() => { })
nextTick(() => {
defaultCheckedKeys.value = props.formConfig.value; defaultCheckedKeys.value = props.formConfig.value;
})
})
}
})
}
const getChildren = () => {
const members = [];
if (spaceDetail.value?.members?.length > 0) {
spaceDetail.value.members.map(v => {
members.push({
id: v.userId,
label: v.username,
})
})
}
return members
} }

View File

@ -45,6 +45,8 @@
import { ref,nextTick } from 'vue' import { ref,nextTick } from 'vue'
import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant' import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant'
import { ElMessage } from 'element-plus'
import { regexpMap } from '@/common/regexpMap.ts'
const props = defineProps({ const props = defineProps({
formConfig: Object, formConfig: Object,
@ -56,12 +58,36 @@ const memberType = ref(props.formConfig.value[1] || 'MOBILE')
const whiteVisible = ref(false) const whiteVisible = ref(false)
const whiteTextarea = ref(whitelist.value.join(',')) const whiteTextarea = ref(whitelist.value.join(','))
const regularMap = {
MOBILE:regexpMap.m,
EMAIL:regexpMap.e
}
const checkValRule = (list) => {
let status = false;
if (list.length > 100) {
ElMessage.error('最多添加100个')
return true;
};
const pattern = regularMap[memberType.value];
if(!pattern) return false;
for (let i = 0; i < list.length; i++) {
if (!pattern.test(list[i])) {
status = true;
ElMessage.error('数据格式错误,请检查后重新输入~')
break;
}
}
return status;
}
const handleChange = () => { const handleChange = () => {
const keys = props.formConfig.keys; const keys = props.formConfig.keys;
const list = whiteTextarea.value ? whiteTextarea.value.split(',') : [] const list = whiteTextarea.value ? whiteTextarea.value.split(',') : []
if(checkValRule(list)) return
emit(FORM_CHANGE_EVENT_KEY, { key:keys[0], value: list }); emit(FORM_CHANGE_EVENT_KEY, { key:keys[0], value: list });
emit(FORM_CHANGE_EVENT_KEY, { key: keys[1], value: memberType.value }) emit(FORM_CHANGE_EVENT_KEY, { key: keys[1], value: memberType.value })
whiteVisible.value = false whiteVisible.value = false

View File

@ -6,18 +6,8 @@ import {
set as _set set as _set
} from 'lodash-es' } from 'lodash-es'
import { INPUT, RATES, QUESTION_TYPE } from '@/common/typeEnum.ts' import { INPUT, RATES, QUESTION_TYPE } from '@/common/typeEnum.ts'
import { regexpMap } from '@/common/regexpMap.ts'
const regexpMap = {
nd: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,
m: /^[1]([3-9])[0-9]{9}$/,
idcard: /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/,
strictIdcard:
/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
n: /^[0-9]+([.]{1}[0-9]+){0,1}$/,
e: /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/,
licensePlate:
/^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DFAG]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1})$/
}
const msgMap = { const msgMap = {
'*': '必填', '*': '必填',

View File

@ -33,9 +33,9 @@ export const getEncryptInfo = () => {
return axios.get('/clientEncrypt/getEncryptInfo') return axios.get('/clientEncrypt/getEncryptInfo')
} }
export const validate = ({ surveyPath,password, value }) => { export const validate = ({ surveyPath,password, whitelist }) => {
return axios.post(`/responseSchema/${surveyPath}/validate`, { return axios.post(`/responseSchema/${surveyPath}/validate`, {
password, password,
value whitelist
}) })
} }

View File

@ -71,19 +71,18 @@ const handleSubmit = async() => {
surveyPath:surveyPath.value surveyPath:surveyPath.value
} }
if (isValue.value) { if (isValue.value) {
params.value = state.value params.whitelist = state.value
} }
if(isPwd.value){ if(isPwd.value){
params.password = state.password params.password = state.password
} }
const res = await validate(params) const res = await validate(params)
if (res.code != 200) { if (res.code != 200) {
ElMessage.error(res.errmsg || '验证失败') ElMessage.error(res.errmsg || '验证失败')
return return
} }
whiteVisible.value = false whiteVisible.value = false
store.commit('setVerifyId', res.data.verifyId) store.commit('setWhiteData',params)
} }
watch(()=>baseConf.value, () => { watch(()=>baseConf.value, () => {

View File

@ -65,7 +65,7 @@ const renderData = computed(() => store.getters.renderData)
const submitConf = computed(() => store.state?.submitConf || {}) const submitConf = computed(() => store.state?.submitConf || {})
const logoConf = computed(() => store.state?.bottomConf || {}) const logoConf = computed(() => store.state?.bottomConf || {})
const surveyPath = computed(() => store.state?.surveyPath || '') const surveyPath = computed(() => store.state?.surveyPath || '')
const verifyId = computed(() => store.state?.verifyId || '') const whiteData = computed(() => store.state?.whiteData || {})
const validate = (cbk: (v: boolean) => void) => { const validate = (cbk: (v: boolean) => void) => {
const index = 0 const index = 0
@ -81,11 +81,8 @@ const normalizationRequestBody = () => {
surveyPath: surveyPath.value, surveyPath: surveyPath.value,
data: JSON.stringify(formValues), data: JSON.stringify(formValues),
difTime: Date.now() - enterTime, difTime: Date.now() - enterTime,
clientTime: Date.now() clientTime: Date.now(),
} ...whiteData.value
if(verifyId.value){
result.verifyId = verifyId.value
} }
if (encryptInfo?.encryptType) { if (encryptInfo?.encryptType) {

View File

@ -50,7 +50,7 @@ export default {
setRuleEgine(state, ruleEngine) { setRuleEgine(state, ruleEngine) {
state.ruleEngine = ruleEngine state.ruleEngine = ruleEngine
}, },
setVerifyId(state, verifyId) { setWhiteData(state, data) {
state.verifyId = verifyId state.whiteData = data
} }
} }

View File

@ -13,5 +13,7 @@ export default {
voteMap: {}, voteMap: {},
encryptInfo: null, encryptInfo: null,
ruleEngine: null, ruleEngine: null,
verifyId:'' whiteData: {
}
} }