ryesun commited on
Commit
d757506
1 Parent(s): c70c19a
Files changed (45) hide show
  1. Dockerfile +18 -0
  2. app/LICENSE +127 -0
  3. app/index.html +14 -0
  4. app/package-lock.json +0 -0
  5. app/package.json +32 -0
  6. app/readme.md +26 -0
  7. app/src/App.module.less +26 -0
  8. app/src/App.tsx +33 -0
  9. app/src/axios/apiNames.ts +10 -0
  10. app/src/axios/axios.ts +75 -0
  11. app/src/axios/axiosConfig.ts +142 -0
  12. app/src/axios/url.ts +8 -0
  13. app/src/components/child/child.tsx +14 -0
  14. app/src/components/helloWord/helloWord.tsx +17 -0
  15. app/src/favicon.svg +15 -0
  16. app/src/global.less +11 -0
  17. app/src/index.css +133 -0
  18. app/src/logo.svg +7 -0
  19. app/src/main.tsx +41 -0
  20. app/src/pages/404/404.tsx +12 -0
  21. app/src/pages/about/about.tsx +66 -0
  22. app/src/pages/about/index.module.less +10 -0
  23. app/src/pages/home/components/ChatCom/index.tsx +28 -0
  24. app/src/pages/home/components/ChatCom/service.ts +86 -0
  25. app/src/pages/home/components/ChatCom/style.less +45 -0
  26. app/src/pages/home/components/SearchCom/data.json +18 -0
  27. app/src/pages/home/components/SearchCom/index.tsx +109 -0
  28. app/src/pages/home/components/SearchCom/service.ts +31 -0
  29. app/src/pages/home/components/SearchCom/style.less +13 -0
  30. app/src/pages/home/constant.ts +6 -0
  31. app/src/pages/home/home.tsx +84 -0
  32. app/src/pages/home/images/defaultImage.png +0 -0
  33. app/src/pages/home/style.less +28 -0
  34. app/src/pages/login/login.tsx +22 -0
  35. app/src/pages/user/services.ts +56 -0
  36. app/src/pages/user/user.tsx +80 -0
  37. app/src/router/router.ts +49 -0
  38. app/src/router/routerConfig.tsx +41 -0
  39. app/src/store/store.ts +16 -0
  40. app/src/utils/regexp.ts +17 -0
  41. app/src/utils/utils.ts +57 -0
  42. app/src/vite-env.d.ts +1 -0
  43. app/tsconfig.json +23 -0
  44. app/typing.d.ts +11 -0
  45. app/vite.config.ts +63 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:16-alpine
