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 = [ export const ruleConf = [
{ {
conditions: [ conditions: [

View File

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

View File

@ -58,7 +58,9 @@ const tabArr = [
} }
] ]
const tabs = ref([]) const tabs = ref([])
watch(() => store.state.cooperPermissions, (newVal) => { watch(
() => store.state.cooperPermissions,
(newVal) => {
tabs.value = [] tabs.value = []
// //
if (newVal.includes(SurveyPermissions.SurveyManage)) { if (newVal.includes(SurveyPermissions.SurveyManage)) {
@ -69,7 +71,9 @@ watch(() => store.state.cooperPermissions, (newVal) => {
if (newVal.includes(SurveyPermissions.DataManage)) { if (newVal.includes(SurveyPermissions.DataManage)) {
tabs.value.push(tabArr[2]) tabs.value.push(tabArr[2])
} }
}, { immediate: true }) },
{ immediate: true }
)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.nav { .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 type { RouteRecordRaw } from 'vue-router'
import { useStore, type Store } from 'vuex' import { useStore, type Store } from 'vuex'
import { SurveyPermissions } from '@/management/utils/types/workSpace' import { SurveyPermissions } from '@/management/utils/types/workSpace'
@ -161,33 +166,43 @@ router.beforeEach(async (to, from, next) => {
const userStore = useUserStore() const userStore = useUserStore()
// 初始化用户信息 // 初始化用户信息
if (!userStore?.initialized) { if (!userStore?.initialized) {
await userStore.init(); await userStore.init()
} }
// 更新页面标题 // 更新页面标题
if (to.meta.title) { if (to.meta.title) {
document.title = to.meta.title as string; document.title = to.meta.title as string
} }
if (to.meta.needLogin) { if (to.meta.needLogin) {
await handleLoginGuard(to, from, next, store); await handleLoginGuard(to, from, next, store)
} else { } else {
next(); next()
} }
}); })
async function handleLoginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext, store: Store<any>) { async function handleLoginGuard(
const userStore = useUserStore(); to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
store: Store<any>
) {
const userStore = useUserStore()
if (userStore?.hasLogined) { if (userStore?.hasLogined) {
await handlePermissionsGuard(to, from, next, store); await handlePermissionsGuard(to, from, next, store)
} else { } else {
next({ next({
name: 'login', 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 currSurveyId = to?.params?.id || ''
const prevSurveyId = from?.params?.id || '' const prevSurveyId = from?.params?.id || ''
// 如果跳转页面不存在surveyId 或者不需要页面权限,则直接跳转 // 如果跳转页面不存在surveyId 或者不需要页面权限,则直接跳转
@ -198,21 +213,19 @@ async function handlePermissionsGuard(to: RouteLocationNormalized, from: RouteLo
if (currSurveyId !== prevSurveyId) { if (currSurveyId !== prevSurveyId) {
await store.dispatch('fetchCooperPermissions', currSurveyId) await store.dispatch('fetchCooperPermissions', currSurveyId)
if (hasRequiredPermissions(to.meta.permissions as string[], store.state.cooperPermissions)) { if (hasRequiredPermissions(to.meta.permissions as string[], store.state.cooperPermissions)) {
next(); next()
} else { } else {
ElMessage.warning('您没有该问卷的相关协作权限'); ElMessage.warning('您没有该问卷的相关协作权限')
next({ name: 'survey' }); next({ name: 'survey' })
} }
} else { } else {
next(); next()
} }
} }
} }
function hasRequiredPermissions(requiredPermissions: string[], userPermissions: string[]) { function hasRequiredPermissions(requiredPermissions: string[], userPermissions: string[]) {
return requiredPermissions.some(permission => userPermissions.includes(permission)); return requiredPermissions.some((permission) => userPermissions.includes(permission))
} }
export default router export default router

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
// Pinia Store
import { defineStore } from 'pinia'
import { ref } from 'vue' import { ref } from 'vue'
import { defineStore } from 'pinia'
const USER_INFO_KEY = 'surveyUserInfo' const USER_INFO_KEY = 'surveyUserInfo'
export const useUserStore = defineStore('user', () => { export const useUserStore = defineStore('user', () => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -73,7 +73,7 @@ const validate = (cbk: (v: boolean) => void) => {
const normalizationRequestBody = () => { const normalizationRequestBody = () => {
const enterTime = surveyStore.enterTime const enterTime = surveyStore.enterTime
const encryptInfo = surveyStore.encryptInfo as any; const encryptInfo = surveyStore.encryptInfo as any
const formValues = store.state.formValues const formValues = store.state.formValues
const result: any = { const result: any = {

View File

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

View File

@ -1,6 +1,6 @@
// 问卷相关的Pinia Store
import { defineStore } from 'pinia'
import { ref } from 'vue' import { ref } from 'vue'
import { defineStore } from 'pinia'
import { isMobile as isInMobile } from '@/render/utils/index' import { isMobile as isInMobile } from '@/render/utils/index'
import { getEncryptInfo as getEncryptInfoApi } from '@/render/api/survey' import { getEncryptInfo as getEncryptInfoApi } from '@/render/api/survey'
@ -13,7 +13,7 @@ const CODE_MAP = {
NO_AUTH: 403 NO_AUTH: 403
} }
export const useSurveyStore = defineStore('survey', () => { export const useSurveyStore = defineStore('survey', () => {
const surveyPath = ref(''); const surveyPath = ref('')
const isMobile = ref(isInMobile()) const isMobile = ref(isInMobile())
const enterTime = ref(0) const enterTime = ref(0)
const encryptInfo = ref(null) const encryptInfo = ref(null)