Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fc0e7a334 | ||
|
|
4959e402b7 | ||
|
|
aed501d308 | ||
|
|
de50ca5f66 | ||
|
|
f2db16447d | ||
|
|
e08155d2cc | ||
|
|
c59a2587dd | ||
|
|
cda60022be | ||
|
|
f0f2d2b8ed | ||
|
|
d4b7f659a1 |
No files matched your search
Vendored
+3
-1
@@ -8,6 +8,7 @@ export {}
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
Copyright: typeof import('./src/components/Copyright.vue')['default']
|
||||
Editor: typeof import('./src/components/Editor.vue')['default']
|
||||
ImagePreviewer: typeof import('./src/components/ImagePreviewer.vue')['default']
|
||||
ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
|
||||
RegularPage: typeof import('./src/components/RegularPage.vue')['default']
|
||||
@@ -23,7 +24,6 @@ declare module 'vue' {
|
||||
TFormItem: typeof import('tdesign-vue-next')['FormItem']
|
||||
THeader: typeof import('tdesign-vue-next')['Header']
|
||||
TIcon: typeof import('tdesign-vue-next')['Icon']
|
||||
TImage: typeof import('tdesign-vue-next')['Image']
|
||||
TImageViewer: typeof import('tdesign-vue-next')['ImageViewer']
|
||||
TInput: typeof import('tdesign-vue-next')['Input']
|
||||
TInputNumber: typeof import('tdesign-vue-next')['InputNumber']
|
||||
@@ -33,10 +33,12 @@ declare module 'vue' {
|
||||
TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm']
|
||||
TRadioButton: typeof import('tdesign-vue-next')['RadioButton']
|
||||
TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
|
||||
TSelect: typeof import('tdesign-vue-next')['Select']
|
||||
TSelectInput: typeof import('tdesign-vue-next')['SelectInput']
|
||||
TSpace: typeof import('tdesign-vue-next')['Space']
|
||||
TTable: typeof import('tdesign-vue-next')['Table']
|
||||
TTag: typeof import('tdesign-vue-next')['Tag']
|
||||
TTextarea: typeof import('tdesign-vue-next')['Textarea']
|
||||
TUpload: typeof import('tdesign-vue-next')['Upload']
|
||||
}
|
||||
}
|
||||
@@ -1 +1,15 @@
|
||||
/// <reference types="vite/client" />
|
||||
import { SlateDescendant, SlateElement, SlateText, Toolbar } from '@wangeditor/editor'
|
||||
|
||||
declare module '@wangeditor/editor' {
|
||||
// 扩展 Text
|
||||
interface SlateText {
|
||||
text: string
|
||||
}
|
||||
|
||||
// 扩展 Element
|
||||
interface SlateElement {
|
||||
type: string
|
||||
children: SlateDescendant[]
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -6,7 +6,7 @@ export const searchArticlesRequest = (articleFilterParam:ArticleSearchFilter ) =
|
||||
return httpClient.get<PageResult<Article>>('/articles',articleFilterParam)
|
||||
}
|
||||
|
||||
export const createArticlesRequest = (article: CreateArticleRequest) => {
|
||||
export const createArticle = (article: CreateArticleRequest) => {
|
||||
return httpClient.post<Article>('/articles',article)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export const searchArticlesByIdRequest = (id: string) => {
|
||||
return httpClient.get<Article>(`/articles/${id}`)
|
||||
}
|
||||
|
||||
export const updateArticlesByIdRequest = (id: string,article:CreateArticleRequest) => {
|
||||
export const updateArticle = (id: string, article:CreateArticleRequest) => {
|
||||
return httpClient.put<Article>(`/articles/${id}`,article)
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -1,19 +1,25 @@
|
||||
import httpClient from './httpClient'
|
||||
import type { CarousalResult, CreateCarousalsRequest, SearchCarousalsFilter } from '@/model/carousals'
|
||||
import type {
|
||||
CarousalResult, Carousals,
|
||||
CreateCarousalsRequest,
|
||||
SearchCarousalsFilter,
|
||||
UpdateCarousalsRequest
|
||||
} from '@/model/carousals'
|
||||
import type { PageResult } from '@/model/base'
|
||||
import type {UnwrapRef} from "vue";
|
||||
|
||||
export const createCarousal = (createCarousalsRequest: CreateCarousalsRequest) => {
|
||||
return httpClient.post<PageResult<CarousalResult>>('/carousals', createCarousalsRequest)
|
||||
}
|
||||
|
||||
export const searchCarousals = (searchCarousalsFilter: SearchCarousalsFilter) => {
|
||||
return httpClient.get<PageResult<CarousalResult>>('/carousals',searchCarousalsFilter)
|
||||
return httpClient.get<PageResult<Carousals>>('/carousals',searchCarousalsFilter)
|
||||
}
|
||||
export const getCarousalItem = (id:string) => {
|
||||
return httpClient.get<CarousalResult>(`/carousals/${id}`)
|
||||
}
|
||||
|
||||
export const updateCarousalItem = (id:number,updateCarousalsRequest: CreateCarousalsRequest) => {
|
||||
export const updateCarousalItem = (id: UnwrapRef<UpdateCarousalsRequest["id"]> | undefined, updateCarousalsRequest: CreateCarousalsRequest) => {
|
||||
return httpClient.put<CarousalResult>(`/carousals/${id}`,updateCarousalsRequest)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ import httpClient from '@/api/httpClient'
|
||||
import type { PageResult } from '@/model/base'
|
||||
import type { Category,CategorySearchFilter, } from '@/model/category'
|
||||
|
||||
export const searchCategories = (categoryFilterParam:CategorySearchFilter ) => {
|
||||
return httpClient.get<PageResult<Category>>('/categories',categoryFilterParam)
|
||||
export const searchCategories = (categoryFilterParam :CategorySearchFilter ) => {
|
||||
return httpClient.get<PageResult<Category>>('/categories', categoryFilterParam)
|
||||
}
|
||||
export const searchCategoryListRequest = ( ) => {
|
||||
return httpClient.get<Category[]>('/categories/list',)
|
||||
|
||||
+6
-1
@@ -1,7 +1,7 @@
|
||||
import type { RequestMethodResponse, UploadFile } from 'tdesign-vue-next'
|
||||
import httpClient from '@/api/httpClient'
|
||||
|
||||
export const uploadFile = async (files: UploadFile): Promise<RequestMethodResponse> => {
|
||||
export const uploadFileOld = async (files: UploadFile): Promise<RequestMethodResponse> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
httpClient.uploadFile<{
|
||||
url: string
|
||||
@@ -22,3 +22,8 @@ export const uploadFile = async (files: UploadFile): Promise<RequestMethodRespon
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
export const uploadFile = async (file: File) => {
|
||||
return httpClient.uploadFile<{ url: string }>('/files/upload', file)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<script setup lang="ts">
|
||||
import '@wangeditor/editor/dist/css/style.css'
|
||||
|
||||
// @ts-ignore
|
||||
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import type { IEditorConfig } from '@wangeditor/editor'
|
||||
import { uploadFile, uploadFileOld } from '@/api/file'
|
||||
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue: string
|
||||
mode?: 'default' | 'simple'
|
||||
}>(), {
|
||||
mode: 'default'
|
||||
})
|
||||
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [string]
|
||||
}>()
|
||||
|
||||
const editorRef = shallowRef()
|
||||
const valueHtml = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
|
||||
const editorConfig: Partial<IEditorConfig> = {
|
||||
placeholder: '请输入内容...',
|
||||
MENU_CONF: {
|
||||
uploadImage: {
|
||||
async customUpload(file: File, insertFn: (url: string) => void) {
|
||||
const result = await uploadFile(file)
|
||||
insertFn(result.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const toolbarConfig = {}
|
||||
|
||||
|
||||
|
||||
|
||||
const handleCreated = (editor: typeof Editor) => {
|
||||
editorRef.value = editor // 记录 editor 实例,重要!
|
||||
}
|
||||
|
||||
// 组件销毁时,也及时销毁编辑器
|
||||
//
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
const editor = editorRef.value
|
||||
if (editor == null) return
|
||||
editor.destroy()
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full border-2">
|
||||
|
||||
<Toolbar
|
||||
style="border-bottom: 1px solid #ccc"
|
||||
:editor="editorRef"
|
||||
:defaultConfig="toolbarConfig"
|
||||
:mode="mode"
|
||||
/>
|
||||
<Editor
|
||||
style="height: 500px; overflow-y: hidden;"
|
||||
v-model="valueHtml"
|
||||
:defaultConfig="editorConfig"
|
||||
:mode="mode"
|
||||
@onCreated="handleCreated"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -23,7 +23,7 @@ export interface ArticleSearchFilter extends Partial<Paging>{
|
||||
}
|
||||
|
||||
export interface CreateArticleRequest{
|
||||
categoryId:string
|
||||
categoryId: string
|
||||
title: string
|
||||
content: number
|
||||
content: string
|
||||
}
|
||||
+17
-9
@@ -1,17 +1,25 @@
|
||||
import type { BaseModel } from '@/model/base'
|
||||
import type { AuditBaseModel, BaseModel, Paging } from '@/model/base'
|
||||
|
||||
export interface CreateCarousalsRequest {
|
||||
imageUrl:string,
|
||||
targetType:string,
|
||||
targetUrl?:string,
|
||||
targetId?:string
|
||||
imageUrl:string
|
||||
targetType:string
|
||||
targetUrl?:string | null
|
||||
targetId?:string | null
|
||||
}
|
||||
export interface SearchCarousalsFilter {
|
||||
page:number,
|
||||
size:number,
|
||||
order?:[string]
|
||||
export interface Carousals extends AuditBaseModel,CreateCarousalsRequest {
|
||||
}
|
||||
export interface UpdateCarousalsRequest extends CreateCarousalsRequest{
|
||||
createBy?:null
|
||||
createdTime?:string
|
||||
id?:string
|
||||
updateBy?:null
|
||||
updateTime?:string
|
||||
}
|
||||
export interface SearchCarousalsFilter extends Partial<Paging> {
|
||||
order?:string
|
||||
}
|
||||
|
||||
export interface CarousalResult extends BaseModel,CreateCarousalsRequest{
|
||||
status:string
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface Category extends AuditBaseModel{
|
||||
|
||||
export interface CategorySearchFilter extends Partial<Paging>{
|
||||
order?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,90 +1,28 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
width="60%"
|
||||
:header="header"
|
||||
:confirmBtn="confirmBtn"
|
||||
:closeOnOverlayClick="false"
|
||||
@close="handleCloseDialog"
|
||||
@confirm="saveArticleData"
|
||||
>
|
||||
<t-space direction="vertical" style="width: 100%">
|
||||
<TForm ref="form" :data="articleData" :rules="rules" resetType="initial">
|
||||
<TFormItem label="咨询标题:" name="title" help="名称长度大于2个汉字,小于120个汉字">
|
||||
<t-input v-model.trim="articleData.title" clearable placeholder="请输入咨询标题" />
|
||||
</TFormItem>
|
||||
<TFormItem label="咨询分类:" name="categoryId">
|
||||
<t-select-input
|
||||
:value="articleData.categoryName"
|
||||
placeholder="请选择咨询分类"
|
||||
:popup-visible="popupVisible"
|
||||
:popup-props="{ overlayInnerStyle: { padding: '6px' } }"
|
||||
clearable
|
||||
allow-input
|
||||
@popup-visible-change="onPopupVisibleChange"
|
||||
@clear="onClear"
|
||||
@input-change="onInputChange"
|
||||
>
|
||||
<template #panel>
|
||||
<ul class="flex flex-col gap-1 p-0">
|
||||
<li
|
||||
v-for="item in categoryList"
|
||||
:key="item.id"
|
||||
class="block rounded-sm cursor-pointer px-2 py-0.5 text-gray-900 transition-colors duration-200 whitespace-nowrap overflow-hidden text-ellipsis hover:bg-gray-200"
|
||||
@click="() => onOptionClick({ id: item.id, value: item.name })"
|
||||
>
|
||||
{{ item.name }}
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
<template #suffixIcon>
|
||||
<chevron-down-icon />
|
||||
</template>
|
||||
</t-select-input>
|
||||
</TFormItem>
|
||||
<TFormItem label="内容:" name="content"> </TFormItem>
|
||||
</TForm>
|
||||
</t-space>
|
||||
</t-dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import type { Category } from '@/model/category'
|
||||
import type { Article } from '@/model/article'
|
||||
import type { Article, CreateArticleRequest } from '@/model/article'
|
||||
import { computed, ref, reactive, watch } from 'vue'
|
||||
import type { FormInstanceFunctions, FormProps, SelectInputProps } from 'tdesign-vue-next'
|
||||
import type {
|
||||
FormInstanceFunctions,
|
||||
FormRules,
|
||||
TdSelectProps
|
||||
} from 'tdesign-vue-next'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { ChevronDownIcon } from 'tdesign-icons-vue-next'
|
||||
import { updateArticlesByIdRequest, createArticlesRequest } from '@/api/article'
|
||||
import { updateArticle, createArticle } from '@/api/article'
|
||||
import { searchCategories } from '@/api/category'
|
||||
import Editor from '@/components/Editor.vue'
|
||||
const props = defineProps<{
|
||||
isEdit?: Boolean | null
|
||||
headerTitle?: String | null
|
||||
article?: Article | {}
|
||||
categoryList: Category[] | []
|
||||
article: Article | null
|
||||
categoryList: Category[]
|
||||
}>()
|
||||
const formRef = ref<FormInstanceFunctions | null>(null)
|
||||
const headerText = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
||||
const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定'))
|
||||
const articleData: FormProps['data'] = reactive({ categoryName: '' })
|
||||
const headerText = computed(() => `${props.article ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
||||
const confirmBtnText = computed(() => (props.article ? '保存' : '确定'))
|
||||
const articleData = reactive<CreateArticleRequest>({ title: '', categoryId: '', content: ''})
|
||||
|
||||
const popupVisible = ref(false)
|
||||
const onOptionClick = (item: { id: string; value: string }) => {
|
||||
articleData.categoryName = item.value
|
||||
articleData.categoryId = item.id
|
||||
// 选中后立即关闭浮层
|
||||
popupVisible.value = false
|
||||
}
|
||||
const onClear: SelectInputProps['onClear'] = () => {
|
||||
articleData.categoryId = ''
|
||||
articleData.categoryName = undefined
|
||||
}
|
||||
const onPopupVisibleChange: SelectInputProps['onPopupVisibleChange'] = (val) => {
|
||||
popupVisible.value = val
|
||||
}
|
||||
const onInputChange: SelectInputProps['onInputChange'] = (val, context) => {
|
||||
// 过滤功能
|
||||
console.log(val, context)
|
||||
}
|
||||
const rules: FormProps['rules'] = {
|
||||
name: [
|
||||
const rules: FormRules<CreateArticleRequest> = {
|
||||
title: [
|
||||
{
|
||||
required: true,
|
||||
message: '咨询标题不能为空',
|
||||
@@ -114,7 +52,7 @@ const rules: FormProps['rules'] = {
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
code: [
|
||||
categoryId: [
|
||||
{
|
||||
required: true,
|
||||
message: '咨询分类不能为空',
|
||||
@@ -144,7 +82,9 @@ const rules: FormProps['rules'] = {
|
||||
watch(
|
||||
() => props.article,
|
||||
(newArticleData) => {
|
||||
Object.assign(articleData, newArticleData)
|
||||
articleData.categoryId = newArticleData?.category.id || ''
|
||||
articleData.title = newArticleData?.title || ''
|
||||
articleData.content = newArticleData?.content || ''
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
@@ -152,27 +92,70 @@ const emit = defineEmits<{
|
||||
success: [void]
|
||||
onInputChange: [void]
|
||||
}>()
|
||||
const saveArticleData = async () => {
|
||||
if (form.value) {
|
||||
const valid = await form.value.validate()
|
||||
if (valid && typeof valid === 'boolean') {
|
||||
const { title, categoryId, content, id } = articleData
|
||||
if (!props.isEdit) {
|
||||
await createArticlesRequest({ title, categoryId, content })
|
||||
const handleSave = async () => {
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (valid === true) {
|
||||
if (props.article) {
|
||||
await updateArticle(props.article.id, articleData)
|
||||
} else {
|
||||
await updateArticlesByIdRequest(id, { title, categoryId, content })
|
||||
await createArticle(articleData)
|
||||
}
|
||||
MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}咨询成功`)
|
||||
MessagePlugin.success(`${props.article ? '编辑' : '创建'}咨询成功`)
|
||||
emit('success')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
const handleCloseDialog = () => {
|
||||
// 数据&&规则校验结果重置
|
||||
if (form.value) {
|
||||
form.value.reset()
|
||||
form.value.clearValidate()
|
||||
}
|
||||
if (!formRef.value) return
|
||||
formRef.value.reset()
|
||||
formRef.value.clearValidate()
|
||||
}
|
||||
|
||||
const categoryOptions = ref<TdSelectProps['options']>([])
|
||||
|
||||
const fetchCategories = async (search: string) => {
|
||||
const { data } = await searchCategories({ name: search })
|
||||
categoryOptions.value = data.map((category) => {
|
||||
return {
|
||||
label: category.name,
|
||||
value: category.id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fetchCategories('')
|
||||
|
||||
|
||||
</script>
|
||||
<template>
|
||||
<t-dialog
|
||||
width="60%"
|
||||
:header="headerText"
|
||||
:confirmBtn="confirmBtnText"
|
||||
:closeOnOverlayClick="false"
|
||||
@close="handleCloseDialog"
|
||||
destroy-on-close
|
||||
@confirm="handleSave"
|
||||
>
|
||||
<t-space direction="vertical" style="width: 100%">
|
||||
<TForm ref="formRef" :data="articleData" :rules="rules" resetType="initial">
|
||||
<TFormItem label="咨询标题:" name="title" help="名称长度大于2个汉字,小于120个汉字">
|
||||
<t-input v-model.trim="articleData.title" clearable placeholder="请输入咨询标题" />
|
||||
</TFormItem>
|
||||
<TFormItem label="咨询分类:" name="categoryId">
|
||||
<TSelect
|
||||
v-model="articleData.categoryId"
|
||||
:options="categoryOptions"
|
||||
placeholder="请选择咨询分类"
|
||||
filterable
|
||||
@search="fetchCategories"
|
||||
/>
|
||||
</TFormItem>
|
||||
<TFormItem label="内容:" name="content">
|
||||
<Editor v-model="articleData.content"></Editor>
|
||||
</TFormItem>
|
||||
</TForm>
|
||||
</t-space>
|
||||
</t-dialog>
|
||||
</template>
|
||||
@@ -52,7 +52,7 @@ const columns: BaseTableColumns = [
|
||||
]
|
||||
const articleDialogVisble = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const currentTableData = ref<Article | {}>({})
|
||||
const currentTableData = ref<Article | null>(null)
|
||||
const categoryList = ref<Category[]>([])
|
||||
onMounted(fetchData)
|
||||
watch(articleDialogVisble, (newValue) => {
|
||||
@@ -79,7 +79,7 @@ const handleArticleDialogSuccess = () => {
|
||||
}
|
||||
const handleArticleDialogClosed = () => {
|
||||
isEdit.value = false
|
||||
currentTableData.value = {}
|
||||
currentTableData.value = null
|
||||
}
|
||||
const toggleArticleStatus = async (article: Article) => {
|
||||
if (article.status === 'published') {
|
||||
@@ -147,7 +147,6 @@ const deleteCategoryClick = async (article: Article) => {
|
||||
</TTable>
|
||||
<ArticleDialog
|
||||
headerTitle="咨询"
|
||||
:isEdit="isEdit"
|
||||
:article="currentTableData"
|
||||
:categoryList="categoryList"
|
||||
v-model:visible="articleDialogVisble"
|
||||
|
||||
@@ -27,24 +27,26 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, reactive, watch } from 'vue'
|
||||
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
||||
import type { FormInstanceFunctions } from 'tdesign-vue-next'
|
||||
import ImageUpload from '@/components/ImageUpload.vue'
|
||||
import { createCarousal, updateCarousalItem } from '@/api/carousal'
|
||||
// Todo: 改为ts方式
|
||||
const props = defineProps<{
|
||||
isEdit?: Boolean | null
|
||||
headerTitle?: String | null
|
||||
carousal: {} | number
|
||||
}>()
|
||||
import type {CreateCarousalsRequest, UpdateCarousalsRequest} from "@/model/carousals";
|
||||
const props = withDefaults(defineProps<{
|
||||
isEdit?: boolean | null
|
||||
headerTitle?: string | null
|
||||
carousal: CreateCarousalsRequest
|
||||
}>(),{
|
||||
headerTitle:''
|
||||
})
|
||||
const emit = defineEmits<{
|
||||
success: [string]
|
||||
success: [void]
|
||||
}>()
|
||||
const formRef = ref<FormInstanceFunctions | null>(null)
|
||||
const headerText = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
||||
const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定'))
|
||||
const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
||||
|
||||
const carousalData = ref<FormProps['data']>({
|
||||
const carousalData = ref<UpdateCarousalsRequest>({
|
||||
imageUrl: '',
|
||||
targetType: 'article',
|
||||
targetId: '',
|
||||
@@ -90,18 +92,17 @@ const typeOption = reactive([
|
||||
])
|
||||
const handleFormTypeData = () => {
|
||||
if (carousalData.value.targetType === 'article') {
|
||||
delete carousalData.value.targetUrl
|
||||
carousalData.value.targetUrl = null
|
||||
} else if (carousalData.value.targetType === 'url') {
|
||||
delete carousalData.value.targetId
|
||||
carousalData.value.targetId = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.carousal,
|
||||
(newClassify) => {
|
||||
(newClassify: CreateCarousalsRequest) => {
|
||||
carousalData.value = Object.assign({}, newClassify)
|
||||
const carousalObj = Object.assign({},newClassify)
|
||||
// imgUrl.value.url = carousalObj.imageUrl || ''
|
||||
imgUrl.value = { url: carousalObj.imageUrl || '' }
|
||||
},
|
||||
{
|
||||
@@ -113,42 +114,24 @@ const fetchSaveCarousalData = async () => {
|
||||
/* TODO: 保存分类数据 */
|
||||
if (formRef.value) {
|
||||
const valid = await formRef.value.validate()
|
||||
// console.log(valid,'valid')
|
||||
if (valid && typeof valid === 'boolean') {
|
||||
/* TODO: 校验通过保存分类数据 */
|
||||
handleFormTypeData()
|
||||
// console.log(formType.value,'formType')
|
||||
let res
|
||||
|
||||
switch (formType.value){
|
||||
case 'create':
|
||||
res = await createCarousal(carousalData.value)
|
||||
emit('success')
|
||||
break;
|
||||
case 'update':
|
||||
const fieldsToKeep = ["imageUrl", "targetType", "targetUrl", "targetId"];
|
||||
const requestObj = {};
|
||||
|
||||
for (const field of fieldsToKeep) {
|
||||
if (carousalData.value[field]!== null && carousalData.value[field]!== undefined) {
|
||||
requestObj[field] = carousalData.value[field];
|
||||
}
|
||||
}
|
||||
handleFormTypeData()
|
||||
res = await updateCarousalItem(carousalData.value.id,requestObj)
|
||||
emit('success')
|
||||
break;
|
||||
default:
|
||||
res = await createCarousal(carousalData.value)
|
||||
emit('success')
|
||||
break;
|
||||
}
|
||||
// const createCarousalApi = createCarousal(carousalData.value)
|
||||
// console.log(createCarousalApi,'createCarousalApi')
|
||||
formType.value === 'add' ? await createCarousalData() : await updateCarousalData()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
const createCarousalData = async () => {
|
||||
await createCarousal(carousalData.value)
|
||||
emit('success')
|
||||
}
|
||||
const updateCarousalData = async () => {
|
||||
handleFormTypeData()
|
||||
const requestObj: CreateCarousalsRequest = {imageUrl: carousalData.value.imageUrl,targetType:carousalData.value.targetType,targetUrl:carousalData.value.targetUrl,targetId:carousalData.value.targetId}
|
||||
await updateCarousalItem(carousalData.value.id, requestObj)
|
||||
emit('success')
|
||||
}
|
||||
const handleCloseDialog = () => {
|
||||
// 数据&&规则校验结果重置
|
||||
if (formRef.value) {
|
||||
|
||||
@@ -4,7 +4,11 @@ import { onMounted, ref } from 'vue'
|
||||
import type { BaseTableColumns } from 'tdesign-vue-next'
|
||||
import CarousalDialog from '@/pages/carousal/components/CarousalDialog.vue'
|
||||
import { activeCarousal, deleteCarousal, searchCarousals, inactiveCarousal } from '@/api/carousal'
|
||||
import type { CarousalResult, SearchCarousalsFilter } from '@/model/carousals'
|
||||
import type {
|
||||
CarousalResult, Carousals,
|
||||
CreateCarousalsRequest,
|
||||
SearchCarousalsFilter,
|
||||
} from '@/model/carousals'
|
||||
import ImagePreviewer from '@/components/ImagePreviewer.vue'
|
||||
import { useSearchable } from '@/composables/useSearchable'
|
||||
|
||||
@@ -31,16 +35,17 @@ const columns: BaseTableColumns = [
|
||||
}
|
||||
]
|
||||
|
||||
const { loading, data, pagination, fetchData, onPageChange } = useSearchable<CarousalResult, SearchCarousalsFilter>(searchCarousals)
|
||||
const { loading, data, pagination, fetchData, onPageChange } = useSearchable<SearchCarousalsFilter,Carousals>(searchCarousals)
|
||||
onMounted(fetchData)
|
||||
|
||||
|
||||
const carousalDialogVisible = ref<boolean>(false)
|
||||
const isEdit = ref<boolean>(false)
|
||||
const currentTableData = ref<CarousalResult | null>(null)
|
||||
|
||||
|
||||
const handleEdit = (row: object): void => {
|
||||
const currentTableData = ref<CreateCarousalsRequest>({
|
||||
imageUrl: '',
|
||||
targetType: ''
|
||||
})
|
||||
const handleEdit = (row: CarousalResult): void => {
|
||||
isEdit.value = true
|
||||
currentTableData.value = Object.assign({}, row)
|
||||
carousalDialogVisible.value = true
|
||||
@@ -60,7 +65,12 @@ const handleDelete = async (row: CarousalResult): Promise<void> => {
|
||||
const handleCreateCarousal = (): void => {
|
||||
isEdit.value = false
|
||||
carousalDialogVisible.value = true
|
||||
currentTableData.value = {}
|
||||
currentTableData.value = {
|
||||
imageUrl: '',
|
||||
targetId: '',
|
||||
targetType: '',
|
||||
targetUrl: '',
|
||||
}
|
||||
}
|
||||
const handleSuccessDialog = async (): Promise<void> => {
|
||||
await fetchData()
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
<TDialog
|
||||
width="40%"
|
||||
:header="headerText"
|
||||
:confirmBtn="confirmBtnText"
|
||||
:closeOnOverlayClick="false"
|
||||
@close="handleCloseDialog"
|
||||
@confirm="SaveCategoryData"
|
||||
@close="handleClose"
|
||||
@confirm="handleSave"
|
||||
>
|
||||
<t-space direction="vertical" style="width: 100%">
|
||||
<TForm ref="form" :data="categoryData" :rules="rules" resetType="initial">
|
||||
<TForm ref="formRef" :data="categoryData" :rules="rules" resetType="initial">
|
||||
<TFormItem label="分类名称:" name="name" help="名称长度小于5个汉字,大于2个汉字">
|
||||
<t-input v-model.trim="categoryData.name" clearable placeholder="请输入分类名称" />
|
||||
</TFormItem>
|
||||
@@ -26,8 +25,7 @@
|
||||
></t-input-number>
|
||||
</TFormItem>
|
||||
</TForm>
|
||||
</t-space>
|
||||
</t-dialog>
|
||||
</TDialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import type { Category } from '@/model/category'
|
||||
@@ -51,16 +49,6 @@ const rules: FormProps['rules'] = {
|
||||
type: 'error',
|
||||
trigger: 'blur'
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
message: '分类名称不能为空',
|
||||
type: 'error',
|
||||
trigger: 'change'
|
||||
},
|
||||
{
|
||||
whitespace: true,
|
||||
message: '分类名称不能为空'
|
||||
},
|
||||
{
|
||||
min: 4,
|
||||
message: '输入汉字长度应在2到5之间',
|
||||
@@ -81,16 +69,6 @@ const rules: FormProps['rules'] = {
|
||||
type: 'error',
|
||||
trigger: 'blur'
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
message: '分类编号不能为空',
|
||||
type: 'error',
|
||||
trigger: 'change'
|
||||
},
|
||||
{
|
||||
whitespace: true,
|
||||
message: '分类编号不能为空'
|
||||
},
|
||||
{
|
||||
min: 4,
|
||||
message: '输入字符应大于4个字符长度',
|
||||
@@ -111,16 +89,6 @@ const rules: FormProps['rules'] = {
|
||||
type: 'error',
|
||||
trigger: 'blur'
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
message: '排序级别不能为空',
|
||||
type: 'error',
|
||||
trigger: 'change'
|
||||
},
|
||||
{
|
||||
whitespace: true,
|
||||
message: '排序级别不能为空'
|
||||
},
|
||||
{
|
||||
pattern: /^[1-9]\d*$/,
|
||||
message: '排序级别必须为正整数',
|
||||
@@ -139,27 +107,26 @@ watch(
|
||||
const emit = defineEmits<{
|
||||
success: [void]
|
||||
}>()
|
||||
const SaveCategoryData = async () => {
|
||||
if (form.value) {
|
||||
const valid = await form.value.validate()
|
||||
if (valid && typeof valid === 'boolean') {
|
||||
const handleSave = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
const valid = await formRef.value.validate()
|
||||
if (valid === true) {
|
||||
const { code, name, order, id } = categoryData
|
||||
if (!props.isEdit) {
|
||||
if (!props.category) {
|
||||
await createCategoryRequest({ code, name, order })
|
||||
} else {
|
||||
await updateCategoryByIdRequest(id, { code, name, order })
|
||||
}
|
||||
MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}分类成功`)
|
||||
MessagePlugin.success(`${props.category ? '编辑' : '创建'}分类成功`)
|
||||
emit('success')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
const handleCloseDialog = () => {
|
||||
// 数据&&规则校验结果重置
|
||||
if (form.value) {
|
||||
form.value.reset()
|
||||
form.value.clearValidate()
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
formRef.value.reset()
|
||||
formRef.value.clearValidate()
|
||||
}
|
||||
</script>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { uploadFile } from '@/api/file'
|
||||
import { uploadFileOld } from '@/api/file'
|
||||
import { ref, watch } from 'vue'
|
||||
import type { UploadFile } from 'tdesign-vue-next'
|
||||
|
||||
@@ -37,7 +37,7 @@ watch(() => props.modelValue, (value) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TUpload theme="image" accept="image/jpeg,image/png" :request-method="uploadFile" v-model="fileList">
|
||||
<TUpload theme="image" accept="image/jpeg,image/png" :request-method="uploadFileOld" v-model="fileList">
|
||||
</TUpload>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ const handleRoleSettingSuccess = () => {
|
||||
<TFormItem label="手机号码">
|
||||
<TInput placeholder="请输入需要搜索的用户姓名"></TInput>
|
||||
</TFormItem>
|
||||
</TCol>
|
||||
</TCol>7
|
||||
<TCol :span="3">
|
||||
<TFormItem label="手机号码">
|
||||
<TInput placeholder="请输入需要搜索的用户姓名"></TInput>
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ export default defineConfig(({ command, mode }) => {
|
||||
'/api': {
|
||||
target: env.VITE_PROXY_ENDPOINT,
|
||||
changeOrigin: true,
|
||||
// rewrite: (path) => path.replace(/^\/api/, '')
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user