feat: 优化引入、lint & format

This commit is contained in:
sudoooooo 2024-07-10 15:30:39 +08:00
parent 2ad6a77740
commit 5a8fab4e4b
27 changed files with 174 additions and 188 deletions

View File

@ -1,4 +1,4 @@
// 静态数据
// test静态数据,实际业务里无用
export const ruleConf = [
{
conditions: [

View File

@ -7,7 +7,7 @@ export enum QUESTION_TYPE {
BINARY_CHOICE = 'binary-choice',
RADIO_STAR = 'radio-star',
RADIO_NPS = 'radio-nps',
VOTE = 'vote',
VOTE = 'vote'
}
// 题目类型标签映射对象
@ -23,19 +23,13 @@ export const typeTagLabels: Record<QUESTION_TYPE, string> = {
}
// 输入类题型
export const INPUT = [
QUESTION_TYPE.TEXT,
QUESTION_TYPE.TEXTAREA
]
export const INPUT = [QUESTION_TYPE.TEXT, QUESTION_TYPE.TEXTAREA]
// 选择类题型分类
export const NORMAL_CHOICES = [
QUESTION_TYPE.RADIO,
QUESTION_TYPE.CHECKBOX
]
export const NORMAL_CHOICES = [QUESTION_TYPE.RADIO, QUESTION_TYPE.CHECKBOX]
// 选择类题型分类
export const CHOICES = [
export const CHOICES = [
QUESTION_TYPE.RADIO,
QUESTION_TYPE.CHECKBOX,
QUESTION_TYPE.BINARY_CHOICE,
@ -43,8 +37,4 @@ export const CHOICES = [
]
// 评分题题型分类
export const RATES = [
QUESTION_TYPE.RADIO_STAR,
QUESTION_TYPE.RADIO_NPS
]
export const RATES = [QUESTION_TYPE.RADIO_STAR, QUESTION_TYPE.RADIO_NPS]

View File

@ -71,4 +71,4 @@ export const getCollaboratorPermissions = (surveyId: string) => {
surveyId
}
})
}
}

View File

@ -58,18 +58,22 @@ const tabArr = [
}
]
const tabs = ref([])
watch(() => store.state.cooperPermissions, (newVal) => {
tabs.value = []
//
if (newVal.includes(SurveyPermissions.SurveyManage)) {
tabs.value.push(tabArr[0])
tabs.value.push(tabArr[1])
}
//
if (newVal.includes(SurveyPermissions.DataManage)) {
tabs.value.push(tabArr[2])
}
}, { immediate: true })
watch(
() => store.state.cooperPermissions,
(newVal) => {
tabs.value = []
//
if (newVal.includes(SurveyPermissions.SurveyManage)) {
tabs.value.push(tabArr[0])
tabs.value.push(tabArr[1])
}
//
if (newVal.includes(SurveyPermissions.DataManage)) {
tabs.value.push(tabArr[2])
}
},
{ immediate: true }
)
</script>
<style lang="scss" scoped>
.nav {

View File

@ -1,4 +1,9 @@
import { createRouter, createWebHistory, type RouteLocationNormalized, type NavigationGuardNext } from 'vue-router'
import {
createRouter,
createWebHistory,
type RouteLocationNormalized,
type NavigationGuardNext
} from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { useStore, type Store } from 'vuex'
import { SurveyPermissions } from '@/management/utils/types/workSpace'
@ -161,33 +166,43 @@ router.beforeEach(async (to, from, next) => {
const userStore = useUserStore()
// 初始化用户信息
if (!userStore?.initialized) {
await userStore.init();
await userStore.init()
}
// 更新页面标题
if (to.meta.title) {
document.title = to.meta.title as string;
document.title = to.meta.title as string
}
if (to.meta.needLogin) {
await handleLoginGuard(to, from, next, store);
await handleLoginGuard(to, from, next, store)
} else {
next();
next()
}
});
})
async function handleLoginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext, store: Store<any>) {
const userStore = useUserStore();
async function handleLoginGuard(
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
store: Store<any>
) {
const userStore = useUserStore()
if (userStore?.hasLogined) {
await handlePermissionsGuard(to, from, next, store);
await handlePermissionsGuard(to, from, next, store)
} else {
next({
name: 'login',
query: { redirect: encodeURIComponent(to.path) },
});
query: { redirect: encodeURIComponent(to.path) }
})
}
}
async function handlePermissionsGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext, store: Store<any>) {
async function handlePermissionsGuard(
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
store: Store<any>
) {
const currSurveyId = to?.params?.id || ''
const prevSurveyId = from?.params?.id || ''
// 如果跳转页面不存在surveyId 或者不需要页面权限,则直接跳转
@ -198,21 +213,19 @@ async function handlePermissionsGuard(to: RouteLocationNormalized, from: RouteLo
if (currSurveyId !== prevSurveyId) {
await store.dispatch('fetchCooperPermissions', currSurveyId)
if (hasRequiredPermissions(to.meta.permissions as string[], store.state.cooperPermissions)) {
next();
next()
} else {
ElMessage.warning('您没有该问卷的相关协作权限');
next({ name: 'survey' });
ElMessage.warning('您没有该问卷的相关协作权限')
next({ name: 'survey' })
}
} else {
next();
next()
}
}
}
function hasRequiredPermissions(requiredPermissions: string[], userPermissions: string[]) {
return requiredPermissions.some(permission => userPermissions.includes(permission));
return requiredPermissions.some((permission) => userPermissions.includes(permission))
}
export default router

View File

@ -12,7 +12,7 @@ export default createStore({
mutations,
actions,
modules: {
edit,
edit
// user,
// list
}

View File

@ -1,9 +1,11 @@
import { defineStore } from 'pinia'
import { type Ref, ref, reactive, toRef, computed } from 'vue'
import { getSurveyById } from '@/management/api/survey'
import { defineStore } from 'pinia'
import { merge as _merge, cloneDeep as _cloneDeep, set as _set } from 'lodash-es'
import { getSurveyById } from '@/management/api/survey'
import { getNewField } from '@/management/utils'
import submitFormConfig from '@/management/config/setterConfig/submitConfig'
import questionLoader from '@/materials/questions/questionLoader'
const innerMetaConfig = {
@ -78,8 +80,6 @@ function useInitializeSchema(surveyId: Ref<string>) {
schema.submitConf = _merge({}, schema.submitConf, codeData.submitConf)
schema.questionDataList = codeData.questionDataList || []
schema.logicConf = codeData.logicConf
console.log(metaData, codeData)
}
async function getSchemaFromRemote() {
@ -205,6 +205,17 @@ function useCurrentEdit({
return key
})
const currentEditMeta = computed(() => {
if (currentEditOne.value === null) {
return null
} else if (innerMetaConfig[currentEditOne.value as keyof typeof innerMetaConfig]) {
return innerMetaConfig[currentEditOne.value as keyof typeof innerMetaConfig]
} else {
const questionType = questionDataList.value?.[currentEditOne.value]?.type
return questionLoader.getMeta(questionType)
}
})
const moduleConfig = computed(() => {
if (currentEditOne.value === null) {
return null
@ -231,17 +242,6 @@ function useCurrentEdit({
return currentEditMeta.value?.formConfig || []
})
const currentEditMeta = computed(() => {
if (currentEditOne.value === null) {
return null
} else if (innerMetaConfig[currentEditOne.value as keyof typeof innerMetaConfig]) {
return innerMetaConfig[currentEditOne.value as keyof typeof innerMetaConfig]
} else {
const questionType = questionDataList.value?.[currentEditOne.value]?.type
return questionLoader.getMeta(questionType)
}
})
function setCurrentEditOne(data: any) {
currentEditOne.value = data
}
@ -267,6 +267,7 @@ export const useEditStore = defineStore('edit', () => {
const schemaUpdateTime = ref(Date.now())
const { schema, initSchema, getSchemaFromRemote } = useInitializeSchema(surveyId)
const questionDataList = toRef(schema, 'questionDataList')
function setQuestionDataList(data: any) {
schema.questionDataList = data
}

View File

@ -1,12 +1,13 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/src/message.scss'
import { defineStore } from 'pinia'
import { CODE_MAP } from '@/management/api/base'
import { getSurveyList as getSurveyListReq } from '@/management/api/survey'
import { useWorkSpaceStore } from './workSpace'
import { ref, computed } from 'vue'
function useSearchSurvey() {
const searchVal = ref('')

View File

@ -1,7 +1,5 @@
// Pinia Store
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { defineStore } from 'pinia'
const USER_INFO_KEY = 'surveyUserInfo'
export const useUserStore = defineStore('user', () => {
@ -41,11 +39,11 @@ export const useUserStore = defineStore('user', () => {
})
)
}
const logout = () => {
const logout = () => {
userInfo.value = null
hasLogined.value = false
localStorage.removeItem(USER_INFO_KEY)
}
return { userInfo, hasLogined, loginTime, initialized, init, login, logout }
})
})

View File

@ -1,5 +1,6 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/src/message.scss'
@ -11,6 +12,7 @@ import {
getSpaceList as getSpaceListReq,
getSpaceDetail as getSpaceDetailReq
} from '@/management/api/space'
import { SpaceType } from '@/management/utils/types/workSpace'
import {
type SpaceDetail,

View File

@ -39,19 +39,20 @@ export const getQuestionByType = (type, fields) => {
const questionMeta = questionLoader.getMeta(type)
const { attrs } = questionMeta
let newQuestion = defaultQuestionConfig
if( attrs ) {
if (attrs) {
let questionSchema = {}
attrs.forEach(element => {
attrs.forEach((element) => {
questionSchema[element.name] = element.defaultValue
});
})
newQuestion = questionSchema
} else {
newQuestion = defaultQuestionConfig
newQuestion.type = type
}
newQuestion.field = getNewField(fields) // 动态生成题目id
if('options ' in newQuestion) { // 动态更新选项的hash-id
if ('options' in newQuestion) {
// 动态更新选项的hash-id
const hashList = []
for (const option of newQuestion.options) {
const hash = generateHash(hashList)
@ -59,7 +60,7 @@ export const getQuestionByType = (type, fields) => {
option.hash = hash
}
}
return newQuestion
}

View File

@ -34,7 +34,7 @@ export interface SpaceDetail {
export type SpaceItem = Required<Omit<SpaceDetail, 'members'>> & {
createDate: string
curStatus: { date: number, status: string }
curStatus: { date: number; status: string }
memberTotal: number
currentUserRole: string
owner: string

View File

@ -111,20 +111,10 @@ export default defineComponent({
editConfigure={questionMeta?.editConfigure}
onChange={this.onChange}
>
<dynamicComponent
readonly
{...props}
onBlur={this.onBlur}
onFocus={this.onFocus}
/>
<dynamicComponent readonly {...props} onBlur={this.onBlur} onFocus={this.onFocus} />
</EditOptions>
) : (
<dynamicComponent
readonly
{...props}
onBlur={this.onBlur}
onFocus={this.onFocus}
/>
<dynamicComponent readonly {...props} onBlur={this.onBlur} onFocus={this.onFocus} />
)}
</div>
</div>

View File

@ -53,25 +53,25 @@ const meta = {
description: '这是用于描述选项',
defaultValue: [
{
"text": "对",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115019"
text: '对',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
},
{
"text": "错",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115020"
text: '错',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
}
]
},
}
],
formConfig: [basicConfig],
editConfigure: {

View File

@ -53,22 +53,22 @@ const meta = {
description: '这是用于描述选项',
defaultValue: [
{
"text": "选项1",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115019"
text: '选项1',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
},
{
"text": "选项2",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115020"
text: '选项2',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
}
]
},

View File

@ -19,7 +19,7 @@
}
}
.question-block {
padding: 0!important;
padding: 0 !important;
}
.radio-nps-hover {
.rate-item {

View File

@ -53,29 +53,27 @@ const meta = {
description: '这是用于描述选项',
defaultValue: [
{
"text": "选项1",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115019"
text: '选项1',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
},
{
"text": "选项2",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115020"
text: '选项2',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
}
]
},
],
formConfig: [
basicConfig,
}
],
formConfig: [basicConfig],
editConfigure: {
optionEdit: {
show: true

View File

@ -63,14 +63,14 @@ const meta = {
name: 'starStyle',
propType: String,
description: '',
defaultValue: 'star',
defaultValue: 'star'
},
{
name: 'rangeConfig',
propType: Object,
description: '这是用于描述评分高级设置',
defaultValue: {}
},
}
],
formConfig: [
basicConfig,

View File

@ -53,22 +53,22 @@ const meta = {
description: '这是用于描述选项',
defaultValue: [
{
"text": "选项1",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115019"
text: '选项1',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
},
{
"text": "选项2",
"imageUrl": "",
"others": false,
"mustOthers": false,
"othersKey": "",
"placeholderDesc": "",
"hash": "115020"
text: '选项2',
imageUrl: '',
others: false,
mustOthers: false,
othersKey: '',
placeholderDesc: '',
hash: ''
}
]
},

View File

@ -199,7 +199,7 @@ const generateOthersKeyMap = (question) => {
let othersKeyMap = undefined
if (RATES.includes(type)) {
const { rangeConfig } = question
const { rangeConfig } = question
othersKeyMap = {}
for (const key in rangeConfig) {
if (rangeConfig[key].isShowInput) {
@ -207,7 +207,7 @@ const generateOthersKeyMap = (question) => {
}
}
} else if (type?.includes(QUESTION_TYPE.RADIO) || type?.includes(QUESTION_TYPE.CHECKBOX)) {
const { options } = question
const { options } = question
othersKeyMap = {}
options
.filter((op) => op.others)

View File

@ -57,8 +57,10 @@ const questionConfig = computed(() => {
moduleConfig.othersValue = unref(othersValue)
}
if (
RATES.includes(type) && rest?.rangeConfig &&
Object.keys(rest?.rangeConfig).filter((index) => rest?.rangeConfig[index].isShowInput).length > 0
RATES.includes(type) &&
rest?.rangeConfig &&
Object.keys(rest?.rangeConfig).filter((index) => rest?.rangeConfig[index].isShowInput).length >
0
) {
let { rangeConfig, othersValue } = useShowInput(field)
moduleConfig.rangeConfig = unref(rangeConfig)

View File

@ -5,7 +5,6 @@ import router from './router'
import store from './store'
import { createPinia } from 'pinia'
const app = createApp(App)
const pinia = createPinia()
@ -17,5 +16,4 @@ app.use(store)
app.use(pinia)
app.use(router)
app.mount('#app')

View File

@ -7,9 +7,7 @@
</div>
</template>
<script setup>
</script>
<script setup></script>
<style scoped>
.container {

View File

@ -18,15 +18,8 @@ const surveyStore = useSurveyStore()
const loadData = (res: any, surveyPath: string) => {
if (res.code === 200) {
const data = res.data
const {
bannerConf,
baseConf,
bottomConf,
dataConf,
skinConf,
submitConf,
logicConf
} = data.code
const { bannerConf, baseConf, bottomConf, dataConf, skinConf, submitConf, logicConf } =
data.code
const questionData = {
bannerConf,
baseConf,
@ -62,7 +55,7 @@ const getDetail = async (surveyPath: string) => {
} else {
const res: any = await getPublishedSurveyInfo({ surveyPath })
loadData(res, surveyPath)
surveyStore.getEncryptInfo();
surveyStore.getEncryptInfo()
}
} catch (error: any) {
console.log(error)

View File

@ -73,7 +73,7 @@ const validate = (cbk: (v: boolean) => void) => {
const normalizationRequestBody = () => {
const enterTime = surveyStore.enterTime
const encryptInfo = surveyStore.encryptInfo as any;
const encryptInfo = surveyStore.encryptInfo as any
const formValues = store.state.formValues
const result: any = {
@ -82,7 +82,7 @@ const normalizationRequestBody = () => {
difTime: Date.now() - enterTime,
clientTime: Date.now()
}
if (encryptInfo?.encryptType) {
result.encryptType = encryptInfo.encryptType
result.data = encrypt[result.encryptType as 'rsa']({

View File

@ -19,12 +19,9 @@ const VOTE_INFO_KEY = 'voteinfo'
import router from '../router'
export default {
// 初始化
init(
{ commit, dispatch },
{ bannerConf, baseConf, bottomConf, dataConf, skinConf, submitConf }
) {
init({ commit, dispatch }, { bannerConf, baseConf, bottomConf, dataConf, skinConf, submitConf }) {
const surveyStore = useSurveyStore()
surveyStore.setEnterTime();
surveyStore.setEnterTime()
const { begTime, endTime, answerBegTime, answerEndTime } = baseConf
const { msgContent } = submitConf
const now = Date.now()

View File

@ -1,8 +1,8 @@
// 问卷相关的Pinia Store
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { isMobile as isInMobile } from '@/render/utils/index'
import { getEncryptInfo as getEncryptInfoApi } from '@/render/api/survey'
import { getEncryptInfo as getEncryptInfoApi } from '@/render/api/survey'
/**
* CODE_MAP不从management引入在dev阶段会导致B端 router被加载进而导致C端路由被添加 baseUrl: /management
@ -13,12 +13,12 @@ const CODE_MAP = {
NO_AUTH: 403
}
export const useSurveyStore = defineStore('survey', () => {
const surveyPath = ref('');
const surveyPath = ref('')
const isMobile = ref(isInMobile())
const enterTime = ref(0)
const encryptInfo = ref(null)
const setSurveyPath = ( data) => {
const setSurveyPath = (data) => {
surveyPath.value = data
}
@ -26,7 +26,7 @@ export const useSurveyStore = defineStore('survey', () => {
enterTime.value = Date.now()
}
const getEncryptInfo = async() => {
const getEncryptInfo = async () => {
try {
const res = await getEncryptInfoApi()
if (res.code === CODE_MAP.SUCCESS) {
@ -47,4 +47,4 @@ export const useSurveyStore = defineStore('survey', () => {
setEnterTime,
getEncryptInfo
}
})
})