Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d49b19cea0 |
No files matched your search
+1
-3
@@ -1,3 +1 @@
|
|||||||
VITE_ENABLE_MOCK=false
|
VITE_ENABLE_MOCK=true
|
||||||
VITE_API_PREFIX=/api
|
|
||||||
VITE_PROXY_ENDPOINT=http://localhost:3000
|
|
||||||
Vendored
-6
@@ -8,7 +8,6 @@ export {}
|
|||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
Copyright: typeof import('./src/components/Copyright.vue')['default']
|
Copyright: typeof import('./src/components/Copyright.vue')['default']
|
||||||
Editor: typeof import('./src/components/Editor.vue')['default']
|
|
||||||
ImagePreviewer: typeof import('./src/components/ImagePreviewer.vue')['default']
|
ImagePreviewer: typeof import('./src/components/ImagePreviewer.vue')['default']
|
||||||
ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
|
ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
|
||||||
RegularPage: typeof import('./src/components/RegularPage.vue')['default']
|
RegularPage: typeof import('./src/components/RegularPage.vue')['default']
|
||||||
@@ -18,7 +17,6 @@ declare module 'vue' {
|
|||||||
TAvatar: typeof import('tdesign-vue-next')['Avatar']
|
TAvatar: typeof import('tdesign-vue-next')['Avatar']
|
||||||
TButton: typeof import('tdesign-vue-next')['Button']
|
TButton: typeof import('tdesign-vue-next')['Button']
|
||||||
TCard: typeof import('tdesign-vue-next')['Card']
|
TCard: typeof import('tdesign-vue-next')['Card']
|
||||||
TCol: typeof import('tdesign-vue-next')['Col']
|
|
||||||
TDialog: typeof import('tdesign-vue-next')['Dialog']
|
TDialog: typeof import('tdesign-vue-next')['Dialog']
|
||||||
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
|
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
|
||||||
TForm: typeof import('tdesign-vue-next')['Form']
|
TForm: typeof import('tdesign-vue-next')['Form']
|
||||||
@@ -34,13 +32,9 @@ declare module 'vue' {
|
|||||||
TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm']
|
TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm']
|
||||||
TRadioButton: typeof import('tdesign-vue-next')['RadioButton']
|
TRadioButton: typeof import('tdesign-vue-next')['RadioButton']
|
||||||
TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
|
TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
|
||||||
TRow: typeof import('tdesign-vue-next')['Row']
|
|
||||||
TSelect: typeof import('tdesign-vue-next')['Select']
|
|
||||||
TSpace: typeof import('tdesign-vue-next')['Space']
|
TSpace: typeof import('tdesign-vue-next')['Space']
|
||||||
TTable: typeof import('tdesign-vue-next')['Table']
|
TTable: typeof import('tdesign-vue-next')['Table']
|
||||||
TTag: typeof import('tdesign-vue-next')['Tag']
|
TTag: typeof import('tdesign-vue-next')['Tag']
|
||||||
TTagInput: typeof import('tdesign-vue-next')['TagInput']
|
|
||||||
TTextarea: typeof import('tdesign-vue-next')['Textarea']
|
|
||||||
TUpload: typeof import('tdesign-vue-next')['Upload']
|
TUpload: typeof import('tdesign-vue-next')['Upload']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <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)
|
return httpClient.get<PageResult<Article>>('/articles',articleFilterParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createArticle = (article: CreateArticleRequest) => {
|
export const createArticlesRequest = (article: CreateArticleRequest) => {
|
||||||
return httpClient.post<Article>('/articles',article)
|
return httpClient.post<Article>('/articles',article)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export const searchArticlesByIdRequest = (id: string) => {
|
|||||||
return httpClient.get<Article>(`/articles/${id}`)
|
return httpClient.get<Article>(`/articles/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateArticle = (id: string, article:CreateArticleRequest) => {
|
export const updateArticlesByIdRequest = (id: string,article:CreateArticleRequest) => {
|
||||||
return httpClient.put<Article>(`/articles/${id}`,article)
|
return httpClient.put<Article>(`/articles/${id}`,article)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@ import httpClient from '@/api/httpClient'
|
|||||||
import type { PageResult } from '@/model/base'
|
import type { PageResult } from '@/model/base'
|
||||||
import type { Category,CategorySearchFilter, } from '@/model/category'
|
import type { Category,CategorySearchFilter, } from '@/model/category'
|
||||||
|
|
||||||
export const searchCategories = (categoryFilterParam :CategorySearchFilter ) => {
|
export const searchCategories = (categoryFilterParam:CategorySearchFilter ) => {
|
||||||
return httpClient.get<PageResult<Category>>('/categories', categoryFilterParam)
|
return httpClient.get<PageResult<Category>>('/categories',categoryFilterParam)
|
||||||
}
|
}
|
||||||
export const searchCategoryListRequest = ( ) => {
|
export const searchCategoryListRequest = ( ) => {
|
||||||
return httpClient.get<Category[]>('/categories/list',)
|
return httpClient.get<Category[]>('/categories/list',)
|
||||||
|
|||||||
+1
-6
@@ -1,7 +1,7 @@
|
|||||||
import type { RequestMethodResponse, UploadFile } from 'tdesign-vue-next'
|
import type { RequestMethodResponse, UploadFile } from 'tdesign-vue-next'
|
||||||
import httpClient from '@/api/httpClient'
|
import httpClient from '@/api/httpClient'
|
||||||
|
|
||||||
export const uploadFileOld = async (files: UploadFile): Promise<RequestMethodResponse> => {
|
export const uploadFile = async (files: UploadFile): Promise<RequestMethodResponse> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
httpClient.uploadFile<{
|
httpClient.uploadFile<{
|
||||||
url: string
|
url: string
|
||||||
@@ -22,8 +22,3 @@ export const uploadFileOld = async (files: UploadFile): Promise<RequestMethodRes
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const uploadFile = async (file: File) => {
|
|
||||||
return httpClient.uploadFile<{ url: string }>('/files/upload', file)
|
|
||||||
}
|
|
||||||
@@ -9,13 +9,8 @@ const client: AxiosInstance = axios.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleError = (errorResponse: ErrorResponse) => {
|
const handleError = (errorResponse: ErrorResponse) => {
|
||||||
if (errorResponse.code === 401) {
|
|
||||||
useAppStore().logout()
|
|
||||||
MessagePlugin.error('登录信息失效,请重新登录')
|
|
||||||
} else {
|
|
||||||
MessagePlugin.error(errorResponse.message)
|
|
||||||
|
|
||||||
}
|
MessagePlugin.error(errorResponse.message)
|
||||||
}
|
}
|
||||||
client.interceptors.response.use(
|
client.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import httpClient from '@/api/httpClient'
|
|
||||||
import type { PageResult } from '@/model/base'
|
|
||||||
import type { PetVariety, SearchPetVarietyFilter } from '@/model/pet-variety'
|
|
||||||
|
|
||||||
export const searchPetVarieties = async (searchPetVarietyFilter: SearchPetVarietyFilter) => {
|
|
||||||
return httpClient.get<PageResult<PetVariety>>('/pet-varieties', searchPetVarietyFilter)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const createPetVariety = async (name: string) => {
|
|
||||||
return httpClient.post<PetVariety>('/pet-varieties', { name })
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const editPetVariety = async (id: string, name: string) => {
|
|
||||||
return httpClient.put<PetVariety>(`/pet-varieties/${id}`, { name })
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const deletePetVariety = async (id: string) => {
|
|
||||||
return httpClient.delete(`/pet-varieties/${id}`)
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import type { CreateProductRequest, Product, SearchProductFilter, UpdateProductRequest } from '@/model/product'
|
|
||||||
import httpClient from '@/api/httpClient'
|
|
||||||
import type { PageResult } from '@/model/base'
|
|
||||||
|
|
||||||
export const searchProducts = async (searchProductFilter: SearchProductFilter) => {
|
|
||||||
return httpClient.get<PageResult<Product>>('/products', searchProductFilter)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const createProduct = async (createProductRequest: CreateProductRequest) => {
|
|
||||||
return httpClient.post<Product>('/products', createProductRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const editProduct = async (id: string, updateProductRequest: UpdateProductRequest) => {
|
|
||||||
return httpClient.put<Product>(`/products/${id}`, updateProductRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const deleteProduct = async (id: string) => {
|
|
||||||
return httpClient.delete(`/products/${id}`)
|
|
||||||
}
|
|
||||||
+1
-1
@@ -10,6 +10,6 @@ export const searchUsers = (userSearchFilter: UserSearchFilter) => {
|
|||||||
return httpClient.get<PageResult<User>>('/users', userSearchFilter)
|
return httpClient.get<PageResult<User>>('/users', userSearchFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setUserRoles = (id: string, roles: string[]) => {
|
export const setUserRoles = (id: number, roles: string[]) => {
|
||||||
return httpClient.put<User>(`/users/${id}/roles`, { roles })
|
return httpClient.put<User>(`/users/${id}/roles`, { roles })
|
||||||
}
|
}
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
<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>
|
|
||||||
@@ -9,7 +9,7 @@ const sizeLimit = ref<UploadProps['sizeLimit']>({
|
|||||||
size: 2,
|
size: 2,
|
||||||
unit: 'MB',
|
unit: 'MB',
|
||||||
});
|
});
|
||||||
const fileList = ref<UploadProps['value']>([]);
|
const file1 = ref<UploadProps['value']>([]);
|
||||||
const disabled = ref<boolean>(false);
|
const disabled = ref<boolean>(false);
|
||||||
const autoUpload = ref<boolean>(true);
|
const autoUpload = ref<boolean>(true);
|
||||||
const showImageFileName = ref<boolean>(true);
|
const showImageFileName = ref<boolean>(true);
|
||||||
@@ -19,7 +19,8 @@ const handleFail: UploadProps['onFail'] = ({ file }) => {
|
|||||||
};
|
};
|
||||||
const handleSuccess: UploadProps['onSuccess'] = ({ file }) => {
|
const handleSuccess: UploadProps['onSuccess'] = ({ file }) => {
|
||||||
if(file?.url){
|
if(file?.url){
|
||||||
emits('update:modelValue',file.url)
|
console.log(file1.value,'file1')
|
||||||
|
emits('on-success',file.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
@@ -27,36 +28,35 @@ const appStore = useAppStore()
|
|||||||
const uploadHeaders = ref<UploadProps['headers']>({
|
const uploadHeaders = ref<UploadProps['headers']>({
|
||||||
Authorization: `Bearer ${appStore.token}`
|
Authorization: `Bearer ${appStore.token}`
|
||||||
})
|
})
|
||||||
|
const props = defineProps({
|
||||||
|
imageUrl:{
|
||||||
const props = withDefaults(defineProps<{
|
type:Object,
|
||||||
modelValue: string
|
default:() => {
|
||||||
}>(), {
|
return { url: '' }
|
||||||
modelValue: ''
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emits = defineEmits(['on-success'])
|
||||||
const emits = defineEmits<{
|
watch(() => props.imageUrl,(newVal) => {
|
||||||
'update:modelValue': [string]
|
if (!newVal) return
|
||||||
}>()
|
if (newVal.url !== '') {
|
||||||
watch(() => props.modelValue,(newVal) => {
|
file1.value = [{...newVal}]
|
||||||
if (newVal) {
|
|
||||||
fileList.value = [{url: newVal}]
|
|
||||||
} else {
|
} else {
|
||||||
fileList.value = []
|
file1.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
},{
|
},{
|
||||||
deep:true,
|
deep:true,
|
||||||
immediate:true
|
immediate:true
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<t-upload
|
<t-upload
|
||||||
v-model="fileList"
|
ref="uploadRef1"
|
||||||
|
v-model="file1"
|
||||||
:image-viewer-props="imageViewerProps"
|
:image-viewer-props="imageViewerProps"
|
||||||
:size-limit="sizeLimit"
|
:size-limit="sizeLimit"
|
||||||
action="/api/files/upload"
|
action="/api/files/upload"
|
||||||
@@ -76,7 +76,10 @@ watch(() => props.modelValue,(newVal) => {
|
|||||||
@fail="handleFail"
|
@fail="handleFail"
|
||||||
@success="handleSuccess"
|
@success="handleSuccess"
|
||||||
>
|
>
|
||||||
|
<!-- custom UI -->
|
||||||
|
<!-- <template #fileListDisplay="{ files }">
|
||||||
|
<div>{{ JSON.stringify(files) }}</div>
|
||||||
|
</template> -->
|
||||||
</t-upload>
|
</t-upload>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
import { ChevronDownIcon } from 'tdesign-icons-vue-next'
|
import { ChevronDownIcon } from 'tdesign-icons-vue-next'
|
||||||
import type { DropdownOption } from 'tdesign-vue-next'
|
import type { DropdownOption } from 'tdesign-vue-next'
|
||||||
import { useAppStore } from '@/stores/app'
|
import { useAppStore } from '@/stores/app'
|
||||||
|
import type { User } from '@/models/user'
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const currentUser = appStore.currentUser
|
const currentUser: User = appStore.currentUser
|
||||||
const options: DropdownOption[] = [
|
const options: DropdownOption[] = [
|
||||||
{
|
{
|
||||||
content: '退出登录',
|
content: '退出登录',
|
||||||
@@ -20,7 +21,7 @@ const options: DropdownOption[] = [
|
|||||||
<TButton variant="text">
|
<TButton variant="text">
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
<TAvatar size="24px" image="https://tdesign.gtimg.com/site/avatar.jpg"></TAvatar>
|
<TAvatar size="24px" image="https://tdesign.gtimg.com/site/avatar.jpg"></TAvatar>
|
||||||
{{ currentUser?.username }}
|
{{ currentUser.username }}
|
||||||
<ChevronDownIcon />
|
<ChevronDownIcon />
|
||||||
</div>
|
</div>
|
||||||
</TButton>
|
</TButton>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import type { AuditBaseModel,Paging } from '@/model/base'
|
|||||||
import type { Category } from './category'
|
import type { Category } from './category'
|
||||||
|
|
||||||
export enum ArticleStatus {
|
export enum ArticleStatus {
|
||||||
DRAFT = 'draft',
|
Draft = 'draft',
|
||||||
PUBLISHED = 'published',
|
Published = 'published',
|
||||||
Closed = 'closed'
|
Closed = 'closed'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,8 +12,6 @@ export interface Article extends AuditBaseModel{
|
|||||||
content:string
|
content:string
|
||||||
category: Category
|
category: Category
|
||||||
status: ArticleStatus
|
status: ArticleStatus
|
||||||
thumbnail: string
|
|
||||||
description: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -25,9 +23,7 @@ export interface ArticleSearchFilter extends Partial<Paging>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateArticleRequest{
|
export interface CreateArticleRequest{
|
||||||
categoryId: string
|
categoryId:string
|
||||||
title: string
|
title: string
|
||||||
content: string
|
content: number
|
||||||
thumbnail: string
|
|
||||||
description:string
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -7,7 +7,7 @@ export interface ErrorResponse {
|
|||||||
export interface BaseModel {
|
export interface BaseModel {
|
||||||
id: string
|
id: string
|
||||||
createdTime: string
|
createdTime: string
|
||||||
updatedTime: string
|
updateTime: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuditBaseModel extends BaseModel {
|
export interface AuditBaseModel extends BaseModel {
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ export interface CreateCarousalsRequest {
|
|||||||
export interface Carousals extends AuditBaseModel,CreateCarousalsRequest {
|
export interface Carousals extends AuditBaseModel,CreateCarousalsRequest {
|
||||||
}
|
}
|
||||||
export interface UpdateCarousalsRequest extends CreateCarousalsRequest{
|
export interface UpdateCarousalsRequest extends CreateCarousalsRequest{
|
||||||
createBy?:null
|
|
||||||
createdTime?:string
|
|
||||||
id?:string
|
id?:string
|
||||||
updateBy?:null
|
|
||||||
updateTime?:string
|
|
||||||
}
|
}
|
||||||
export interface SearchCarousalsFilter extends Partial<Paging> {
|
export interface SearchCarousalsFilter extends Partial<Paging> {
|
||||||
order?:string
|
order?:string
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export interface Category extends AuditBaseModel{
|
|||||||
|
|
||||||
export interface CategorySearchFilter extends Partial<Paging>{
|
export interface CategorySearchFilter extends Partial<Paging>{
|
||||||
order?: string
|
order?: string
|
||||||
name?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import type { BaseFilterRequest, BaseModel } from '@/model/base'
|
|
||||||
|
|
||||||
export interface PetVariety extends BaseModel{
|
|
||||||
name: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SearchPetVarietyFilter extends BaseFilterRequest {}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import type { BaseFilterRequest, BaseModel } from '@/model/base'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface Product extends BaseModel{
|
|
||||||
name: string;
|
|
||||||
category: ProductCategory
|
|
||||||
photo: string;
|
|
||||||
tags: string[];
|
|
||||||
totalWeight: number;
|
|
||||||
protein: number;
|
|
||||||
fat: number;
|
|
||||||
fiber: number;
|
|
||||||
ash: number;
|
|
||||||
moisture: number;
|
|
||||||
meValue: number | null; // ME值(kcal/g),直接配置的代谢能
|
|
||||||
totalCalories: number; // 产品总能量(kcal),由后端基于ME算法计算或直接配置
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CreateProductRequest extends Pick<Product, "name" | 'photo' | 'tags' | 'totalWeight' | 'category' | 'protein' | 'fat' | 'fiber' | 'ash' | 'moisture'> {
|
|
||||||
meValue?: number; // ME值(kcal/g),可选
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SearchProductFilter extends BaseFilterRequest{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface UpdateProductRequest extends CreateProductRequest {}
|
|
||||||
|
|
||||||
export enum ProductCategory {
|
|
||||||
DRY_FOOD,
|
|
||||||
WET_FOOD,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const productCategoryOptions: {
|
|
||||||
label: string
|
|
||||||
value: ProductCategory
|
|
||||||
}[] = [
|
|
||||||
{ label: '干粮', value: ProductCategory.DRY_FOOD },
|
|
||||||
{ label: '湿粮', value: ProductCategory.WET_FOOD },
|
|
||||||
]
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
import type { BaseFilterRequest, AuditBaseModel } from '@/model/base'
|
import type { BaseFilterRequest, AuditBaseModel } from '@/model/base'
|
||||||
import type { Role } from '@/model/role'
|
|
||||||
|
|
||||||
export interface User extends AuditBaseModel{
|
export interface User extends AuditBaseModel{
|
||||||
username: string
|
username: string
|
||||||
locked: boolean
|
locked: boolean
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
name?: string
|
|
||||||
roles?: Role[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,90 @@
|
|||||||
|
<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>
|
<script lang="ts" setup>
|
||||||
import type { Category } from '@/model/category'
|
import type { Category } from '@/model/category'
|
||||||
import type { Article, CreateArticleRequest } from '@/model/article'
|
import type { Article } from '@/model/article'
|
||||||
import { computed, ref, reactive, watch } from 'vue'
|
import { computed, ref, reactive, watch } from 'vue'
|
||||||
import type {
|
import type { FormInstanceFunctions, FormProps, SelectInputProps } from 'tdesign-vue-next'
|
||||||
FormInstanceFunctions,
|
|
||||||
FormRules,
|
|
||||||
TdSelectProps
|
|
||||||
} from 'tdesign-vue-next'
|
|
||||||
import { MessagePlugin } from 'tdesign-vue-next'
|
import { MessagePlugin } from 'tdesign-vue-next'
|
||||||
import { updateArticle, createArticle } from '@/api/article'
|
import { ChevronDownIcon } from 'tdesign-icons-vue-next'
|
||||||
import { searchCategories } from '@/api/category'
|
import { updateArticlesByIdRequest, createArticlesRequest } from '@/api/article'
|
||||||
import Editor from '@/components/Editor.vue'
|
|
||||||
import ImageUpload from '@/components/ImageUpload.vue'
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
isEdit?: Boolean | null
|
||||||
headerTitle?: String | null
|
headerTitle?: String | null
|
||||||
article: Article | null
|
article?: Article | {}
|
||||||
categoryList: Category[]
|
categoryList: Category[] | []
|
||||||
}>()
|
}>()
|
||||||
const formRef = ref<FormInstanceFunctions | null>(null)
|
const formRef = ref<FormInstanceFunctions | null>(null)
|
||||||
const headerText = computed(() => `${props.article ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
const headerText = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
||||||
const confirmBtnText = computed(() => (props.article ? '保存' : '确定'))
|
const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定'))
|
||||||
const articleData = reactive<CreateArticleRequest>({ title: '', categoryId: '', content: '', thumbnail: '', description: ''})
|
const articleData: FormProps['data'] = reactive({ categoryName: '' })
|
||||||
|
|
||||||
const rules: FormRules<CreateArticleRequest> = {
|
const popupVisible = ref(false)
|
||||||
title: [
|
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: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '咨询标题不能为空',
|
message: '咨询标题不能为空',
|
||||||
@@ -53,7 +114,7 @@ const rules: FormRules<CreateArticleRequest> = {
|
|||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
categoryId: [
|
code: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '咨询分类不能为空',
|
message: '咨询分类不能为空',
|
||||||
@@ -78,35 +139,12 @@ const rules: FormRules<CreateArticleRequest> = {
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}
|
}
|
||||||
],
|
|
||||||
thumbnail: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '请上传封面图',
|
|
||||||
type: 'error',
|
|
||||||
trigger: 'blur'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
whitespace: true,
|
|
||||||
message: '请上传封面图'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
description: [
|
|
||||||
{
|
|
||||||
max: 500,
|
|
||||||
message: '描述不超过500字',
|
|
||||||
type: 'error',
|
|
||||||
trigger: 'blur'
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
watch(
|
watch(
|
||||||
() => props.article,
|
() => props.article,
|
||||||
(newArticleData) => {
|
(newArticleData) => {
|
||||||
articleData.categoryId = newArticleData?.category.id || ''
|
Object.assign(articleData, newArticleData)
|
||||||
articleData.title = newArticleData?.title || ''
|
|
||||||
articleData.content = newArticleData?.content || ''
|
|
||||||
articleData.thumbnail = newArticleData?.thumbnail || ''
|
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
)
|
)
|
||||||
@@ -114,76 +152,27 @@ const emit = defineEmits<{
|
|||||||
success: [void]
|
success: [void]
|
||||||
onInputChange: [void]
|
onInputChange: [void]
|
||||||
}>()
|
}>()
|
||||||
const handleSave = async () => {
|
const saveArticleData = async () => {
|
||||||
if (!formRef.value) return
|
if (form.value) {
|
||||||
const valid = await formRef.value.validate()
|
const valid = await form.value.validate()
|
||||||
if (valid === true) {
|
if (valid && typeof valid === 'boolean') {
|
||||||
if (props.article) {
|
const { title, categoryId, content, id } = articleData
|
||||||
await updateArticle(props.article.id, articleData)
|
if (!props.isEdit) {
|
||||||
|
await createArticlesRequest({ title, categoryId, content })
|
||||||
} else {
|
} else {
|
||||||
await createArticle(articleData)
|
await updateArticlesByIdRequest(id, { title, categoryId, content })
|
||||||
}
|
}
|
||||||
MessagePlugin.success(`${props.article ? '编辑' : '创建'}咨询成功`)
|
MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}咨询成功`)
|
||||||
emit('success')
|
emit('success')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const handleCloseDialog = () => {
|
const handleCloseDialog = () => {
|
||||||
// 数据&&规则校验结果重置
|
// 数据&&规则校验结果重置
|
||||||
if (!formRef.value) return
|
if (form.value) {
|
||||||
formRef.value.reset()
|
form.value.reset()
|
||||||
formRef.value.clearValidate()
|
form.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>
|
</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="description" help="描述长度小于500字符">
|
|
||||||
<TTextarea v-model.trim="articleData.description" clearable placeholder="请输入咨询标题" :maxcharacter="500"/>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="咨询分类:" name="categoryId">
|
|
||||||
<TSelect
|
|
||||||
v-model="articleData.categoryId"
|
|
||||||
:options="categoryOptions"
|
|
||||||
placeholder="请选择咨询分类"
|
|
||||||
filterable
|
|
||||||
@search="fetchCategories"
|
|
||||||
/>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="轮播图:" name="thumbnail">
|
|
||||||
<ImageUpload v-model="articleData.thumbnail"/>
|
|
||||||
</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 articleDialogVisble = ref(false)
|
||||||
const isEdit = ref(false)
|
const isEdit = ref(false)
|
||||||
const currentTableData = ref<Article | null>(null)
|
const currentTableData = ref<Article | {}>({})
|
||||||
const categoryList = ref<Category[]>([])
|
const categoryList = ref<Category[]>([])
|
||||||
onMounted(fetchData)
|
onMounted(fetchData)
|
||||||
watch(articleDialogVisble, (newValue) => {
|
watch(articleDialogVisble, (newValue) => {
|
||||||
@@ -79,7 +79,7 @@ const handleArticleDialogSuccess = () => {
|
|||||||
}
|
}
|
||||||
const handleArticleDialogClosed = () => {
|
const handleArticleDialogClosed = () => {
|
||||||
isEdit.value = false
|
isEdit.value = false
|
||||||
currentTableData.value = null
|
currentTableData.value = {}
|
||||||
}
|
}
|
||||||
const toggleArticleStatus = async (article: Article) => {
|
const toggleArticleStatus = async (article: Article) => {
|
||||||
if (article.status === 'published') {
|
if (article.status === 'published') {
|
||||||
@@ -147,6 +147,7 @@ const deleteCategoryClick = async (article: Article) => {
|
|||||||
</TTable>
|
</TTable>
|
||||||
<ArticleDialog
|
<ArticleDialog
|
||||||
headerTitle="咨询"
|
headerTitle="咨询"
|
||||||
|
:isEdit="isEdit"
|
||||||
:article="currentTableData"
|
:article="currentTableData"
|
||||||
:categoryList="categoryList"
|
:categoryList="categoryList"
|
||||||
v-model:visible="articleDialogVisble"
|
v-model:visible="articleDialogVisble"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
>
|
>
|
||||||
<TForm v-if="carousalData" ref="formRef" :data="carousalData" :rules="rules" resetType="initial" label-width="100">
|
<TForm v-if="carousalData" ref="formRef" :data="carousalData" :rules="rules" resetType="initial" label-width="100">
|
||||||
<TFormItem label="轮播图:" name="imageUrl">
|
<TFormItem label="轮播图:" name="imageUrl">
|
||||||
<ImageUpload v-model="carousalData.imageUrl" />
|
<ImageUpload @on-success="handleSuccessImg" :image-url="imgUrl"/>
|
||||||
</TFormItem>
|
</TFormItem>
|
||||||
<TFormItem label="跳转类型:" name="targetType" >
|
<TFormItem label="跳转类型:" name="targetType" >
|
||||||
<t-radio-group :default-value="carousalData.targetType" v-model="carousalData.targetType">
|
<t-radio-group :default-value="carousalData.targetType" v-model="carousalData.targetType">
|
||||||
@@ -52,6 +52,7 @@ const carousalData = ref<UpdateCarousalsRequest>({
|
|||||||
targetId: '',
|
targetId: '',
|
||||||
targetUrl: '',
|
targetUrl: '',
|
||||||
})
|
})
|
||||||
|
const imgUrl = ref({})
|
||||||
const rules = computed(() => {
|
const rules = computed(() => {
|
||||||
const commonRules = {
|
const commonRules = {
|
||||||
imageUrl: [
|
imageUrl: [
|
||||||
@@ -81,6 +82,10 @@ const rules = computed(() => {
|
|||||||
? {...commonRules, targetId: [{ required: true, message: '文章 id 不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '文章 id 不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] }
|
? {...commonRules, targetId: [{ required: true, message: '文章 id 不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '文章 id 不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] }
|
||||||
: {...commonRules, targetUrl: [{ required: true, message: '网址路径不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '网址路径不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] };
|
: {...commonRules, targetUrl: [{ required: true, message: '网址路径不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '网址路径不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] };
|
||||||
});
|
});
|
||||||
|
const handleSuccessImg = (res:string) => {
|
||||||
|
console.log(res,'图片地址')
|
||||||
|
carousalData.value.imageUrl = res
|
||||||
|
}
|
||||||
const typeOption = reactive([
|
const typeOption = reactive([
|
||||||
{ value: 'article', label: '文章' },
|
{ value: 'article', label: '文章' },
|
||||||
{ value: 'url', label: '地址' },
|
{ value: 'url', label: '地址' },
|
||||||
@@ -97,6 +102,8 @@ watch(
|
|||||||
() => props.carousal,
|
() => props.carousal,
|
||||||
(newClassify: CreateCarousalsRequest) => {
|
(newClassify: CreateCarousalsRequest) => {
|
||||||
carousalData.value = Object.assign({}, newClassify)
|
carousalData.value = Object.assign({}, newClassify)
|
||||||
|
const carousalObj = Object.assign({},newClassify)
|
||||||
|
imgUrl.value = { url: carousalObj.imageUrl || '' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: true,
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<TDialog
|
<t-dialog
|
||||||
width="40%"
|
width="40%"
|
||||||
:header="headerText"
|
:header="header"
|
||||||
:confirmBtn="confirmBtnText"
|
:confirmBtn="confirmBtn"
|
||||||
:closeOnOverlayClick="false"
|
:closeOnOverlayClick="false"
|
||||||
@close="handleClose"
|
@close="handleCloseDialog"
|
||||||
@confirm="handleSave"
|
@confirm="SaveCategoryData"
|
||||||
>
|
>
|
||||||
<TForm ref="formRef" :data="categoryData" :rules="rules" resetType="initial">
|
<t-space direction="vertical" style="width: 100%">
|
||||||
<TFormItem label="分类名称:" name="name" help="名称长度小于5个汉字,大于2个汉字">
|
<TForm ref="form" :data="categoryData" :rules="rules" resetType="initial">
|
||||||
<t-input v-model.trim="categoryData.name" clearable placeholder="请输入分类名称" />
|
<TFormItem label="分类名称:" name="name" help="名称长度小于5个汉字,大于2个汉字">
|
||||||
</TFormItem>
|
<t-input v-model.trim="categoryData.name" clearable placeholder="请输入分类名称" />
|
||||||
<TFormItem label="分类编号:" name="code" help="编号由大于4个字符的英文字母组成">
|
</TFormItem>
|
||||||
<t-input v-model.trim="categoryData.code" clearable placeholder="请输入分类编号" />
|
<TFormItem label="分类编号:" name="code" help="编号由大于4个字符的英文字母组成">
|
||||||
</TFormItem>
|
<t-input v-model.trim="categoryData.code" clearable placeholder="请输入分类编号" />
|
||||||
<TFormItem label="排序级别:" name="order" help="排序级别由正整数组成">
|
</TFormItem>
|
||||||
<t-input-number
|
<TFormItem label="排序级别:" name="order" help="排序级别由正整数组成">
|
||||||
:min="0"
|
<t-input-number
|
||||||
name="order"
|
:min="0"
|
||||||
theme="normal"
|
name="order"
|
||||||
class="!w-full"
|
theme="normal"
|
||||||
placeholder="请输入排序级别"
|
class="!w-full"
|
||||||
v-model.trim="categoryData.order"
|
placeholder="请输入排序级别"
|
||||||
></t-input-number>
|
v-model.trim="categoryData.order"
|
||||||
</TFormItem>
|
></t-input-number>
|
||||||
</TForm>
|
</TFormItem>
|
||||||
</TDialog>
|
</TForm>
|
||||||
|
</t-space>
|
||||||
|
</t-dialog>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { Category } from '@/model/category'
|
import type { Category } from '@/model/category'
|
||||||
@@ -49,6 +51,16 @@ const rules: FormProps['rules'] = {
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '分类名称不能为空',
|
||||||
|
type: 'error',
|
||||||
|
trigger: 'change'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
whitespace: true,
|
||||||
|
message: '分类名称不能为空'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
min: 4,
|
min: 4,
|
||||||
message: '输入汉字长度应在2到5之间',
|
message: '输入汉字长度应在2到5之间',
|
||||||
@@ -69,6 +81,16 @@ const rules: FormProps['rules'] = {
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '分类编号不能为空',
|
||||||
|
type: 'error',
|
||||||
|
trigger: 'change'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
whitespace: true,
|
||||||
|
message: '分类编号不能为空'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
min: 4,
|
min: 4,
|
||||||
message: '输入字符应大于4个字符长度',
|
message: '输入字符应大于4个字符长度',
|
||||||
@@ -89,6 +111,16 @@ const rules: FormProps['rules'] = {
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '排序级别不能为空',
|
||||||
|
type: 'error',
|
||||||
|
trigger: 'change'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
whitespace: true,
|
||||||
|
message: '排序级别不能为空'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
pattern: /^[1-9]\d*$/,
|
pattern: /^[1-9]\d*$/,
|
||||||
message: '排序级别必须为正整数',
|
message: '排序级别必须为正整数',
|
||||||
@@ -107,26 +139,27 @@ watch(
|
|||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
success: [void]
|
success: [void]
|
||||||
}>()
|
}>()
|
||||||
const handleSave = async () => {
|
const SaveCategoryData = async () => {
|
||||||
if (!formRef.value) return
|
if (form.value) {
|
||||||
|
const valid = await form.value.validate()
|
||||||
const valid = await formRef.value.validate()
|
if (valid && typeof valid === 'boolean') {
|
||||||
if (valid === true) {
|
const { code, name, order, id } = categoryData
|
||||||
const { code, name, order, id } = categoryData
|
if (!props.isEdit) {
|
||||||
if (!props.category) {
|
await createCategoryRequest({ code, name, order })
|
||||||
await createCategoryRequest({ code, name, order })
|
} else {
|
||||||
} else {
|
await updateCategoryByIdRequest(id, { code, name, order })
|
||||||
await updateCategoryByIdRequest(id, { code, name, order })
|
}
|
||||||
|
MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}分类成功`)
|
||||||
|
emit('success')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
MessagePlugin.success(`${props.category ? '编辑' : '创建'}分类成功`)
|
|
||||||
emit('success')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const handleCloseDialog = () => {
|
||||||
const handleClose = () => {
|
// 数据&&规则校验结果重置
|
||||||
if (!formRef.value) return
|
if (form.value) {
|
||||||
|
form.value.reset()
|
||||||
formRef.value.reset()
|
form.value.clearValidate()
|
||||||
formRef.value.clearValidate()
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { uploadFileOld } from '@/api/file'
|
import { uploadFile } from '@/api/file'
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import type { UploadFile } from 'tdesign-vue-next'
|
import type { UploadFile } from 'tdesign-vue-next'
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ watch(() => props.modelValue, (value) => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<TUpload theme="image" accept="image/jpeg,image/png" :request-method="uploadFileOld" v-model="fileList">
|
<TUpload theme="image" accept="image/jpeg,image/png" :request-method="uploadFile" v-model="fileList">
|
||||||
</TUpload>
|
</TUpload>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { PetVariety } from '@/model/pet-variety'
|
|
||||||
import { type FormInstanceFunctions, type FormRules, MessagePlugin } from 'tdesign-vue-next'
|
|
||||||
import { createPetVariety, editPetVariety } from '@/api/petVariety'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
data: PetVariety | null
|
|
||||||
}>()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const formData = ref<{
|
|
||||||
name: string
|
|
||||||
}>({
|
|
||||||
name: ''
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.data,
|
|
||||||
(newData) => {
|
|
||||||
if (newData) {
|
|
||||||
formData.value = newData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const rules: FormRules<{ name: string }> = {
|
|
||||||
name: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '品种名称不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const formRef = ref<FormInstanceFunctions | null>(null)
|
|
||||||
const emits = defineEmits<{
|
|
||||||
success: [void]
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const editId = computed(() => props.data?.id)
|
|
||||||
const handleSave = async () => {
|
|
||||||
const validate = await formRef.value?.validate()
|
|
||||||
|
|
||||||
if (validate !== true) return
|
|
||||||
|
|
||||||
try {
|
|
||||||
editId.value
|
|
||||||
? await editPetVariety(editId.value, formData.value.name)
|
|
||||||
: await createPetVariety(formData.value.name)
|
|
||||||
await MessagePlugin.success(`${editId.value ? '编辑' : '创建'}成功`)
|
|
||||||
emits('success')
|
|
||||||
} finally {
|
|
||||||
formRef.value?.reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<TDialog @confirm="handleSave">
|
|
||||||
<TForm ref="formRef" :data="formData" :rules="rules" resetType="initial">
|
|
||||||
<TFormItem label="宠物品种名称" name="name">
|
|
||||||
<TInput v-model.trim="formData.name" clearable placeholder="请输入宠物品种名称" />
|
|
||||||
</TFormItem>
|
|
||||||
</TForm>
|
|
||||||
</TDialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { onMounted } from 'vue'
|
|
||||||
import RegularPage from '@/components/RegularPage.vue'
|
|
||||||
|
|
||||||
import { type BaseTableColumns, MessagePlugin } from 'tdesign-vue-next'
|
|
||||||
import { useSearchable } from '@/composables/useSearchable'
|
|
||||||
import { deleteProduct } from '@/api/product'
|
|
||||||
import type { Product } from '@/model/product'
|
|
||||||
import ProductDialog from '@/pages/product/components/ProductDialog.vue'
|
|
||||||
import ImagePreviewer from '@/components/ImagePreviewer.vue'
|
|
||||||
import type { PetVariety, SearchPetVarietyFilter } from '@/model/pet-variety'
|
|
||||||
import { deletePetVariety, searchPetVarieties } from '@/api/petVariety'
|
|
||||||
import PetVarietyDialog from '@/pages/pet-variety/components/PetVarietyDialog.vue'
|
|
||||||
const { data, loading, pagination, onPageChange, fetchData } = useSearchable<
|
|
||||||
SearchPetVarietyFilter,
|
|
||||||
PetVariety
|
|
||||||
>(searchPetVarieties)
|
|
||||||
|
|
||||||
const columns: BaseTableColumns = [
|
|
||||||
{
|
|
||||||
title: '品种名称',
|
|
||||||
colKey: 'name',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建时间',
|
|
||||||
colKey: 'createdTime',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
colKey: 'operation',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
onMounted(fetchData)
|
|
||||||
|
|
||||||
|
|
||||||
const productDialogVisible = ref(false)
|
|
||||||
|
|
||||||
const editData = ref<PetVariety | null>(null)
|
|
||||||
|
|
||||||
const handleEdit = (data: PetVariety) => {
|
|
||||||
editData.value = data
|
|
||||||
productDialogVisible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const handleDelete = async (id: string) => {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
await deletePetVariety(id)
|
|
||||||
await fetchData()
|
|
||||||
await MessagePlugin.success('删除成功')
|
|
||||||
} catch (e) {
|
|
||||||
await MessagePlugin.error('删除失败')
|
|
||||||
}finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const handleSuccess = async () => {
|
|
||||||
await fetchData()
|
|
||||||
productDialogVisible.value = false
|
|
||||||
editData.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
editData.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<RegularPage title="宠物品种">
|
|
||||||
<template #right-area>
|
|
||||||
<TButton @click="productDialogVisible = true">添加品种</TButton>
|
|
||||||
</template>
|
|
||||||
<TTable
|
|
||||||
class="w-full h-full"
|
|
||||||
row-key="id"
|
|
||||||
height="92%"
|
|
||||||
table-layout="auto"
|
|
||||||
:data="data"
|
|
||||||
:loading="loading"
|
|
||||||
:columns="columns"
|
|
||||||
cell-empty-content="-"
|
|
||||||
:paginationAffixedBottom="true"
|
|
||||||
:pagination="{
|
|
||||||
total: pagination.total,
|
|
||||||
current: pagination.page,
|
|
||||||
pageSize: pagination.size,
|
|
||||||
onChange: onPageChange
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
|
|
||||||
<template #operation="{ row }">
|
|
||||||
<TSpace :size="1">
|
|
||||||
<TButton variant="text" size="small" theme="primary" @click="() => handleEdit(row)"
|
|
||||||
>编辑</TButton
|
|
||||||
>
|
|
||||||
<t-popconfirm
|
|
||||||
theme="default"
|
|
||||||
content="确定删除此品种吗?"
|
|
||||||
@confirm="() => handleDelete(row.id)"
|
|
||||||
>
|
|
||||||
<TButton variant="text" size="small" theme="danger">删除</TButton>
|
|
||||||
</t-popconfirm>
|
|
||||||
</TSpace>
|
|
||||||
</template>
|
|
||||||
</TTable>
|
|
||||||
<PetVarietyDialog v-model:visible="productDialogVisible" :data="editData" @success="handleSuccess" @close="handleClose"></PetVarietyDialog>
|
|
||||||
</RegularPage>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { type CreateProductRequest, type Product, ProductCategory, productCategoryOptions } from '@/model/product'
|
|
||||||
import { type FormInstanceFunctions, type FormRules, MessagePlugin } from 'tdesign-vue-next'
|
|
||||||
import ImageUpload from '@/components/ImageUpload.vue'
|
|
||||||
import { createProduct, editProduct } from '@/api/product'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
data: Product | null
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const defaultData: CreateProductRequest = {
|
|
||||||
name: '',
|
|
||||||
photo: '',
|
|
||||||
category: ProductCategory.DRY_FOOD,
|
|
||||||
tags: [],
|
|
||||||
totalWeight: 0,
|
|
||||||
protein: 0,
|
|
||||||
fat: 0,
|
|
||||||
fiber: 0,
|
|
||||||
ash: 0,
|
|
||||||
moisture: 0,
|
|
||||||
meValue: undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const formData = ref<CreateProductRequest>(defaultData)
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.data,
|
|
||||||
(newData) => {
|
|
||||||
if (newData) {
|
|
||||||
// @ts-ignore
|
|
||||||
const existCategory = productCategoryOptions.find((item) => item.label === newData.category)
|
|
||||||
formData.value = {
|
|
||||||
name: newData.name,
|
|
||||||
category: existCategory ? existCategory.value : ProductCategory.DRY_FOOD,
|
|
||||||
photo: newData.photo,
|
|
||||||
tags: newData.tags,
|
|
||||||
protein: newData.protein,
|
|
||||||
fat: newData.fat,
|
|
||||||
fiber: newData.fiber,
|
|
||||||
ash: newData.ash,
|
|
||||||
moisture: newData.moisture,
|
|
||||||
totalWeight: newData.totalWeight,
|
|
||||||
meValue: newData.meValue ?? undefined,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
formData.value = defaultData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const rules: FormRules<CreateProductRequest> = {
|
|
||||||
name: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '产品名称不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
photo: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '产品图片不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
totalWeight: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '净重量不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
protein: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '蛋白质不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
fat: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '脂肪不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
fiber: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '纤维不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
ash: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '粗灰分不能为空'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
moisture: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '水分不能为空'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const formRef = ref<FormInstanceFunctions | null>(null)
|
|
||||||
const emits = defineEmits<{
|
|
||||||
success: [void]
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const editId = computed(() => props.data?.id)
|
|
||||||
const handleSave = async () => {
|
|
||||||
const validate = await formRef.value?.validate()
|
|
||||||
|
|
||||||
if (validate !== true) return
|
|
||||||
|
|
||||||
try {
|
|
||||||
editId.value
|
|
||||||
? await editProduct(editId.value, formData.value)
|
|
||||||
: await createProduct(formData.value)
|
|
||||||
await MessagePlugin.success(`${editId.value ? '编辑' : '创建'}成功`)
|
|
||||||
emits('success')
|
|
||||||
} finally {
|
|
||||||
formRef.value?.reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<TDialog @confirm="handleSave">
|
|
||||||
<TForm ref="formRef" :data="formData" :rules="rules" resetType="initial">
|
|
||||||
<TFormItem label="产品名称" name="name">
|
|
||||||
<TInput v-model.trim="formData.name" clearable placeholder="请输入产品名称" />
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="产品分类" name="category">
|
|
||||||
<TSelect v-model="formData.category" :options="productCategoryOptions" />
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="产品名称" name="photo">
|
|
||||||
<ImageUpload v-model="formData.photo" />
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="产品标签" name="tags">
|
|
||||||
<TTagInput v-model="formData.tags" clearable placeholder="请输入产品标签" />
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="净重量" name="totalWeight">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.totalWeight"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入净重量"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="g"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="蛋白质" name="protein">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.protein"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入蛋白质含比"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="%"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="脂肪" name="fat">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.fat"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入脂肪含比"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="%"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="纤维" name="fiber">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.fiber"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入纤维含比"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="%"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="粗灰分" name="ash">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.ash"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入粗灰分含比"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="%"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="水分" name="moisture">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.moisture"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入水分含比"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="%"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
<TFormItem label="ME值" name="meValue" help="可选项,直接配置每克产品的代谢能(kcal/g)。如果填写则优先使用此值,否则通过营养成分自动计算">
|
|
||||||
<TInputNumber
|
|
||||||
v-model="formData.meValue"
|
|
||||||
clearable
|
|
||||||
placeholder="请输入ME值(可选)"
|
|
||||||
theme="normal"
|
|
||||||
align="right"
|
|
||||||
suffix="kcal/g"
|
|
||||||
:decimalPlaces="2"
|
|
||||||
:min="0"
|
|
||||||
></TInputNumber>
|
|
||||||
</TFormItem>
|
|
||||||
</TForm>
|
|
||||||
</TDialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
@@ -1,179 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { onMounted } from 'vue'
|
|
||||||
import RegularPage from '@/components/RegularPage.vue'
|
|
||||||
|
|
||||||
import { type BaseTableColumns, MessagePlugin } from 'tdesign-vue-next'
|
|
||||||
import { useSearchable } from '@/composables/useSearchable'
|
|
||||||
import { deleteProduct, searchProducts } from '@/api/product'
|
|
||||||
import type { Product, SearchProductFilter } from '@/model/product'
|
|
||||||
import ProductDialog from '@/pages/product/components/ProductDialog.vue'
|
|
||||||
import ImagePreviewer from '@/components/ImagePreviewer.vue'
|
|
||||||
const { data, loading, pagination, onPageChange, fetchData } = useSearchable<
|
|
||||||
SearchProductFilter,
|
|
||||||
Product
|
|
||||||
>(searchProducts)
|
|
||||||
|
|
||||||
const columns: BaseTableColumns = [
|
|
||||||
{
|
|
||||||
title: '产品名称',
|
|
||||||
colKey: 'name',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品分类',
|
|
||||||
colKey: 'category',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品图片',
|
|
||||||
colKey: 'photo',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品标签',
|
|
||||||
colKey: 'tags',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '净重',
|
|
||||||
colKey: 'totalWeight',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'ME值',
|
|
||||||
colKey: 'meValue',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '总能量',
|
|
||||||
colKey: 'totalCalories',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '蛋白质',
|
|
||||||
colKey: 'protein',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '脂肪',
|
|
||||||
colKey: 'fat',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '纤维',
|
|
||||||
colKey: 'fiber',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '粗灰分',
|
|
||||||
colKey: 'ash',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '水分',
|
|
||||||
colKey: 'moisture',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建时间',
|
|
||||||
colKey: 'createdTime',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
colKey: 'operation',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
onMounted(fetchData)
|
|
||||||
|
|
||||||
|
|
||||||
const productDialogVisible = ref(false)
|
|
||||||
|
|
||||||
const editData = ref<Product | null>(null)
|
|
||||||
|
|
||||||
const handleEdit = (data: Product) => {
|
|
||||||
editData.value = data
|
|
||||||
productDialogVisible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const handleDelete = async (id: string) => {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
await deleteProduct(id)
|
|
||||||
await fetchData()
|
|
||||||
await MessagePlugin.success('删除成功')
|
|
||||||
} catch (e) {
|
|
||||||
await MessagePlugin.error('删除失败')
|
|
||||||
}finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const handleSuccess = async () => {
|
|
||||||
await fetchData()
|
|
||||||
productDialogVisible.value = false
|
|
||||||
editData.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
editData.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<RegularPage title="产品管理">
|
|
||||||
<template #right-area>
|
|
||||||
<TButton @click="productDialogVisible = true">创建产品</TButton>
|
|
||||||
</template>
|
|
||||||
<TTable
|
|
||||||
class="w-full h-full"
|
|
||||||
row-key="id"
|
|
||||||
height="92%"
|
|
||||||
table-layout="auto"
|
|
||||||
:data="data"
|
|
||||||
:loading="loading"
|
|
||||||
:columns="columns"
|
|
||||||
cell-empty-content="-"
|
|
||||||
:paginationAffixedBottom="true"
|
|
||||||
:pagination="{
|
|
||||||
total: pagination.total,
|
|
||||||
current: pagination.page,
|
|
||||||
pageSize: pagination.size,
|
|
||||||
onChange: onPageChange
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
|
|
||||||
<template #photo="{ row }">
|
|
||||||
<ImagePreviewer :url="row.photo"/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #tags="{ row }">
|
|
||||||
<TSpace>
|
|
||||||
<TTag v-for="tag in row.tags" :key="tag">{{ tag }}</TTag>
|
|
||||||
</TSpace>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #totalWeight="{ row }">
|
|
||||||
{{ row.totalWeight }}g
|
|
||||||
</template>
|
|
||||||
<template #meValue="{ row }">
|
|
||||||
<span v-if="row.meValue">{{ row.meValue }} kcal/g</span>
|
|
||||||
<span v-else class="text-gray-400">自动计算</span>
|
|
||||||
</template>
|
|
||||||
<template #totalCalories="{ row }">
|
|
||||||
{{ row.totalCalories }}kcal
|
|
||||||
</template>
|
|
||||||
<template #operation="{ row }">
|
|
||||||
<TSpace :size="1">
|
|
||||||
<TButton variant="text" size="small" theme="primary" @click="() => handleEdit(row)"
|
|
||||||
>编辑</TButton
|
|
||||||
>
|
|
||||||
<t-popconfirm
|
|
||||||
theme="default"
|
|
||||||
content="确定删除此产品吗?"
|
|
||||||
@confirm="() => handleDelete(row.id)"
|
|
||||||
>
|
|
||||||
<TButton variant="text" size="small" theme="danger">删除</TButton>
|
|
||||||
</t-popconfirm>
|
|
||||||
</TSpace>
|
|
||||||
</template>
|
|
||||||
</TTable>
|
|
||||||
<ProductDialog v-model:visible="productDialogVisible" :data="editData" @success="handleSuccess" @close="handleClose"></ProductDialog>
|
|
||||||
</RegularPage>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
@@ -13,8 +13,8 @@ const props = defineProps<{
|
|||||||
const roles = ref<string[]>([])
|
const roles = ref<string[]>([])
|
||||||
|
|
||||||
watch(() => props.user, (user) => {
|
watch(() => props.user, (user) => {
|
||||||
if (user && user.roles) {
|
if (user) {
|
||||||
roles.value = user.roles.map((role: Role) => role.name)
|
roles.value = user.roles.map(role => role.name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ const handleConfirm = async () => {
|
|||||||
<TDialog>
|
<TDialog>
|
||||||
<TForm v-if="user">
|
<TForm v-if="user">
|
||||||
<TFormItem label="用户">
|
<TFormItem label="用户">
|
||||||
<div>{{ user.name || user.username }}</div>
|
<div>{{ user.name }}</div>
|
||||||
</TFormItem>
|
</TFormItem>
|
||||||
<TFormItem label="角色">
|
<TFormItem label="角色">
|
||||||
<TSelect v-model="roles" :options="options" multiple></TSelect>
|
<TSelect v-model="roles" :options="options" multiple></TSelect>
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ const handleRoleSettingSuccess = () => {
|
|||||||
<TFormItem label="手机号码">
|
<TFormItem label="手机号码">
|
||||||
<TInput placeholder="请输入需要搜索的用户姓名"></TInput>
|
<TInput placeholder="请输入需要搜索的用户姓名"></TInput>
|
||||||
</TFormItem>
|
</TFormItem>
|
||||||
</TCol>7
|
</TCol>
|
||||||
<TCol :span="3">
|
<TCol :span="3">
|
||||||
<TFormItem label="手机号码">
|
<TFormItem label="手机号码">
|
||||||
<TInput placeholder="请输入需要搜索的用户姓名"></TInput>
|
<TInput placeholder="请输入需要搜索的用户姓名"></TInput>
|
||||||
|
|||||||
@@ -32,24 +32,6 @@ export const asyncRoutes: RouteRecordRaw[] = [
|
|||||||
icon: 'image'
|
icon: 'image'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'product',
|
|
||||||
path: 'product',
|
|
||||||
meta: {
|
|
||||||
title: '产品管理',
|
|
||||||
icon: 'shop'
|
|
||||||
},
|
|
||||||
component: () => import('@/pages/product/index.vue')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'pet-variety',
|
|
||||||
path: 'pet-variety',
|
|
||||||
meta: {
|
|
||||||
title: '宠物品种',
|
|
||||||
icon: 'cat'
|
|
||||||
},
|
|
||||||
component: () => import('@/pages/pet-variety/index.vue')
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"composite": true,
|
"composite": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Bundler",
|
"moduleResolution": "Bundler",
|
||||||
"types": ["node"]
|
"types": ["node"]
|
||||||
|
|||||||
Reference in new issue
Block a user