From f3a14c0d97f0ae5486ab3e94006178fe4f10cf8d Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Fri, 21 Jan 2022 13:34:59 +0800 Subject: [PATCH] fix post --- admin/config/config.ts | 3 + admin/src/app.tsx | 14 ++ admin/src/pages/account/center/service.ts | 11 ++ admin/src/pages/course/option/index.tsx | 163 +++++++++++++++++++--- admin/src/pages/course/option/service.ts | 3 + 5 files changed, 175 insertions(+), 19 deletions(-) diff --git a/admin/config/config.ts b/admin/config/config.ts index 38dd0d7..ece75a2 100644 --- a/admin/config/config.ts +++ b/admin/config/config.ts @@ -5,6 +5,9 @@ import defaultSettings from './defaultSettings'; import proxy from './proxy'; const { REACT_APP_ENV } = process.env; export default defineConfig({ + history:{ + type: 'hash' + }, hash: true, antd: {}, dva: { diff --git a/admin/src/app.tsx b/admin/src/app.tsx index 599777e..b062996 100644 --- a/admin/src/app.tsx +++ b/admin/src/app.tsx @@ -6,6 +6,9 @@ import RightContent from '@/components/RightContent'; import Footer from '@/components/Footer'; import { currentUser as queryCurrentUser } from './services/ant-design-pro/api'; import { BookOutlined, LinkOutlined } from '@ant-design/icons'; +import { RequestConfig } from 'umi'; +import { ResponseError } from 'umi-request'; +import { notification } from 'antd'; const isDev = process.env.NODE_ENV === 'development'; const loginPath = '/user/login'; @@ -70,3 +73,14 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => { ...initialState?.settings, }; }; + +/** request 用于配置全局的网络请求,你可以在这里做拦截器,全局错误处理,鉴权的配置。*/ +export const request: RequestConfig = { + errorHandler: (error: ResponseError) => { + notification.error({ + description: '您的网络发生异常,无法连接服务器', + message: '网络异常', + }); + throw error; + }, +}; \ No newline at end of file diff --git a/admin/src/pages/account/center/service.ts b/admin/src/pages/account/center/service.ts index b6bfad7..a98d237 100644 --- a/admin/src/pages/account/center/service.ts +++ b/admin/src/pages/account/center/service.ts @@ -12,3 +12,14 @@ export async function queryFakeList(params: { params, }); } + +/** 查询用户信息 */ +export async function queryUserInfo(params: { + person_id: number; + identity_id: number; + u_type: number; +}): Promise<{ data: any }> { + return request('/dsideal_yy/ypt/userinfo/getUserInfo', { + params, + }); +} \ No newline at end of file diff --git a/admin/src/pages/course/option/index.tsx b/admin/src/pages/course/option/index.tsx index 2c709d0..8a67619 100644 --- a/admin/src/pages/course/option/index.tsx +++ b/admin/src/pages/course/option/index.tsx @@ -1,20 +1,22 @@ import React, { useState, useRef } from 'react'; -import { useRequest } from 'umi'; import { PlusOutlined, TagsOutlined, UploadOutlined } from '@ant-design/icons'; -import { Button, message, Input, Drawer, Modal, Col, Row, Space, Upload } from 'antd'; +import { Button, message, Modal, Col, Row, Space, Upload } from 'antd'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import type { ProColumns, ActionType } from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table'; -import { BetaSchemaForm, ModalForm, ProFormText, ProFormTextArea } from '@ant-design/pro-form'; +import { BetaSchemaForm, ModalForm } from '@ant-design/pro-form'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import ProDescriptions from '@ant-design/pro-descriptions'; import type { FormValueType } from './components/UpdateForm'; -import UpdateForm from './components/UpdateForm'; + import { queryTagList, saveCourse, removeCourse, queryCourseList } from './service'; import type { TableListItem, TableListPagination } from './data'; import Tags from './components/Tags'; import type { DataItem } from '@antv/data-set/lib/transform/tag-cloud'; import { VideoJS } from './components/VideoJS'; +import { v4 as uuidv4 } from 'uuid'; + +const uuid = uuidv4(); /** * 添加课程 @@ -25,7 +27,7 @@ const handleAdd = async (fields: TableListItem) => { const hide = message.loading('正在添加'); try { - await saveCourse({ ...fields }); + await saveCourse({ ...fields, attachment_filesize:0, attachment_json: `{"img":"", "url": "down/M3u8/${uuid?.substr(0,2)}/${uuid}.m3u8"}` }); hide(); message.success('添加成功'); return true; @@ -82,6 +84,7 @@ const handleRemove = async (selectedRows: TableListItem[]) => { } }; + const CourseList: React.FC = () => { /** 新建窗口的弹窗 */ @@ -96,6 +99,10 @@ const CourseList: React.FC = () => { const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); + const [uploadFileName, SetUploadFileName] = useState(); + const [uploadFileExt, SetUploadFileExt] = useState(); + + /** 列表项定义 */ const columns: ProColumns[] = [ { @@ -112,6 +119,19 @@ const CourseList: React.FC = () => { hideInDescriptions: false, hideInForm: false, hideInSearch: true, + formItemProps: { + // 参照 https://ant.design/components/form-cn/#Rule + rules: [ + { + required: true, + message: '此项为必填项', + }, + { + max: 50, + message: '最大长度为50字符', + } + ], + }, // 传递给 Form.Item 的配置 }, { title: '主讲教师', @@ -122,6 +142,19 @@ const CourseList: React.FC = () => { hideInForm: false, hideInSearch: true, renderText: (val: string) => `${val}`, + formItemProps: { + // 参照 https://ant.design/components/form-cn/#Rule + rules: [ + { + required: true, + message: '此项为必填项', + }, + { + max: 20, + message: '最大长度为20字符', + } + ], + }, // 传递给 Form.Item 的配置 }, { title: '课时', @@ -132,6 +165,19 @@ const CourseList: React.FC = () => { hideInForm: false, hideInSearch: true, renderText: (val: string) => `${val}`, + formItemProps: { + // 参照 https://ant.design/components/form-cn/#Rule + rules: [ + { + required: true, + message: '此项为必填项', + }, + { + max: 4, + message: '最大长度为4字符', + } + ], + }, // 传递给 Form.Item 的配置 }, { title: '课程描述', @@ -142,14 +188,52 @@ const CourseList: React.FC = () => { hideInForm: false, hideInSearch: true, renderText: (val: string) => `${val}`, + formItemProps: { + // 参照 https://ant.design/components/form-cn/#Rule + rules: [ + { + required: true, + message: '此项为必填项', + }, + { + max: 150, + message: '最大长度为150字符', + } + ], + }, // 传递给 Form.Item 的配置 }, { title: '标签', dataIndex: 'tag_name', sorter: false, valueType: 'select', - hideInForm: false, + hideInForm: true, renderText: (val: string) => `${val}`, + + }, + { + title: '标签', + dataIndex: 'tag_id', + sorter: false, + valueType: 'select', + hideInForm: false, + request: async () => { + const {data: Items} = await queryTagList({}); + const tags = [] + for(let i=0; i { hideInForm: false, hideInSearch: true, renderFormItem: () => ( - + { + console.log('file', file) + // 获取文件名 + SetUploadFileName(file?.name) ; + // 获取最后一个.的位置 + const index = file?.name.lastIndexOf("."); + // 获取后缀 + SetUploadFileExt(file?.name.substr(index+1)); + + }} + data={{ + name: uploadFileName, + chunk: 0, + chunks: 1, + key: `down/Syzx/${uuid?.substr(0,2)}/${uuid}.${uploadFileExt}` + }} + maxCount={1} + multiple={false} + > - ), - renderText: (val: string) => `${val}M`, + + ), + formItemProps: { + // 参照 https://ant.design/components/form-cn/#Rule + rules: [ + { + required: true, + message: '此项为必填项', + }, + ], + }, // 传递给 Form.Item 的配置 + //renderText: (val: string) => `${val}M`, }, { title: '视频大小', @@ -170,6 +284,15 @@ const CourseList: React.FC = () => { hideInForm: true, hideInSearch: true, renderText: (val: string) => `${val}M`, + formItemProps: { + // 参照 https://ant.design/components/form-cn/#Rule + rules: [ + { + required: true, + message: '此项为必填项', + }, + ], + }, // 传递给 Form.Item 的配置 }, { title: '创建时间', @@ -179,7 +302,6 @@ const CourseList: React.FC = () => { hideInTable: true, hideInForm: true, hideInSearch: false, - //renderText: (val: string) => `${val}`, }, { @@ -190,7 +312,6 @@ const CourseList: React.FC = () => { { - //console.log('entity', entity); setCurrentRow(record); handleDetailModalVisible(true); }} @@ -206,7 +327,11 @@ const CourseList: React.FC = () => { > 编辑 , - { }}> + { + handleRemove(record); + }}> 删除 , ], @@ -294,9 +419,9 @@ const CourseList: React.FC = () => { > 批量删除 - )} + { fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。 sources: [ { - src: (currentRow?.attachment_json?.url) || 'http://10.10.14.199/dsideal_yy/html/down/M3u8/2D/2D99BF1D-2F37-47FB-8A24-45112A236B8F.m3u8', // 测试地址后续请删除 + src: (currentRow?.attachment_json?.url) || '/dsideal_yy/html/down/M3u8/2D/2D99BF1D-2F37-47FB-8A24-45112A236B8F.m3u8', // 测试地址后续请删除 type: 'application/x-mpegURL' } ], @@ -412,9 +537,9 @@ const CourseList: React.FC = () => { wrapperCol={{ span: 12 }} onFinish={async (values: any) => { // 表单处理 - console.log('columns:', columns); - console.log('values:', values); - + //console.log('columns:', columns); + //console.log('values:', values); + handleAdd(values); }} submitter={{ render: (props, doms) => ( @@ -427,7 +552,7 @@ const CourseList: React.FC = () => { }} // action = '' title="新建" - columns={columns} + columns={columns||[]} /> @@ -441,7 +566,7 @@ const CourseList: React.FC = () => { }} footer={null} > - {currentRow?.name && ( + {currentRow?.course_id && ( layout="horizontal" layoutType="Form" diff --git a/admin/src/pages/course/option/service.ts b/admin/src/pages/course/option/service.ts index 246124f..8eb5468 100644 --- a/admin/src/pages/course/option/service.ts +++ b/admin/src/pages/course/option/service.ts @@ -33,6 +33,7 @@ export async function saveCourse(data: Record, options?: Record('/dsideal_yy/ypt/careerTraining/course/save', { data, method: 'POST', + requestType: 'form', ...(options || {}), }); } @@ -42,6 +43,7 @@ export async function removeCourse(data: { key: number[] }, options?: Record>('/dsideal_yy/ypt/careerTraining/course/delete', { data, method: 'POST', + requestType: 'form', ...(options || {}), }); } @@ -51,6 +53,7 @@ export async function queryCourseView(data: Record, options?: Recor return request('/dsideal_yy/ypt/careerTraining/course/view', { data, method: 'POST', + requestType: 'form', ...(options || {}), }); }