瀏覽代碼

fix:接口域名统一修改以及新增广告封面

zhubo 2 年之前
父節點
當前提交
c3e8ce4d10

+ 1 - 1
config/defaultSettings.ts

@@ -16,7 +16,7 @@ const proSettings: DefaultSettings = {
   },
   pwa: false,
   headerHeight: 48,
-  title: '中德论坛',
+  title: '中德精英俱乐部后台',
   menuHeaderRender: false,
 };
 

+ 1 - 6
config/proxy.ts

@@ -7,13 +7,8 @@
  */
 export default {
   dev: {
-    // '/api': {
-    //   target: 'http://192.168.1.21:38089',
-    //   changeOrigin: true,
-    //   pathRewrite: { '^/api': '' },
-    // },
     '/api': {
-      target: 'https://open.luojigou.vip',
+      target: 'https://open.test.luojigou.vip',
       changeOrigin: true,
       pathRewrite: { '^/api': '' },
     },

+ 2 - 1
src/components/upload/index.tsx

@@ -81,6 +81,7 @@ class PicturesWall extends Component<PicturesWallType> {
     return (
       <>
         <Upload
+          key={previewImage}
           action={`${baseUrl}/forum/file/uploadImage`}
           listType="picture-card"
           fileList={fileList}
@@ -96,7 +97,7 @@ class PicturesWall extends Component<PicturesWallType> {
           footer={null}
           onCancel={this.handleCancel}
         >
-          <img alt="example" style={{ width: '100%' }} src={previewImage} />
+          <img alt="example" style={{ width: '100%' }} key={previewImage} src={previewImage} />
         </Modal>
       </>
     );

+ 2 - 1
src/e2e/baseLayout.e2e.js

@@ -1,7 +1,8 @@
 const { uniq } = require('lodash');
 const RouterConfig = require('../../config/config').default.routes;
 
-const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
+// const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
+import { BASE_URL } from '@/utils/eventkey';
 
 function formatter(routes, parentPath = '') {
   const fixedParentPath = parentPath.replace(/\/{1,}/g, '/');

+ 3 - 4
src/layouts/BasicLayout.tsx

@@ -8,17 +8,16 @@ import type {
   BasicLayoutProps as ProLayoutProps,
   Settings,
 } from '@ant-design/pro-layout';
-import ProLayout, { DefaultFooter, SettingDrawer } from '@ant-design/pro-layout';
+import ProLayout, { SettingDrawer } from '@ant-design/pro-layout';
 import React, { useEffect, useMemo, useRef } from 'react';
 import type { Dispatch } from 'umi';
 import { Link, useIntl, connect, history } from 'umi';
-import { GithubOutlined } from '@ant-design/icons';
 import { Result, Button } from 'antd';
 import Authorized from '@/utils/Authorized';
 import RightContent from '@/components/GlobalHeader/RightContent';
 import type { ConnectState } from '@/models/connect';
 import { getMatchMenu } from '@umijs/route-utils';
-import logo from '../assets/logo.svg';
+import { BASE_URL } from '@/utils/eventkey';
 
 const noMatch = (
   <Result
@@ -98,7 +97,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
 
     if (!window.localStorage.getItem('token')) {
       if (process.env.NODE_ENV === 'development') {
-        window.location.href = 'http://localhost:8000/#/user/login';
+        window.location.href = `${BASE_URL}/#/user/login`;
       } else {
         window.location.href = 'https://luojigou.vip/tieba-admin/#/user/login';
       }

+ 1 - 0
src/pages/notice/data.d.ts

@@ -9,6 +9,7 @@ export type PostOrPutNoticeType = {
   content: string;
   label: string;
   type: Type;
+  imgUrl: string;
 };
 
 export interface noticeModalProps {

+ 41 - 15
src/pages/notice/modal.tsx

@@ -1,18 +1,18 @@
-import React, { useState, useEffect, useLayoutEffect } from 'react';
-import { Modal, Row, Col, Space, Form, Input, Select, message, Upload, Button } from 'antd';
+import React, { useState, useEffect } from 'react';
+import { Modal, Form, Input, Select, message, Upload } from 'antd';
 
-import { ScissorOutlined } from '@ant-design/icons';
+// import { ScissorOutlined } from '@ant-design/icons';
 
-import { getAgent } from '@/services/agent';
+// import { getAgent } from '@/services/agent';
 
 import { postOrPutNotice } from '@/services/notice';
 
-import { uploadFile } from '@/services/user';
+// import { uploadFile } from '@/services/user';
 
 // import ReactWEditor from 'wangeditor-for-react';
 
 // 引入编辑器组件
-import BraftEditor, { ControlType, ExtendControlType, ImageControlType } from 'braft-editor';
+import BraftEditor, { ExtendControlType, ImageControlType } from 'braft-editor';
 // 引入编辑器样式
 import 'braft-editor/dist/index.css';
 
@@ -24,10 +24,10 @@ import type { noticeModalProps } from './data';
 
 import type { Dispatch } from 'umi';
 
-import { useIntl } from 'react-intl';
-
 import { Role } from '@/models/user';
 
+import PicturesWall from '@/components/upload';
+
 const layout = {
   labelCol: { span: 5 },
   wrapperCol: { span: 16 },
@@ -230,6 +230,8 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
 
   const [label, setLabel] = useState('');
 
+  const [imgUrl, setImgUrl] = useState('');
+
   const [content, setContent] = useState('');
 
   // editContent 反填
@@ -251,11 +253,11 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
 
   // 新增或者编辑公告
   const PostOrPutNotice = async (record: any): Promise<void> => {
-    const { code, data } = await postOrPutNotice({ ...record });
-    if (code === 0 && data) {
+    const { code } = await postOrPutNotice({ ...record });
+    if (code === 0) {
       message.success(type === 1 ? '编辑成功' : '新增成功');
     } else {
-      message.success(type === 1 ? '编辑失败' : '新增失败');
+      message.error(type === 1 ? '编辑失败' : '新增失败');
     }
     closeModal();
     GetNotice();
@@ -268,6 +270,7 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
     form.setFieldsValue($par);
     setEditForm($par);
     setEditContent(curNoticeData.content);
+    setImgUrl(curNoticeData.imgUrl);
   };
 
   const onFinish = (values: any) => {
@@ -283,8 +286,9 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
       $par = {
         ...editForm,
         ...values,
+        imgUrl,
         userIds: ['ALL'],
-        roles: values.roles,
+        roles: Array.isArray(values.roles) ? values.roles : [values.roles],
         type: 'ANN',
         methodType: type,
         content,
@@ -292,19 +296,27 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
     } else {
       $par = {
         ...values,
+        imgUrl,
         userIds: ['ALL'],
-        roles: values.roles,
+        roles: Array.isArray(values.roles) ? values.roles : [values.roles],
         type: 'ANN',
         methodType: type,
         content,
       };
     }
 
-    console.log($par);
+    console.log($par, '参数');
 
     PostOrPutNotice($par);
   };
 
+  const changeImgUrl = (url: string) => {
+    setImgUrl(url);
+    form.setFieldsValue({
+      imgUrl: url,
+    });
+  };
+
   // 提交表单
   const onsubmit = () => form.submit();
 
@@ -323,12 +335,26 @@ const NoticeModal: React.FC<noticeModalProps & IProps> = ({
       onCancel={closeModal}
     >
       <Form {...layout} form={form} onFinish={onFinish}>
+        <Form.Item
+          name="imgUrl"
+          label="封面图"
+          rules={[{ required: true, message: '请上传封面图' }]}
+        >
+          <PicturesWall
+            key={imgUrl}
+            imgUrl={imgUrl}
+            setCoverFn={changeImgUrl}
+            maxCount={1}
+            desc="上传封面图"
+          />
+          <div>建议上传尺寸:398 * 530</div>
+        </Form.Item>
         <Form.Item
           name="roles"
           label="可看人员:"
           rules={[{ required: true, message: '请选择可看人员' }]}
         >
-          <Select style={{ width: '375px' }} mode="multiple">
+          <Select style={{ width: '375px' }}>
             {roleList.length &&
               roleList.map((item: Record<string, any>) => (
                 <Select.Option key={item.id} value={item.id}>

+ 7 - 0
src/utils/eventkey.ts

@@ -3,3 +3,10 @@
  */
 
 export const Token = 'token';
+
+/**
+ * @description BASE_URL
+ * @author zhubo
+ * @date 2022/8/24
+ */
+export const BASE_URL = window.location.host;

+ 3 - 3
src/utils/request.ts

@@ -4,7 +4,7 @@
  */
 import { extend } from 'umi-request';
 import { notification, message } from 'antd';
-import { Token } from '@/utils/eventkey';
+import { BASE_URL, Token } from '@/utils/eventkey';
 
 const codeMessage = {
   200: '服务器成功返回请求的数据。',
@@ -65,7 +65,7 @@ const headers = {
 // https://open.luojigou.vip
 
 export const baseUrl: string =
-  process.env.NODE_ENV === 'development' ? '/api' : 'https://open.luojigou.vip';
+  process.env.NODE_ENV === 'development' ? '/api' : 'https://open.api.luojigou.vip';
 
 request.interceptors.request.use(
   (url: string, options: any, mutUrl?: string) => {
@@ -84,7 +84,7 @@ request.interceptors.response.use(async (response, options) => {
   const r = await response.clone().json();
   if (r.code === 5001) {
     if (process.env.NODE_ENV === 'development') {
-      window.location.href = 'http://localhost:8000/#/user/login';
+      window.location.href = `${BASE_URL}/#/user/login`;
     } else {
       window.location.href = 'https://luojigou.vip/tieba-admin/#/user/login';
     }