@cqsjjb/course-res-design 0.1.0-beta.3 → 0.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CourseInfo.js CHANGED
@@ -2,11 +2,54 @@ import React from 'react';
2
2
  import { Descriptions } from 'antd';
3
3
  import './CourseInfo.less';
4
4
  import { getLabelName } from './utils/tools';
5
- import { getCourseInfo } from './api/courseLibrary';
5
+ import { getCourseInfo, typePageAction } from './api/courseLibrary';
6
+ /** 内置字段 labelTypeCode -> { label, valueKey, enumMap } */
7
+ const INNER_FIELD_MAP = {
8
+ INDUSTRY: {
9
+ label: '行业',
10
+ valueKey: 'categorizeName'
11
+ },
12
+ JOB_TYPE: {
13
+ label: '工种',
14
+ valueKey: 'jobTypeName'
15
+ },
16
+ YEAR: {
17
+ label: '年份',
18
+ valueKey: 'yearValue'
19
+ },
20
+ REGION: {
21
+ label: '区域',
22
+ valueKey: 'regionName'
23
+ },
24
+ CHANNEL: {
25
+ label: '渠道',
26
+ valueKey: 'courseChannelEnum',
27
+ enumMap: COURSE_CHANNEL_ENUM
28
+ },
29
+ PRODUCER: {
30
+ label: '制作方',
31
+ valueKey: 'lecturerName'
32
+ },
33
+ RESOURCE_TYPE: {
34
+ label: '资源类型',
35
+ valueKey: 'courseModeEnum',
36
+ enumMap: COURSE_MODE_ENUM
37
+ },
38
+ RESOURCE_FORM: {
39
+ label: '资源形式',
40
+ valueKey: 'courseModeEnum',
41
+ enumMap: COURSE_MODE_ENUM
42
+ },
43
+ STAR: {
44
+ label: '星级',
45
+ valueKey: 'star'
46
+ }
47
+ };
6
48
  export default class CourseInfo extends React.Component {
7
49
  state = {
8
50
  loading: false,
9
- courseInfo: {}
51
+ courseInfo: {},
52
+ industryFields: []
10
53
  };
11
54
  componentDidMount() {
12
55
  // 如果提供了 courseId,则内部获取数据
@@ -41,6 +84,13 @@ export default class CourseInfo extends React.Component {
41
84
  loading: true
42
85
  });
43
86
  try {
87
+ const labelRes = await typePageAction();
88
+ const data = labelRes.data;
89
+ const arr = Array.isArray(data) ? data : [];
90
+ const industryFields = arr.filter(item => item?.classificationType === 'INNER' && item?.useEnum === 'TRUE' && item?.requiredEnum === 'TRUE');
91
+ this.setState({
92
+ industryFields
93
+ });
44
94
  const infoRes = await (this.props.getCourseInfoAction ? this.props.getCourseInfoAction() : getCourseInfo({
45
95
  id: courseId,
46
96
  apiBaseName: apiBaseName
@@ -58,10 +108,22 @@ export default class CourseInfo extends React.Component {
58
108
  });
59
109
  }
60
110
  }
111
+ getInnerFieldDisplay = item => {
112
+ const config = INNER_FIELD_MAP[item.labelTypeCode];
113
+ const label = config?.label ?? item.labelTypeName ?? '-';
114
+ const raw = config?.valueKey ? this.state.courseInfo[config.valueKey] : this.state.courseInfo[item.labelTypeCode];
115
+ const value = config?.enumMap && raw != null ? config.enumMap[raw] : raw;
116
+ return {
117
+ label,
118
+ value: value ?? '-'
119
+ };
120
+ };
61
121
  render() {
62
122
  const {
63
123
  loading,
64
- courseInfo: stateCourseInfo
124
+ courseInfo: stateCourseInfo,
125
+ industryFields,
126
+ customFields
65
127
  } = this.state;
66
128
  // 如果提供了 courseId,优先使用内部 state 的数据,否则使用 props
67
129
  const hasCourseId = !!this.props.courseId;
@@ -77,10 +139,6 @@ export default class CourseInfo extends React.Component {
77
139
  }, /*#__PURE__*/React.createElement(Descriptions.Item, {
78
140
  label: "\u8BFE\u7A0B\u540D\u79F0"
79
141
  }, courseInfo?.courseName || '--'), /*#__PURE__*/React.createElement(Descriptions.Item, {
80
- label: "\u7C7B\u76EE"
81
- }, courseInfo?.categorizeName ? courseInfo.categorizeName : courseInfo?.courseTypeLabel ? getLabelName(courseInfo?.courseTypeLabel) : '--'), courseInfo?.year && /*#__PURE__*/React.createElement(Descriptions.Item, {
82
- label: "\u5E74\u4EFD"
83
- }, courseInfo.year), /*#__PURE__*/React.createElement(Descriptions.Item, {
84
142
  label: "\u8BFE\u7A0B\u4ECB\u7ECD"
85
143
  }, courseInfo?.courseDescription ? /*#__PURE__*/React.createElement("div", {
86
144
  dangerouslySetInnerHTML: {
@@ -93,11 +151,21 @@ export default class CourseInfo extends React.Component {
93
151
  alt: "\u8BFE\u7A0B\u5C01\u9762",
94
152
  width: 84,
95
153
  height: 50
96
- }) : '--'), courseInfo?.star && /*#__PURE__*/React.createElement(Descriptions.Item, {
97
- label: "\u661F\u7EA7"
98
- }, courseInfo.star), courseInfo?.jobTypeName && /*#__PURE__*/React.createElement(Descriptions.Item, {
99
- label: "\u5DE5\u79CD"
100
- }, courseInfo.jobTypeName), /*#__PURE__*/React.createElement(Descriptions.Item, {
154
+ }) : '--'), industryFields.map((item, idx) => {
155
+ const {
156
+ label,
157
+ value
158
+ } = this.getInnerFieldDisplay(item);
159
+ return /*#__PURE__*/React.createElement(Descriptions.Item, {
160
+ key: item.id ?? idx,
161
+ label: label
162
+ }, value);
163
+ }), JSON.parse(stateCourseInfo.dynamicTags || '[]')?.map((item, idx) => {
164
+ return /*#__PURE__*/React.createElement(Descriptions.Item, {
165
+ key: item.id ?? idx,
166
+ label: item.fieldkey
167
+ }, item.fieldValue);
168
+ }), /*#__PURE__*/React.createElement(Descriptions.Item, {
101
169
  label: "\u8BFE\u7A0B\u6807\u7B7E"
102
170
  }, getLabelName(courseInfo?.courseLabel) || '--')));
103
171
  }
@@ -35,4 +35,10 @@ export const getCourseMenu = params => {
35
35
  */
36
36
  export const getCourseInfo = params => {
37
37
  return request.get(`/${getApiBaseName()}/course/${params.id}`);
38
- };
38
+ };
39
+
40
+ // 查询标签分类管理列表
41
+ export const typePageAction = params =>
42
+ request.get(`/${getApiBaseName()}/typeManage`, {
43
+ params
44
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/course-res-design",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "课程资源设计组件库",
5
5
  "main": "index.js",
6
6
  "author": "jiaoxiwei",
package/utils/index.js CHANGED
@@ -1,9 +1,9 @@
1
- /**
2
- * 获取API Host
3
- * @returns {string} API Host地址,如果VITE_API_HOST为空则返回location.origin
4
- */
5
- export function getApiHost() {
6
- return process.env.NODE_ENV === 'development' ?
7
- process.env?.app?.API_HOST || 'https://yjap.cqzxaq.com'
8
- : window.location.origin;
9
- }
1
+ /**
2
+ * 获取API Host
3
+ * @returns {string} API Host地址,如果VITE_API_HOST为空则返回location.origin
4
+ */
5
+ export function getApiHost() {
6
+ return process.env.NODE_ENV === 'development' ?
7
+ process.env?.app?.API_HOST || 'https://yjap.cqzxaq.com'
8
+ : window.location.origin;
9
+ }
package/utils/request.js CHANGED
@@ -1,76 +1,76 @@
1
- import axios from 'axios';
2
- import { getApiHost } from './index';
3
-
4
- export const API_BASE_NAME = 'res';
5
-
6
- // 创建 axios 实例
7
- const request = axios.create({
8
- // baseURL: 'http://192.168.3.47:3000',
9
- // baseURL: 'http://10.43.82.219',
10
- baseURL: getApiHost(),
11
- // mock 阶段使用测试服务器
12
- timeout: 10000 // 请求超时时间
13
- });
14
-
15
- // 请求拦截器 - 添加 token
16
- request.interceptors.request.use(
17
- config => {
18
- // 从 sessionStorage 获取 token
19
- const token = sessionStorage.getItem('token');
20
- if (token) {
21
- config.headers.token = token;
22
- }
23
- return config;
24
- },
25
- error => {
26
- return Promise.reject(error);
27
- }
28
- );
29
-
30
- // 响应拦截器
31
- request.interceptors.response.use(
32
- response => {
33
- // 直接返回 response.data,因为 axios 默认返回 response.data
34
- // 如果后端返回格式是 { respCode: '0000', data: {...} },则统一处理
35
- if (response.data) {
36
- // 统一处理响应格式,兼容不同的后端响应结构
37
- const data = response.data;
38
- // 如果响应中有 respCode,判断是否成功
39
- if (data.respCode !== undefined) {
40
- return {
41
- success: data.respCode === '0000',
42
- data: data.data || data,
43
- ...data
44
- };
45
- }
46
- // 如果响应中有 success 字段,直接使用
47
- if (data.success !== undefined) {
48
- return {
49
- success: data.success,
50
- data: data.data || data,
51
- ...data
52
- };
53
- }
54
- // 默认返回数据
55
- return {
56
- success: true,
57
- data: data.data || data,
58
- ...data
59
- };
60
- }
61
- return response;
62
- },
63
- error => {
64
- console.error('请求失败:', error);
65
- // 处理错误响应
66
- if (error.response && error.response.data) {
67
- return Promise.reject({
68
- success: false,
69
- message: error.response.data.message || error.message,
70
- ...error.response.data
71
- });
72
- }
73
- return Promise.reject(error);
74
- }
75
- );
76
- export default request;
1
+ import axios from 'axios';
2
+ import { getApiHost } from './index';
3
+
4
+ export const API_BASE_NAME = 'res';
5
+
6
+ // 创建 axios 实例
7
+ const request = axios.create({
8
+ // baseURL: 'http://192.168.3.47:3000',
9
+ // baseURL: 'http://10.43.82.219',
10
+ baseURL: getApiHost(),
11
+ // mock 阶段使用测试服务器
12
+ timeout: 10000 // 请求超时时间
13
+ });
14
+
15
+ // 请求拦截器 - 添加 token
16
+ request.interceptors.request.use(
17
+ config => {
18
+ // 从 sessionStorage 获取 token
19
+ const token = sessionStorage.getItem('token');
20
+ if (token) {
21
+ config.headers.token = token;
22
+ }
23
+ return config;
24
+ },
25
+ error => {
26
+ return Promise.reject(error);
27
+ }
28
+ );
29
+
30
+ // 响应拦截器
31
+ request.interceptors.response.use(
32
+ response => {
33
+ // 直接返回 response.data,因为 axios 默认返回 response.data
34
+ // 如果后端返回格式是 { respCode: '0000', data: {...} },则统一处理
35
+ if (response.data) {
36
+ // 统一处理响应格式,兼容不同的后端响应结构
37
+ const data = response.data;
38
+ // 如果响应中有 respCode,判断是否成功
39
+ if (data.respCode !== undefined) {
40
+ return {
41
+ success: data.respCode === '0000',
42
+ data: data.data || data,
43
+ ...data
44
+ };
45
+ }
46
+ // 如果响应中有 success 字段,直接使用
47
+ if (data.success !== undefined) {
48
+ return {
49
+ success: data.success,
50
+ data: data.data || data,
51
+ ...data
52
+ };
53
+ }
54
+ // 默认返回数据
55
+ return {
56
+ success: true,
57
+ data: data.data || data,
58
+ ...data
59
+ };
60
+ }
61
+ return response;
62
+ },
63
+ error => {
64
+ console.error('请求失败:', error);
65
+ // 处理错误响应
66
+ if (error.response && error.response.data) {
67
+ return Promise.reject({
68
+ success: false,
69
+ message: error.response.data.message || error.message,
70
+ ...error.response.data
71
+ });
72
+ }
73
+ return Promise.reject(error);
74
+ }
75
+ );
76
+ export default request;