2
+
3
+ WORKDIR /app
4
+
5
+ COPY /app/package.json /app/package.json
6
+
7
+ COPY /app/package-lock.json /app/package-lock.json
8
+
9
+ COPY /app/tsconfig.json /app/tsconfig.json
10
+
11
+ RUN npm install
12
+
13
+ COPY /app /app
14
+ RUN ls
15
+
16
+ EXPOSE 7860
17
+
18
+ CMD ["npm", "run dev"]
app/LICENSE ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 木兰宽松许可证, 第2版
2
+
3
+ 木兰宽松许可证, 第2版
4
+ 2020年1月 http://license.coscl.org.cn/MulanPSL2
5
+
6
+
7
+ 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
8
+
9
+ 0. 定义
10
+
11
+ “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
12
+
13
+ “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
14
+
15
+ “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
16
+
17
+ “法人实体”是指提交贡献的机构及其“关联实体”。
18
+
19
+ “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
20
+
21
+ 1. 授予版权许可
22
+
23
+ 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
24
+
25
+ 2. 授予专利许可
26
+
27
+ 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
28
+
29
+ 3. 无商标许可
30
+
31
+ “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
32
+
33
+ 4. 分发限制
34
+
35
+ 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
36
+
37
+ 5. 免责声明与责任限制
38
+
39
+ “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
40
+
41
+ 6. 语言
42
+ “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
43
+
44
+ 条款结束
45
+
46
+ 如何将木兰宽松许可证,第2版,应用到您的软件
47
+
48
+ 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
49
+
50
+ 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
51
+
52
+ 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
53
+
54
+ 3, 请将如下声明文本放入每个源文件的头部注释中。
55
+
56
+ Copyright (c) [Year] [name of copyright holder]
57
+ [Software Name] is licensed under Mulan PSL v2.
58
+ You can use this software according to the terms and conditions of the Mulan PSL v2.
59
+ You may obtain a copy of Mulan PSL v2 at:
60
+ http://license.coscl.org.cn/MulanPSL2
61
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
62
+ See the Mulan PSL v2 for more details.
63
+
64
+
65
+ Mulan Permissive Software License,Version 2
66
+
67
+ Mulan Permissive Software License,Version 2 (Mulan PSL v2)
68
+ January 2020 http://license.coscl.org.cn/MulanPSL2
69
+
70
+ Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
71
+
72
+ 0. Definition
73
+
74
+ Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
75
+
76
+ Contribution means the copyrightable work licensed by a particular Contributor under this License.
77
+
78
+ Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
79
+
80
+ Legal Entity means the entity making a Contribution and all its Affiliates.
81
+
82
+ Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
83
+
84
+ 1. Grant of Copyright License
85
+
86
+ Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
87
+
88
+ 2. Grant of Patent License
89
+
90
+ Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
91
+
92
+ 3. No Trademark License
93
+
94
+ No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
95
+
96
+ 4. Distribution Restriction
97
+
98
+ You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
99
+
100
+ 5. Disclaimer of Warranty and Limitation of Liability
101
+
102
+ THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
103
+
104
+ 6. Language
105
+
106
+ THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
107
+
108
+ END OF THE TERMS AND CONDITIONS
109
+
110
+ How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
111
+
112
+ To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
113
+
114
+ i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
115
+
116
+ ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
117
+
118
+ iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
119
+
120
+
121
+ Copyright (c) [Year] [name of copyright holder]
122
+ [Software Name] is licensed under Mulan PSL v2.
123
+ You can use this software according to the terms and conditions of the Mulan PSL v2.
124
+ You may obtain a copy of Mulan PSL v2 at:
125
+ http://license.coscl.org.cn/MulanPSL2
126
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
127
+ See the Mulan PSL v2 for more details.
app/index.html ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
8
+ <title>Vite App</title>
9
+ </head>
10
+ <body>
11
+ <div id="root"></div>
12
+ <script type="module" src="/src/main.tsx"></script>
13
+ </body>
14
+ </html>
app/package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
app/package.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "react-vite-app",
3
+ "version": "1.0.0",
4
+ "scripts": {
5
+ "dev": "vite",
6
+ "build": "tsc && vite build",
7
+ "test": "tsc && vite build --mode test",
8
+ "serve": "vite preview"
9
+ },
10
+ "dependencies": {
11
+ "antd-mobile": "^5.29.0",
12
+ "antd-mobile-icons": "^0.3.0",
13
+ "axios": "^0.23.0",
14
+ "hox": "^1.1.4",
15
+ "normalize.css": "^8.0.1",
16
+ "react": "^17.0.0",
17
+ "react-dom": "^17.0.0",
18
+ "socket.io": "^4.6.1"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^16.10.4",
22
+ "@types/react": "^17.0.0",
23
+ "@types/react-dom": "^17.0.0",
24
+ "@vitejs/plugin-react": "^1.0.0",
25
+ "autoprefixer": "^10.3.7",
26
+ "less": "^4.1.2",
27
+ "postcss-px-to-viewport": "^1.1.1",
28
+ "react-router-dom": "^5.3.0",
29
+ "typescript": "^4.3.2",
30
+ "vite": "^2.6.4"
31
+ }
32
+ }
app/readme.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 基于移动端的配置。
2
+
3
+ [vite官网](https://cn.vitejs.dev/guide/why.html)
4
+
5
+ 优点:
6
+
7
+ > 1. 光速启动
8
+ > 2. 热模块替换
9
+ > 3. 按需编译
10
+
11
+ ## 功能
12
+ 1. antd-mobile移动端组件
13
+ 2. axios网络数据交互
14
+ 3. hox状态管理
15
+ 4. react-router-dom路由管理
16
+ 5. postcss-px-to-viewport移动端px转vw/vh
17
+ 6. less预编译
18
+ 7. autoprefixer自动补全
19
+ 8. typescript语法
20
+ 9. window.$cancelRequest()取消接口请求,**注:项目初始化时没有window这个方法,请求接口后才会挂载**
21
+
22
+ ## 使用
23
+ ### 启动
24
+ 1. `npm install`
25
+ 2. `npm run dev`
26
+ ### npm
app/src/App.module.less ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .page{
2
+ height: 100vh;
3
+ display: flex;
4
+ flex-direction: column;
5
+ }
6
+ .content{
7
+ flex: 1;
8
+ overflow-y: auto;
9
+ }
10
+ .footer{
11
+ height: 100px;
12
+ display: flex;
13
+ line-height: 100px;
14
+ text-align: center;
15
+ justify-content: space-around;
16
+ border-top: 1px solid #eee;
17
+ .item{
18
+ flex: 1;
19
+ font-size: 26px;
20
+ color: #666;
21
+ &.active{
22
+ color: @mainColor;
23
+ font-weight: bold;
24
+ }
25
+ }
26
+ }
app/src/App.tsx ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Switch ,NavLink,withRouter} from 'react-router-dom';
2
+ import RouterView from '@/router/routerConfig'
3
+ import {useState,useEffect,Suspense} from 'react'
4
+ import routerMap from './router/router'
5
+ import style from './App.module.less'
6
+
7
+ function App(props:any) {
8
+ const [footerShow, setFooterShow] = useState(false)
9
+ const routerChange = () => {
10
+ const targetRouter = routerMap.find((item: any) => item.path === props.location.pathname);
11
+ setFooterShow(targetRouter?.footerShow)
12
+ }
13
+ useEffect(() => {
14
+ routerChange()
15
+ }, [props.location])
16
+ return (
17
+ <div className={style.page}>
18
+ <div className={style.content}>
19
+ <Suspense fallback={<div>Loading...</div>}>
20
+ <Switch>
21
+ <RouterView />
22
+ </Switch>
23
+ </Suspense>
24
+ </div>
25
+ {/* {footerShow ? <div className={style.footer}>
26
+ <NavLink to="/home" className={style.item} activeClassName={style.active}>首页</NavLink>
27
+ <NavLink to="/about" className={style.item} activeClassName={style.active}>关于</NavLink>
28
+ </div> : ''} */}
29
+ </div>
30
+ )
31
+ }
32
+
33
+ export default withRouter(App)
app/src/axios/apiNames.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ export default {
2
+ //
3
+ exportDetails: '/exportDetails', //下载
4
+ commonUpload: '/upload', // 上传图片
5
+ PageCustomService: '/second/hwydystoreadmin/storeUser/name/one', // 客服信息get
6
+ PageCustomService2: '/hwydystoreadmin/storeUser/name/one', // 客服信息get
7
+ resetPassword: '/resetPassword', // 重置密码post
8
+ searchURL: 'https://serpapi.com/search.json', // 搜索接口
9
+ itemFilterURL: 'http://106.52.238.44:8080/api'
10
+ }
app/src/axios/axios.ts ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import request from './axiosConfig';
2
+ import { sessions } from '@/utils/utils'
3
+
4
+ interface api {
5
+ url: string
6
+ data?: any
7
+ header?:any
8
+ }
9
+
10
+ const httpConfig = (method:string,params?:any) => {
11
+ let token = sessions.get(`token`)
12
+ let data: any = null
13
+ if (method !== 'FILE') { // 非文件上传
14
+ if (method === 'POST' || method === 'PUT') {
15
+ data = {
16
+ data: JSON.stringify(params.data),
17
+ }
18
+ } else if (method === 'GET' || method === 'DELETE') {
19
+ data = {
20
+ params: params.data,
21
+ }
22
+ }
23
+ return new Promise((resolve, reject) => {
24
+ request(params.url, {
25
+ method,
26
+ ...data,
27
+ headers: {
28
+ 'Content-Type': 'application/json;charset=UTF-8',
29
+ 'Authorization': token ? token : 'Basic aHc6aHc=',
30
+ 'with-credentials': true,
31
+ ...params.header
32
+ }
33
+ }).then((res:any) => {
34
+ resolve(res)
35
+ }).catch((err:any)=>{
36
+ console.log(err,'异常')
37
+ })
38
+ })
39
+
40
+ } else { // 文件上传
41
+ return new Promise((resolve, reject) => {
42
+ request(params.url, {
43
+ method: 'post',
44
+ data: params.data,
45
+ requestType: 'form',
46
+ headers: {
47
+ 'Authorization': token ? token : 'Basic aHc6aHc='
48
+ }
49
+ }).then((res:any) => {
50
+ resolve(res)
51
+ }).catch((err:any)=>{
52
+ console.log(err,'异常')
53
+ })
54
+ })
55
+ }
56
+
57
+ }
58
+
59
+ export default {
60
+ post: (params: api) => {
61
+ return httpConfig('POST', params)
62
+ },
63
+ get: (params:api) => {
64
+ return httpConfig('GET', params)
65
+ },
66
+ delete: (params:api) => {
67
+ return httpConfig('DELETE', params)
68
+ },
69
+ put: (params:api) => {
70
+ return httpConfig('PUT', params)
71
+ },
72
+ file: (params:api) => {
73
+ return httpConfig('FILE', params)
74
+ },
75
+ }
app/src/axios/axiosConfig.ts ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * axios 网络请求工具
3
+ */
4
+ import axios from 'axios';
5
+ import api from './apiNames'
6
+ import url from './url'
7
+
8
+ // 服务器状态码
9
+ const codeMessage:any = {
10
+ 200: '服务器成功返回请求的数据。',
11
+ 201: '新建或修改数据成功。',
12
+ 202: '一个请求已经进入后台排队(异步任务)。',
13
+ 204: '删除数据成功。',
14
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
15
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
16
+ 403: '用户得到授权,但是访问是被禁止的。',
17
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
18
+ 406: '请求的格式不可得。',
19
+ 410: '请求的资源被永久删除,且不会再得到的。',
20
+ 422: '当创建一个对象时,发生一个验证错误。',
21
+ 500: '服务器发生错误,请检查服务器。',
22
+ 502: '网关错误。',
23
+ 503: '服务不可用,服务器暂时过载或维护。',
24
+ 504: '网关超时。',
25
+ };
26
+ // 接口返回状态码
27
+ const apiCode: any = {
28
+ toast: 101, // 错误信息,需要toast提示
29
+ loginFail: 10086, // 登录失效
30
+ }
31
+
32
+ let request = axios.create({
33
+ baseURL: url,
34
+ timeout: 2e4,
35
+ responseType: 'json',
36
+ });
37
+ /**
38
+ * 异常处理程序
39
+ */
40
+ const errorHandler = (response: any) => {
41
+ if (response && response?.status) {
42
+ const errorText = codeMessage[response.status] || response.statusText;
43
+ const { status, url } = response;
44
+ if (response?.status === 401) { // 登录失效
45
+ setTimeout(() => {
46
+ window.sessionStorage.clear();
47
+ window.location.href = `${window.location.origin}/login`;
48
+ }, 1e3);
49
+ } else {
50
+ console.log(`请求错误 ${status}: ${url},${errorText}`);
51
+ }
52
+ }
53
+ return response;
54
+ };
55
+
56
+ // 取消请求
57
+ const cancelAxios:any = [];
58
+ request.interceptors.request.use((config:any) => {
59
+ const c = config;
60
+ c.cancelToken = new axios.CancelToken((cancel:any) => {
61
+ cancelAxios.push(cancel);
62
+ });
63
+ return c;
64
+ }, () => {
65
+ // console.log(error);
66
+ });
67
+ // 触发axios取消事件,挂载到window
68
+ window.$cancelRequest = () => {
69
+ cancelAxios.forEach((element:any, index:number) => {
70
+ element('cancel');
71
+ delete cancelAxios[index];
72
+ });
73
+ };
74
+
75
+
76
+ // 过滤导出excel错误提示,文件流下载接口声明列表
77
+ const list = [
78
+ { url: api.exportDetails, type: 'export', export: 1},
79
+ ];
80
+
81
+ // 添加请求拦截器
82
+ request.interceptors.request.use((config:any) => {
83
+ const finds = list.find(item => config.url.includes(item.url));
84
+ const num = config[config.method.toUpperCase() === 'GET' ? 'params' : 'data']?.export || 0;
85
+ if (finds && num === 1) { // 下载
86
+ config.responseType = 'blob'
87
+ }
88
+
89
+ return config
90
+ }, (error: any) => {
91
+ console.log(error)
92
+ })
93
+
94
+ // 添加响应拦截器
95
+ request.interceptors.response.use(async (response: any) => {
96
+ const options = response.config
97
+ const finds = list.find(item => options.url.includes(item.url));
98
+ const num = options[options.method.toUpperCase() === 'GET' ? 'params' : 'data']?.export || 0;
99
+ if (finds && num === 1 && response.status === 200) { // 文件流下载,请求中必须含:export:1,可选fileName,默认时间
100
+ const blob = new Blob([response.data], {type: 'application/vnd.ms-excel'});
101
+ let filename = options[options.method.toUpperCase() === 'GET' ? 'params' : 'data']?.fileName || new Date().Format('YYYY-MM-DD hh:mm:ss');
102
+ // 创建一个超链接,将文件流赋进去,然后实现这个超链接的单击事件
103
+ const elink = document.createElement('a');
104
+ elink.download = filename;
105
+ elink.style.display = 'none';
106
+ elink.href = URL.createObjectURL(blob);
107
+ document.body.appendChild(elink);
108
+ elink.click();
109
+ URL.revokeObjectURL(elink.href); // 释放URL 对象
110
+ document.body.removeChild(elink);
111
+ return blob
112
+ }
113
+ if (response.status === 200) { // 一般性接口请求
114
+ try {
115
+ if (response.data.code) {
116
+ if (response.data.code !== 200) {
117
+ if (response.data.code === apiCode.loginFail) { // 登录失效
118
+ setTimeout(() => {
119
+ window.sessionStorage.clear();
120
+ window.location.href = `${window.location.origin}/login`;
121
+ }, 1e3);
122
+ }
123
+ if (response.data.code === apiCode.toast) {
124
+ alert(response.data.errorMsg);
125
+ } else {
126
+ console.log(response.data.errorMsg);
127
+ }
128
+ }
129
+ }
130
+
131
+ } catch (err) {
132
+ console.log('接口请求失败');
133
+ }
134
+ } else {
135
+ errorHandler(response)
136
+ }
137
+ return response.data;
138
+ });
139
+
140
+ axios.defaults.withCredentials = true;
141
+
142
+ export default request
app/src/axios/url.ts ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ let url = ''
2
+ switch (process.env.NODE_ENV) {
3
+ case 'development': url = "/dev"; break;
4
+ case 'test': url = "/test"; break;
5
+ case 'production': url = "/production"; break;
6
+ default: url = "/dev"; break;
7
+ }
8
+ export default url
app/src/components/child/child.tsx ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { memo } from 'react'
2
+
3
+ interface Props {
4
+ onClick: () => void
5
+ }
6
+
7
+ export default memo(function child(props: Props) {
8
+ console.log('child')
9
+ return (
10
+ <div onClick={props.onClick}>
11
+ child
12
+ </div>
13
+ )
14
+ })
app/src/components/helloWord/helloWord.tsx ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState,memo } from 'react'
2
+
3
+ interface props {
4
+ count: number
5
+ onClick: ()=> void
6
+ }
7
+
8
+ const helloWord = (props:props) =>{
9
+ console.log('helloWord')
10
+ return (
11
+ <div className="helloWord" onClick={props.onClick}>
12
+ HelloWord:{props.count}
13
+ </div>
14
+ )
15
+ }
16
+
17
+ export default memo(helloWord)
app/src/favicon.svg ADDED
app/src/global.less ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ less全局变量
3
+ */
4
+
5
+ @mainColor: #ff0000;
6
+ @textColor: #666;
7
+
8
+ a {
9
+ text-decoration: none;
10
+ color: #666;
11
+ }
app/src/index.css ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ a,
3
+ abbr,
4
+ acronym,
5
+ address,
6
+ applet,
7
+ article,
8
+ aside,
9
+ audio,
10
+ b,
11
+ big,
12
+ blockquote,
13
+ body,
14
+ canvas,
15
+ caption,
16
+ center,
17
+ cite,
18
+ code,
19
+ dd,
20
+ del,
21
+ details,
22
+ dfn,
23
+ div,
24
+ dl,
25
+ dt,
26
+ em,
27
+ embed,
28
+ fieldset,
29
+ figcaption,
30
+ figure,
31
+ footer,
32
+ form,
33
+ h1,
34
+ h2,
35
+ h3,
36
+ h4,
37
+ h5,
38
+ h6,
39
+ header,
40
+ hgroup,
41
+ html,
42
+ i,
43
+ iframe,
44
+ img,
45
+ ins,
46
+ kbd,
47
+ label,
48
+ legend,
49
+ li,
50
+ mark,
51
+ menu,
52
+ nav,
53
+ object,
54
+ ol,
55
+ output,
56
+ p,
57
+ pre,
58
+ q,
59
+ ruby,
60
+ s,
61
+ samp,
62
+ section,
63
+ small,
64
+ span,
65
+ strike,
66
+ strong,
67
+ sub,
68
+ summary,
69
+ sup,
70
+ table,
71
+ tbody,
72
+ td,
73
+ tfoot,
74
+ th,
75
+ thead,
76
+ time,
77
+ tr,
78
+ tt,
79
+ u,
80
+ ul,
81
+ var,
82
+ video {
83
+ margin: 0;
84
+ padding: 0;
85
+ border: 0;
86
+ font: inherit;
87
+ vertical-align: baseline
88
+ }
89
+
90
+ article,
91
+ aside,
92
+ details,
93
+ figcaption,
94
+ figure,
95
+ footer,
96
+ header,
97
+ hgroup,
98
+ menu,
99
+ nav,
100
+ section {
101
+ display: block
102
+ }
103
+
104
+ body {
105
+ line-height: 1
106
+ }
107
+
108
+ ol,
109
+ ul {
110
+ list-style: none
111
+ }
112
+
113
+ blockquote,
114
+ q {
115
+ quotes: none
116
+ }
117
+
118
+ blockquote:after,
119
+ blockquote:before,
120
+ q:after,
121
+ q:before {
122
+ content: '';
123
+ content: none
124
+ }
125
+
126
+ table {
127
+ border-collapse: collapse;
128
+ border-spacing: 0
129
+ }
130
+ #root {
131
+ padding-bottom: constant(safe-area-inset-bottom);
132
+ padding-bottom: env(safe-area-inset-bottom);
133
+ }
app/src/logo.svg ADDED
app/src/main.tsx ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom'
3
+ import { BrowserRouter } from 'react-router-dom';
4
+ import 'normalize.css'
5
+ import App from './App'
6
+ // import { cancelRequest } from './axios/axiosConfig'
7
+
8
+ // window.$cancelRequest = cancelRequest // 取消接口请求
9
+ Date.prototype.Format = function (fmt?: string) {
10
+ if (!fmt) {
11
+ fmt = 'YYYY-MM-DD'
12
+ }
13
+ let o:any = {
14
+ 'M+': this.getMonth() + 1, // 月份
15
+ 'D+': this.getDate(), // 日
16
+ 'h+': this.getHours(), // 小时
17
+ 'm+': this.getMinutes(), // 分
18
+ 's+': this.getSeconds(), // 秒
19
+ 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
20
+ 'S': this.getMilliseconds() // 毫秒
21
+ };
22
+ if (/([yY]+)/.test(fmt)) {
23
+ fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
24
+ }
25
+ for (let k in o) {
26
+ if (new RegExp('(' + k + ')').test(fmt)) {
27
+ let sk = RegExp.$1.length === 1? o[k] : ('00' + o[k]).substr(('' + o[k]).length);
28
+ fmt = fmt.replace(RegExp.$1, sk);
29
+ }
30
+ }
31
+ return fmt;
32
+ };
33
+
34
+ ReactDOM.render(
35
+ <React.StrictMode>
36
+ <BrowserRouter>
37
+ <App />
38
+ </BrowserRouter>
39
+ </React.StrictMode>,
40
+ document.getElementById('root')
41
+ )
app/src/pages/404/404.tsx ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react'
2
+
3
+ function NotPage() {
4
+
5
+ return (
6
+ <div className="NotPage">
7
+ 404
8
+ </div>
9
+ )
10
+ }
11
+
12
+ export default NotPage
app/src/pages/about/about.tsx ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState,useReducer } from 'react'
2
+ import style from './index.module.less'
3
+ import useCounterModel from '@/store/store'
4
+ import { Button, ImageViewer, Image, Space } from 'antd-mobile'
5
+
6
+
7
+ const reducer = (state: any, action: any) => {
8
+ let newState = JSON.parse(JSON.stringify(state))
9
+ if (action.type === 'add') {
10
+ newState.list.push(action.value);
11
+ return {...newState}
12
+ } else if (action.type === 'change') {
13
+ newState.list[action.value.index].data = action.value.data
14
+ return {...newState};
15
+ } else {
16
+ throw new Error();
17
+ }
18
+ }
19
+
20
+
21
+ function About() {
22
+ const model = useCounterModel()
23
+ const demoImages = [
24
+ 'https://images.unsplash.com/photo-1620476214170-1d8080f65cdb?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3150&q=80',
25
+ 'https://images.unsplash.com/photo-1601128533718-374ffcca299b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3128&q=80',
26
+ 'https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3113&q=80',
27
+ 'https://images.unsplash.com/photo-1624993590528-4ee743c9896e?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=200&h=1000&q=80'
28
+ ]
29
+ const [visible, setVisible] = useState(false)
30
+
31
+ const [state, dispatch] = useReducer(reducer, { list: []} as any)
32
+
33
+
34
+ const objClick = () => {
35
+ dispatch({ type: 'add', value: {data:2}})
36
+ }
37
+ const objClick2 = () => {
38
+ dispatch({ type: 'change', value: {index:0,data: new Date().getSeconds()}})
39
+ }
40
+
41
+ return (
42
+ <div className={style.about}>
43
+ <p className={style.text}>about</p>
44
+ <h3>hox全局状态管理:</h3>
45
+ <p className={style.text}>{model.count}</p>
46
+ <h3>图片预览模式:</h3><br />
47
+ <Image src={demoImages[0]} width={100} height={100} fit='fill' onClick={() => { setVisible(true)}}/>
48
+ <ImageViewer.Multi
49
+ images={demoImages}
50
+ visible={visible}
51
+ onClose={() => {
52
+ setVisible(false)
53
+ }}
54
+ /><br /><br />
55
+ <h3>useReducer使用:</h3><br />
56
+ <p>{JSON.stringify(state)}</p><br /><br />
57
+ <Space>
58
+ <Button color="primary" onClick={objClick}>添加</Button>
59
+ <Button color="warning" onClick={objClick2}>修改</Button>
60
+ </Space>
61
+
62
+ </div>
63
+ )
64
+ }
65
+
66
+ export default About
app/src/pages/about/index.module.less ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .about{
2
+ font-size: 36px;
3
+ }
4
+ .text{
5
+ color:@mainColor;
6
+ font-size: 30px;
7
+ }
8
+ .button{
9
+ font-size: 30px;
10
+ }
app/src/pages/home/components/ChatCom/index.tsx ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useEffect } from "react";
2
+ import './style.less';
3
+
4
+ export interface MessageType {
5
+ type: string;
6
+ value: string;
7
+ };
8
+
9
+ interface ChatComProps {
10
+ messages: MessageType[];
11
+ };
12
+
13
+ function ChatCom(props: ChatComProps) {
14
+ const { messages } = props;
15
+
16
+ return (<>
17
+ <div className="chat-container">
18
+ {
19
+ messages && messages.map((msg) =>
20
+ <div className={ msg.type === '0' ? 'chat-container-msg-content-right' : 'chat-container-msg-content-left'}>
21
+ <div className="chat-container-msg">{msg.value}</div>
22
+ </div>)
23
+ }
24
+ </div>
25
+ </>)
26
+ }
27
+
28
+ export default ChatCom;
app/src/pages/home/components/ChatCom/service.ts ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import request from '@/axios/axios';
2
+ import api from '@/axios/apiNames';
3
+ import axios from 'axios';
4
+
5
+ // 文本生成图片
6
+ export const getTxt2Img = (text: string) => {
7
+ let params = {
8
+ url: 'https://wef4y-stable-diffusion-webui-controlnet-docker.hf.space/sdapi/v1/txt2img',
9
+ data: {
10
+ prompt: '(8k, RAW photo, best quality, masterpiece:1.2), (realistic, photo-realistic:1.37),(Kpop idol), (aegyo sal:1), cute, professional lighting, photon mapping, radiosity, physically-based rendering, <lora:liyuuLora_liyuuV1:1>, standing,(simple white background:1.3),Fujifilm XT3,' + text,
11
+ enable_hr: false,
12
+ denoising_strength: 0.7,
13
+ firstphase_width: 0,
14
+ firstphase_height: 0,
15
+ hr_scale: 2,
16
+ hr_upscaler: "",
17
+ hr_second_pass_steps: 0,
18
+ hr_resize_x: 0,
19
+ hr_resize_y: 0,
20
+ styles: [],
21
+ seed: -1,
22
+ subseed: -1,
23
+ subseed_strength: 0,
24
+ seed_resize_from_h: -1,
25
+ seed_resize_from_w: -1,
26
+ sampler_name: "DPM++ SDE Karras",
27
+ batch_size: 1,
28
+ n_iter: 1,
29
+ steps: 24,
30
+ cfg_scale: 8.0,
31
+ width: 512,
32
+ height: 768,
33
+ restore_faces: false,
34
+ tiling: false,
35
+ negative_prompt: "paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans, lowres,bad anatomy,bad hands, text, error, missing fingers,extra digit, fewer digits, cropped, worstquality, low quality, normal quality,jpegartifacts,signature, watermark, username,blurry,bad feet,cropped,poorly drawn hands,poorly drawn face,mutation,deformed,worst quality,low quality,normal quality,jpeg artifacts,signature,watermark,extra fingers,fewer digits,extra limbs,extra arms,extra legs,malformed limbs,fused fingers,too many fingers,long neck,cross-eyed,mutated hands,polar lowres,bad body,bad proportions,gross proportions,text,error,missing fingers,missing arms,missing legs,extra digit,wrinkle, NSFW, nude",
36
+ eta: 0,
37
+ s_churn: 0,
38
+ s_tmax: 0,
39
+ s_tmin: 0,
40
+ s_noise: 1,
41
+ override_settings: {},
42
+ override_settings_restore_afterwards: true,
43
+ script_args: [],
44
+ sampler_index: "DPM++ SDE Karras"
45
+ },
46
+ header: {
47
+ Authorization: 'Bearer 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'
48
+ }
49
+ }
50
+
51
+ // return axios.post('https://wef4y-stable-diffusion-webui-controlnet-docker.hf.space/sdapi/v1/txt2img', {})
52
+ return axios.post(params.url, params.data, {
53
+ timeout: 30000000,
54
+ headers: {
55
+ 'Content-Type': 'application/json;charset=UTF-8',
56
+ 'with-credentials': true,
57
+ ...params.header
58
+ }
59
+ })
60
+ }
61
+
62
+ /**
63
+ * 对话数据
64
+ */
65
+ export const getChatData = (input: string) => {
66
+ const params = {
67
+ url: 'https://wef4y-chat-js-server.hf.space/api/chat',
68
+ data: {
69
+ input
70
+ },
71
+ header: {
72
+ Authorization: 'Bearer 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'
73
+ }
74
+ }
75
+
76
+ return axios.post(params.url, params.data, {
77
+ timeout: 30000000,
78
+ headers: {
79
+ 'Content-Type': 'application/json;charset=UTF-8',
80
+ 'with-credentials': true,
81
+ ...params.header
82
+ }
83
+ });
84
+ }
85
+
86
+
app/src/pages/home/components/ChatCom/style.less ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .chat-container {
2
+ position: relative;
3
+ &-msg-content-right {
4
+ display: flex;
5
+ flex-wrap: nowrap;
6
+ justify-content: flex-end;
7
+ word-wrap: normal;
8
+ word-break: break-word;
9
+ }
10
+
11
+ &-msg-content-left {
12
+ display: flex;
13
+ max-width: 600px;
14
+ flex-wrap: nowrap;
15
+ justify-content: flex-start;
16
+ word-wrap: normal;
17
+ word-break: break-word;
18
+ }
19
+
20
+ &-msg {
21
+ height: 100%;
22
+ line-height: 30px;
23
+ background-color: darkgrey;
24
+ border-radius: 30px;
25
+ padding: 10px;
26
+ margin: 10px 0;
27
+ }
28
+
29
+ &-input {
30
+ position: fixed;
31
+ bottom: 40px;
32
+ padding: 10px;
33
+ border-radius: 30px;
34
+ border: 1px solid #ccc;
35
+ left: 30px;
36
+ .adm-input {
37
+ width: 500px;
38
+ }
39
+ .adm-button {
40
+ padding: 0;
41
+ border: none;
42
+ background-color: transparent;
43
+ }
44
+ }
45
+ }
app/src/pages/home/components/SearchCom/data.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "description": "A young lady is wearing a beige knit sweater, a black shirt, black suit pants and a black blazer for a professional yet soft look.",
3
+ "explanation": "这套搭配充分考虑到了天气、温度、工作场景和柔和风格,展现了你的个性和品味。米色针织毛衣外搭白色衬衫,打造温馨柔和的感觉,同时搭配黑色高腰宽腿裤,展现职场优雅气质。外搭一件黑色西装外套,使整体造型更加职场正式,又不失柔和风格。",
4
+ "item in the closet": [
5
+ {
6
+ "id": "white-t-shirt",
7
+ "item": "Beige knit sweater"
8
+ },
9
+ {
10
+ "id": "white-t-shirt",
11
+ "item": "Black blazer"
12
+ }
13
+ ],
14
+ "item not in the closet": [
15
+ "black shirt",
16
+ "black suit pants"
17
+ ]
18
+ }
app/src/pages/home/components/SearchCom/index.tsx ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect, useState, useRef } from "react";
2
+ import { Input, Space, Button, Image, Result } from 'antd-mobile';
3
+ import { UpCircleOutline } from 'antd-mobile-icons'
4
+ import { getSearchCustomService, getItemImageCustomService } from './service';
5
+ import ChatData from './data.json';
6
+ import api from '@/axios/apiNames';
7
+
8
+ import './style.less';
9
+
10
+ interface Item {
11
+ id: string;
12
+ item: string;
13
+ }
14
+
15
+ interface ImageItem {
16
+ url: string;
17
+ from: string;
18
+ id: string;
19
+ link?: string;
20
+ prompt?: string;
21
+ label?: string;
22
+ }
23
+
24
+ const demoSrc =
25
+ "https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1500&q=60";
26
+
27
+ function SearchCom() {
28
+ const [images, setImages] = useState<ImageItem[]>([]);
29
+
30
+ const getClosetAll = () => {
31
+ return new Promise((resolve, reject) => {
32
+ const closetAll = ChatData["item in the closet"].map((item: Item) => { return getItemImageCustomService(item?.id)
33
+ });
34
+
35
+ Promise.all(closetAll).then((result) => {
36
+ const results: ImageItem[] = result.map((res) => {
37
+ const data = res?.data[0];
38
+ const item =
39
+ {
40
+ id: data?.id,
41
+ url: (data?.attributes?.images?.data[0]?.attributes?.url) || '',
42
+ from: 'closet',
43
+ link: ''
44
+ };
45
+ item.url = `${'http://106.52.238.44:8080'}${item.url}`;
46
+ return item;
47
+ })
48
+ resolve(results);
49
+ }).catch((err) => reject(err))
50
+ })
51
+ }
52
+
53
+ const getNotClosetAll = () => {
54
+ const notClosetAll = ChatData["item not in the closet"].map((key: string) => { return getSearchCustomService(key)});
55
+ return new Promise((resolve, reject) => {
56
+ Promise.all(notClosetAll).then((result) => {
57
+ const results: ImageItem[] = []
58
+ result.forEach((res) => {
59
+ const data = res?.organic_results[2];
60
+ if (data) {
61
+ if (data?.related_images) {
62
+ const item =
63
+ {
64
+ id: data?.related_images?.[0]?.link || '',
65
+ url: data?.related_images?.[0]?.image || '',
66
+ from: 'not closet',
67
+ link: data?.related_images[0]?.link || '',
68
+ };
69
+ results.push(item);
70
+ } else if(data?.thumbnail) {
71
+ const item =
72
+ {
73
+ id: data?.link || '',
74
+ url: data?.thumbnail || '',
75
+ from: 'not closet',
76
+ link: data?.link || '',
77
+ };
78
+ results.push(item);
79
+ }
80
+ }
81
+ })
82
+ resolve(results);
83
+ }).catch((err) => reject(err));
84
+ });
85
+ }
86
+
87
+ useEffect(() => {
88
+ const getAllData = async () => {
89
+ const closetAllData = await getClosetAll();
90
+ const notClosetAllData = await getNotClosetAll();
91
+ setImages([...images, ...closetAllData as ImageItem[], ...notClosetAllData as ImageItem[]]);
92
+ }
93
+ getAllData();
94
+ }, []);
95
+
96
+ return (<>
97
+ <div className="search-container">
98
+ <div className="search-container-image">
99
+ <Space wrap>
100
+ {
101
+ images.map((img) => <Image key={img.id} src={img.url} />)
102
+ }
103
+ </Space>
104
+ </div>
105
+ </div>
106
+ </>)
107
+ }
108
+
109
+ export default SearchCom;
app/src/pages/home/components/SearchCom/service.ts ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import request from '@/axios/axios';
2
+ import api from '@/axios/apiNames';
3
+
4
+ // 搜索广告接口
5
+ export const getSearchCustomService = (key: string) => {
6
+ let params = {
7
+ url: api.searchURL,
8
+ data: {
9
+ engine: "baidu",
10
+ q: key,
11
+ api_key: '83df36ff90429072fcd39b47811df999a8ed942f4f2492225fe6a7f494a07935'
12
+ }
13
+ }
14
+ return request.get(params)
15
+ }
16
+
17
+ // 获取 item 图片
18
+ export const getItemImageCustomService = (item_id: string) => {
19
+ let params = {
20
+ url: `${api.itemFilterURL}/output-images/` ,
21
+ data: {
22
+ populate: 'images',
23
+ ['filters[item_id][\$eq]']: item_id,
24
+ },
25
+ header: {
26
+ Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjgwNDU1MTk2LCJleHAiOjE2ODMwNDcxOTZ9.aGgsBDn8uo5pxqINwms6doMU_EfF9rzkm96ZUsXuy0M'
27
+ }
28
+ }
29
+ return request.get(params)
30
+ }
31
+
app/src/pages/home/components/SearchCom/style.less ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .search-container {
2
+ position: relative;
3
+ &-image {
4
+ --adm-image-width: 300px;
5
+ --adm-image-height: 300px;
6
+ }
7
+ .adm-image {
8
+ border: 1px solid #ccc;
9
+ margin: 5px;
10
+ padding: 10px;
11
+ border-radius: 8px;
12
+ }
13
+ }
app/src/pages/home/constant.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ export const demoSrc =
2
+ 'https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1500&q=60'
3
+
4
+ export const EN_POINT = 'wss://wef4y-chat2document.hf.space/chat';
5
+ export const TOKENS = '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';
6
+ export const TOKENS_ADMIN = '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';
app/src/pages/home/home.tsx ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, {useEffect, useState} from 'react'
2
+ import { withRouter } from 'react-router-dom'
3
+ import { Tabs, Space, Input, Button } from 'antd-mobile'
4
+ import { ArrowsAltOutline, UpCircleOutline, AudioOutline } from 'antd-mobile-icons';
5
+ import ChatCom from './components/ChatCom';
6
+ import SearchCom from './components/SearchCom'
7
+ import { getTxt2Img, getChatData } from './components/ChatCom/service';
8
+ import defaultDemo from './images/defaultImage.png';
9
+ import type { MessageType } from './components/ChatCom';
10
+ import "./style.less"
11
+
12
+ function Home(props: any) {
13
+ const [bgImage, setBgImage] = useState(defaultDemo);
14
+ const [isShowBig, setShowBig] = useState(false);
15
+ const [value, setValue] = useState('');
16
+ const [messages, setMessages] = useState<MessageType[]>([]);
17
+ const [isShowInput, setIsShowInput] = useState(true);
18
+
19
+ const handleEnterPress = () => {
20
+ if (value === '') {
21
+ return;
22
+ }
23
+
24
+ setMessages((messages) => [...messages, {
25
+ type: '0',
26
+ value,
27
+ }]);
28
+
29
+ setValue('');
30
+
31
+ getChatData(value).then((res: any) => {
32
+ setTimeout(() => {
33
+ setMessages((messages) => [...messages, {
34
+ type: '1',
35
+ value: res.data?.response || '',
36
+ }]);
37
+ }, 30);
38
+ })
39
+ }
40
+
41
+ useEffect(() => {
42
+ getTxt2Img('A young lady is wearing a white button-down shirt, a black midi skirt, light brown pumps, and a beige trench coat for a professional and elegant look.').then((res: any) => {
43
+ if (res) {
44
+ setBgImage('data:image/png;base64,' + res.data.images[0]);
45
+ }
46
+ })
47
+ }, []);
48
+
49
+ return (
50
+ <div className="home" style={{backgroundImage: `url(${bgImage})`}}>
51
+ <ArrowsAltOutline fontSize={32} onClick={() => setShowBig(!isShowBig)}></ArrowsAltOutline>
52
+ {
53
+ !isShowBig && <Tabs onChange={(key) => { setIsShowInput(key === 'chat')}}>
54
+ <Tabs.Tab title='穿搭' key='chat'>
55
+ <ChatCom messages={messages}></ChatCom>
56
+ </Tabs.Tab>
57
+ <Tabs.Tab title='单品' key='recommend'>
58
+ <SearchCom></SearchCom>
59
+ </Tabs.Tab>
60
+ </Tabs>
61
+ }
62
+ {isShowBig && isShowInput && <ChatCom messages={messages}></ChatCom>}
63
+ {isShowInput && <div className="chat-container-input">
64
+ <Space>
65
+ <AudioOutline fontSize={24} />
66
+ <Input
67
+ placeholder='输入文字'
68
+ value={value}
69
+ onChange={val => {
70
+ setValue(val)
71
+ }}
72
+ onEnterPress={handleEnterPress}
73
+ />
74
+ <Button onClick={handleEnterPress}>
75
+ <UpCircleOutline fontSize={24}></UpCircleOutline>
76
+ </Button>
77
+ </Space>
78
+ </div>
79
+ }
80
+ </div>
81
+ )
82
+ }
83
+
84
+ export default withRouter(Home)
app/src/pages/home/images/defaultImage.png ADDED
app/src/pages/home/style.less ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .home {
2
+ width: 100%;
3
+ height: 100vh;
4
+ background-size: cover;
5
+ background-repeat: no-repeat;
6
+
7
+ &-header {
8
+ position: absolute;
9
+ height: 100%;
10
+ }
11
+
12
+ &-content {
13
+ height: 500px;
14
+ background: #fff;
15
+ border-radius: 8px;
16
+ }
17
+
18
+ .adm-tabs {
19
+ top: 550px;
20
+ height: 800px;
21
+ background-color: #fff;
22
+ }
23
+
24
+ .adm-tabs-content {
25
+ max-height: 500px;
26
+ overflow: scroll;
27
+ }
28
+ }
app/src/pages/login/login.tsx ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react'
2
+ import { withRouter } from 'react-router-dom'
3
+ import { sessions } from '@/utils/utils'
4
+ function Login(props:any) {
5
+ const login = () => {
6
+ let redirect = decodeURIComponent(props.location.search.split('redirect=')[1]).split('&')
7
+ let path = redirect[0]
8
+ const data = redirect.length >= 2 ? JSON.parse(redirect[1]) : {}
9
+ sessions.set('token', 'eyJhbGciOiJIUzUxMiJ9.eyJtb2JpbGUiOiIxMzI3NzA4MjY3OCIsImV4cCI6MTYzNDM0NTcwMywidXNlcklkIjoiMjMyMl9fMl8wXzE2MzQyNTkzMDMifQ.pCmWnB_Gx00RaDAIX1gm8GbevL_B6U7N_xbVH1xf6pa1dY3TudnRcHNkMf4T9rBzaOGMyUbCvJn8FPFfQ9jXCw')
10
+ props.history.replace({pathname:path,...data})
11
+ }
12
+ return (
13
+ <div className="login">
14
+ login
15
+ <button onClick={() => {
16
+ login()
17
+ }}>登录</button>
18
+ </div>
19
+ )
20
+ }
21
+
22
+ export default withRouter(Login)
app/src/pages/user/services.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import request from '@/axios/axios'
2
+ import api from '@/axios/apiNames'
3
+
4
+
5
+ // 获取服务信息
6
+ export const getPageCustomService = () => {
7
+ let params = {
8
+ url: api.PageCustomService,
9
+ data: {
10
+ name:'msw111'
11
+ }
12
+ }
13
+ return request.get(params)
14
+ }
15
+
16
+ // 获取服务信息
17
+ export const getPageCustomService2 = () => {
18
+ let params = {
19
+ url: api.PageCustomService2,
20
+ data: {
21
+ name:'msw111'
22
+ }
23
+ }
24
+ return request.get(params)
25
+ }
26
+ // 重置密码
27
+ export const resetPassword = (name:any) => {
28
+ let params = {
29
+ url: api.resetPassword,
30
+ data: {
31
+ name
32
+ }
33
+ }
34
+ return request.post(params)
35
+ }
36
+ // 上传图片
37
+ export const uploadImage = (formData:any) => {
38
+ let params = {
39
+ url: api.commonUpload,
40
+ data: formData
41
+ }
42
+ return request.file(params)
43
+ }
44
+
45
+ // 导出申请清单
46
+ export const exportUrl = () => {
47
+ let params = {
48
+ url: api.exportDetails,
49
+ data: {
50
+ id: 4,
51
+ fileName: '申请商品明细.xls',
52
+ export: 1,
53
+ }
54
+ }
55
+ return request.get(params)
56
+ }
app/src/pages/user/user.tsx ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState,useEffect } from 'react'
2
+ import { withRouter, Prompt, useHistory } from 'react-router-dom'
3
+ import {
4
+ getPageCustomService,
5
+ getPageCustomService2,
6
+ resetPassword,
7
+ uploadImage,
8
+ exportUrl
9
+ } from './services'
10
+
11
+ function User(props: any) {
12
+ const [leave, setLeave] = useState(true)
13
+ let history = useHistory()
14
+ console.log(history)
15
+
16
+ useEffect(() => {
17
+ getData()
18
+ }, [])
19
+
20
+ // get请求
21
+ const getData = async () => {
22
+ let { data, code } = await getPageCustomService()
23
+ await getPageCustomService2()
24
+ console.log(data,code)
25
+ }
26
+ // post请求
27
+ const postData = async () => {
28
+ let { code, data } = await resetPassword("gdtest002")
29
+ console.log(code,data)
30
+ }
31
+ // 图片上传
32
+ const [file, setFile] = useState(null) as any
33
+ const imageUpload = async () => {
34
+ if (!file) {
35
+ return
36
+ }
37
+ if (file?.size > 2 * 1024 * 1024) {
38
+ alert('大了')
39
+ return
40
+ }
41
+ let formData = new FormData();
42
+ const fileName = props.name || 'file';
43
+ formData.append(fileName, file);
44
+ let {code,data} = await uploadImage(formData)
45
+ console.log(code,data)
46
+ }
47
+ // 导出/下载文件流
48
+ const exportData = async () => {
49
+ let data = await exportUrl()
50
+ console.log(data)
51
+ }
52
+
53
+ return (
54
+ <div className="User">
55
+ user
56
+ <p>
57
+ <button onClick={() => { postData() }}>post请求</button>
58
+ </p>
59
+ <p>
60
+ <button onClick={() => { history.replace('/about') }}>点我去about</button>
61
+ </p>
62
+ <p>
63
+ <button onClick={() => {exportData()}}>点我下载</button>
64
+ </p>
65
+ <p>
66
+ <input type="file" onChange={(e:any) => {setFile(e.target.files[0])}}/>
67
+ <button onClick={() => {imageUpload()}}>点我上传</button>
68
+ </p>
69
+ {/* <Prompt message={() => {
70
+ if (!leave) {
71
+ return true
72
+ }
73
+ const r = confirm('确定离开?')
74
+ return r
75
+ }} when={leave}></Prompt> */}
76
+ </div>
77
+ )
78
+ }
79
+
80
+ export default withRouter(User)
app/src/router/router.ts ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react'
2
+
3
+ // 路由懒加载
4
+ const Home = React.lazy(() => import('@/pages/home/home'))
5
+ const About = React.lazy(() => import('@/pages/about/about'))
6
+ const Login = React.lazy(() => import('@/pages/login/login'))
7
+ const User = React.lazy(() => import('@/pages/user/user'))
8
+ const Miss = React.lazy(() => import('@/pages/404/404'))
9
+
10
+ const routerMap:any[] = [
11
+ {
12
+ path: '/',
13
+ redirect: '/home',
14
+ auth: false,
15
+ footerShow: true
16
+ },
17
+ {
18
+ path: '/home',
19
+ component: Home,
20
+ auth: false,
21
+ footerShow: true
22
+ },
23
+ {
24
+ path: '/about',
25
+ component: About,
26
+ auth: false,
27
+ footerShow: true
28
+ },
29
+ {
30
+ path: '/login',
31
+ component: Login,
32
+ auth: false,
33
+ footerShow: false
34
+ },
35
+ {
36
+ path: '/user',
37
+ component: User,
38
+ auth: true,
39
+ footerShow: false
40
+ },
41
+ {
42
+ path: '/404',
43
+ component: Miss,
44
+ auth: false,
45
+ footerShow: false
46
+ },
47
+ ]
48
+
49
+ export default routerMap
app/src/router/routerConfig.tsx ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Route, Redirect, withRouter } from 'react-router-dom';
2
+ import routerMap from './router'
3
+
4
+ const BasicRoute = (props:any) => {
5
+ const pathname = props.location.pathname
6
+ const targetRouter = routerMap.find((item: any) => item.path === pathname);
7
+ const isLogin = sessionStorage.getItem('token')
8
+ if (!targetRouter) { // 页面不存在
9
+ return <Redirect to="/404" />
10
+ }
11
+ if (targetRouter && targetRouter.redirect) { // 重定向
12
+ return <Redirect to={targetRouter.redirect} />
13
+ }
14
+ if (targetRouter && !targetRouter.auth) { // 无需登录
15
+ return <Route exact path={targetRouter.path} component={targetRouter.component}/>
16
+ }
17
+ if (targetRouter.auth) { // 要登录授权
18
+ if (isLogin) { // 已登录
19
+ return <Route exact path={targetRouter.path} component={targetRouter.component} />
20
+ } else { // 未登录,要保留住之前的传参方式,哎react传参方式真多,params没做,案例只确认传参方式只会选择一下其中一种
21
+ let redirect = pathname
22
+ const query = JSON.stringify(props.location?.query)
23
+ const state = JSON.stringify(props.location?.state)
24
+ const search = props.location?.search
25
+ if (query) { // 是否是query传参
26
+ redirect += `&{"query":${query}}`
27
+ }
28
+ if (state) { // 是否是state传参
29
+ redirect += `&{"state":${state}}`
30
+ }
31
+ if (search) { // 是否是search传参
32
+ redirect += `&{"search":"${search}"}`
33
+ }
34
+ redirect = encodeURIComponent(redirect)
35
+ return <Redirect to={`/login?redirect=${redirect}`} />
36
+ }
37
+ }
38
+ };
39
+
40
+ // exact :精确匹配
41
+ export default withRouter(BasicRoute);
app/src/store/store.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+ import { createModel } from "hox";
3
+
4
+ function useCounter() {
5
+ const [count, setCount] = useState(0);
6
+ const decrement = (num?:number) => setCount(typeof num !== 'number' ? count - 1 : count - num);
7
+ const increment = (num?:number) => setCount(typeof num !== 'number' ? count + 1 : count + num);
8
+
9
+ return {
10
+ count,
11
+ decrement,
12
+ increment
13
+ };
14
+ }
15
+
16
+ export default createModel(useCounter);
app/src/utils/regexp.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * 正则
3
+ */
4
+ // 手机号
5
+ export const mobile = /^1[3456789]\d{9}$/
6
+ // 座机,必须0开头且包含短横线
7
+ export const phone = /^0\d{2,3}-\d{6,8}$/
8
+ // 邮箱
9
+ export const email = /^\w+(\.)?(\w+)?@[0-9a-z]+(\.[a-z]+){1,3}$/
10
+ // 数字
11
+ export const number = /^\d+$/
12
+ // 数字字母
13
+ export const numberLetter = /^[A-Za-z0-9]+$/
14
+ // 身份证
15
+ export const ID = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
16
+ // 中文
17
+ export const Chinese = /^[\u4e00-\u9fa5]+$/
app/src/utils/utils.ts ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const sessions = {
2
+ get(key: string) {
3
+ const data = sessionStorage[key];
4
+ if (!data || data === "null") {
5
+ return null;
6
+ }
7
+ return JSON.parse(data).value;
8
+ },
9
+ set<T>(key: string, value: T) {
10
+ const data = {
11
+ value
12
+ };
13
+ sessionStorage[key] = JSON.stringify(data);
14
+ },
15
+ // 删除
16
+ remove(key: string) {
17
+ sessionStorage.removeItem(key);
18
+ },
19
+ // 清除全部
20
+ clear() {
21
+ sessionStorage.clear();
22
+ }
23
+ };
24
+
25
+ /**
26
+ * 数据替换 *** 号
27
+ * @val 要替换的数据
28
+ * @head 头部保留,默认3
29
+ * @last 尾部保留,默认4
30
+ */
31
+ export const replaceStar = (val:any, head = 3, last = 4) => {
32
+ if (!val) { // 字符串为空直接返回
33
+ return val;
34
+ }
35
+ if (val.length <= 10) { // 少于十位的字符串只显示前三位
36
+ last = 0;
37
+ }
38
+ let str = '*';
39
+ let len = val.length - head - last;
40
+ str = str.repeat(len); // * 重复len次
41
+ let re = new RegExp('(.{' + head + '}).*(.{' + last + '})', ''); // 动态的正则验证
42
+ return val.replace(re, '$1'+str+'$2'); // 替换
43
+ };
44
+
45
+ /**
46
+ * 数字三位加逗号
47
+ * @value 数据
48
+ */
49
+ export const numberFormat = (value:[number,string]) => {
50
+ if(value !== undefined && value !== null) {
51
+ let str = value.toString();
52
+ let reg = str.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
53
+ return str.replace(reg, '$1,');
54
+ } else {
55
+ return '';
56
+ }
57
+ };
app/src/vite-env.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ /// <reference types="vite/client" />
app/tsconfig.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
6
+ "allowJs": false,
7
+ "skipLibCheck": false,
8
+ "esModuleInterop": false,
9
+ "allowSyntheticDefaultImports": true,
10
+ "strict": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "module": "ESNext",
13
+ "moduleResolution": "Node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "noEmit": true,
17
+ "jsx": "react-jsx"
18
+ },
19
+ "include": [
20
+ "./src",
21
+ "./typing.d.ts"
22
+ ]
23
+ }
app/typing.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare module 'react-router-dom'
2
+ declare module '@*'
3
+ declare module 'components*'
4
+ declare module 'axios'
5
+
6
+ interface Window {
7
+ $cancelRequest: Function;
8
+ }
9
+ interface Date { // 给Date添加方法
10
+ Format(params: any): void;
11
+ }
app/vite.config.ts ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { defineConfig } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+ const path = require("path");
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig({
7
+ plugins: [
8
+ react()
9
+ ],
10
+ server: {
11
+ // host: '10.5.9.31',
12
+ port: 7860,
13
+ proxy: {
14
+ '/dev': { // 开发地址,请换成正式地址
15
+ // target: 'http://10.5.9.31:8080',
16
+ // target: 'http://10.21.1.104:9999',
17
+ changeOrigin: true,
18
+ rewrite: (path) => path.replace(/^\/dev/, '')
19
+ },
20
+ // '/test': { // 测试地址
21
+ // target: 'http://127.0.0.1:9999',
22
+ // changeOrigin: true,
23
+ // rewrite: (path) => path.replace(/^\/test/, '')
24
+ // },
25
+ // '/production': { // 生产地址
26
+ // target: 'http://127.0.0.1:9999',
27
+ // changeOrigin: true,
28
+ // rewrite: (path) => path.replace(/^\/production/, '')
29
+ // },
30
+ }
31
+ },
32
+ base:'./',
33
+ resolve: {
34
+ alias: {
35
+ '@':path.resolve(__dirname, "src"),
36
+ 'components':path.resolve(__dirname, "src/components")
37
+ }
38
+ },
39
+ css: {
40
+ preprocessorOptions: {
41
+ less: {
42
+ javascriptEnabled: true,
43
+ additionalData: `@import "${path.resolve(__dirname, 'src/global.less')}";`
44
+ }
45
+ },
46
+ postcss: {
47
+ plugins: [
48
+ require("autoprefixer"),
49
+ require("postcss-px-to-viewport")({
50
+ viewportWidth: 750, //视窗的宽度,对应的是我们设计稿的宽度,一般是750
51
+ viewportHeight: 1334, // 视窗的高度,根据750设备的宽度来指定,一般指定1334,也可以不配置
52
+ unitPrecision: 3, // 指定`px`转换为视窗单位值的小数位数(很多时候无法整除)
53
+ viewportUnit: 'vw', // 指定需要转换成的视窗单位,建议使用vw
54
+ selectorBlackList: ['.ignore', '.hairlines'], // 指定不转换为视窗单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名
55
+ minPixelValue: 1, // 小于或等于`1px`不转换为视窗单位,你也可以设置为你想要的值
56
+ mediaQuery: false, // 允许在媒体查询中转换`px`
57
+ exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
58
+ landscape: false // 是否处理横屏情况
59
+ })
60
+ ]
61
+ }
62
+ }
63
+ })