Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加 Leaflet 项目作为地图打点,可以在web上预览 #899

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
## 前端

- [x] F001: 以城市为单位,实现可视化统计
- [ ] F002: 以小区为单位,实现可视化,思路:结合城市与小区,对接高德api,基于每个小区的轮廓数据画polygon
- [ ] F002: 以小区为单位,实现可视化,思路:结合城市与小区,对接开源的地图库,例如:[Leaflet](https://github.com/Leaflet/Leaflet) 或者其他,基于每个小区的轮廓数据画polygon
- [ ] F003: 以小区为单位,统计开发商信息,思路:搜索城市与小区,看是否有相关的开发商信息,爬虫并汇总数据
- [ ] ...
72 changes: 72 additions & 0 deletions development/frontend/leaflet/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"env": {
"browser": true,
"es2021": true
},
"settings": {
"react": {
"version": "detect"
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
"indent": "off",
"@typescript-eslint/indent": ["error", 4],
"no-multiple-empty-lines": ["error"],
"keyword-spacing": ["error"],
"key-spacing": ["error"],
"camelcase": ["error"],
"eqeqeq": ["error"],
"no-alert": ["error"],
"no-eval": ["error"],
"no-nested-ternary": ["error"],
"no-plusplus": ["error"],
"array-callback-return": ["error"],
"consistent-return": ["error"],
"default-case": "error",
"no-caller": "error",
"no-else-return": "error",
"no-implied-eval": "error",
"no-useless-return": "error",
"radix": "error",
"no-use-before-define": "off",
"array-bracket-spacing": "error",
"object-curly-spacing": ["error", "always"],
"@typescript-eslint/no-use-before-define": ["error"],
"computed-property-spacing":"error",
"jsx-quotes": "error",
"no-negated-condition": "error",
"spaced-comment": "error",
"func-call-spacing": "off",
"@typescript-eslint/func-call-spacing": ["error"],
"space-infix-ops": ["error"],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
}
31 changes: 31 additions & 0 deletions development/frontend/leaflet/.fastpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import FastpackPluginLessLoader from '@weblif/plugin-less-loader'
import ESLintPlugin from 'eslint-webpack-plugin'
import { getFastpackConfig } from '@weblif/fastpack'

/**
* 扩展 Webpack 的信息
*/
class WebpackChainPlugin {
after(webpack: any) {
webpack.plugin('fastpack/ESLintPlugin').use(ESLintPlugin, [{
extensions: ['.ts', '.tsx', '.js', '.jsx']
}])
}
}

export default getFastpackConfig({
title: 'test',
router: {
paths: [
'/'
],
notFound: '/components/NotFound',
loading: '/components/Loading',
layout: '/layouts'
},
publicPath: '/ms-template',
plugins: [
new FastpackPluginLessLoader({}),
new WebpackChainPlugin()
]
})
19 changes: 19 additions & 0 deletions development/frontend/leaflet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Dependency directories
node_modules

src/.fastpack

# husky
.husky

dist

6 changes: 6 additions & 0 deletions development/frontend/leaflet/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
21 changes: 21 additions & 0 deletions development/frontend/leaflet/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Web-Lif

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
182 changes: 182 additions & 0 deletions development/frontend/leaflet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<h1 align="center">MS Template</h1>

<div align="center">
开箱即用的中台前端/设计解决方案。并且支持多标签和单标签模式。
</div>

<br />

![image](https://user-images.githubusercontent.com/91561865/142795569-6ae1150f-f3de-4857-9833-1f7590a81066.png)


## 快速开始

> PS: 此项目属于探索阶段,在没有发布 `1.0.0` 版本的情况下,任何 `API` 也项目结构都可能会进行重大的调整以及改变。


使用下面命令克隆项目

```sh

# 克隆项目
git clone https://github.com/Web-Lif/ms-template.git

# 安装依赖
npm run install

# 启动项目
npm run start

# 可选, 进行编译 dist 文件
npm run build

# 可选, 检查 eslint
npm run lint:script

# 可选,执行测试测过
npm run test
```


```sh
.
├── babel.config.js
├── jest.config.ts
├── LICENSE
├── package.json
├── package-lock.json
├── README.md
├── src
│ ├── app.tsx
│ ├── components
│ │ ├── Loading.tsx
│ │ ├── NotFound.tsx
│ │ └── styles
│ │ ├── assets
│ │ │ └── undraw_Taken_re_yn20.svg
│ │ └── notfound.mless
│ ├── layouts
│ │ ├── BasicLayout.tsx
│ │ ├── index.tsx
│ │ └── styles
│ │ └── layout.mless
│ ├── pages
│ │ ├── index.tsx
│ │ ├── User
│ │ │ ├── Login.tsx
│ │ │ └── styles
│ │ │ ├── assets
│ │ │ │ └── LoginBackground.svg
│ │ │ └── login.mless
│ │ └── welcome.tsx
│ ├── typings.d.ts
│ └── utils
└── tsconfig.json
```

项目的大致目录如下

- `pages` 只有在 pages 编写的页面,才能配置成为路由信息
- `layouts` 主要的布局文件
- `components` 项目中自定义的组件信息
- `app.tsx` 留给用户的扩展点,里面都会配置对应的接口和方法

## 配置说明

在项目中 `src/app.tsx` 会有很多导出的函数,这些函数需要使用者进行实现,或则进行修改进行扩展功能


### config

- layout `'side' | 'top'| 'mix'` 菜单的布局方式
- navTheme `'light' | 'dark'` 导航的主题,side 和 mix 模式下是左侧菜单的主题,top 模式下是顶部菜单
- headerTheme `'light' | 'dark'` 顶部导航的主题,mix 模式生效
- tabs `'single' | 'multi'` 标签页模式

一些全局的配置信息

### checkLoginStatus

- return `boolean`

检查用户是否登入, `true` 表示用户已经登入, `false` 表示用户已经退出

### requestIgnoreList

- return `string[]`

如果请求的路径匹配到了返回的结果,表示这个路由是不经过 `layouts` 处理, 也就是用户可以自定自己想要的登入页面。

### requestGlobalData

- return `Promise<GlobalData>`

请求后端接口,返回当期的菜单信息, 以及对应的人员信息


## 多标签页说明

当用户开启多标签页模式的时候,那么就会想子组件传递一个 `tabs` 的属性

`tabs` 有以下信息

- `open` 开启一个新的标签页面
- `close` 关闭一个标签页面
- `active` 激活当前标签页面
- `status` 当期的标签页的状态
- `params` 传入进来的参数信息

> 见 [src/types.ts](./src/types.ts) 里面的 `RouteComponentProps` 的定义


建议采用 `RouteComponentProps` 来定义类型,这样有更好的开发体验


```tsx
import React, { FC, useRef } from 'react'
import { Button } from '@weblif/fast-ui'
import { RouteComponentProps } from '@/types'


const App: FC<RouteComponentProps> = ({
tabs
}) => {
const count = useRef<number>(0)
return (
<>
<Button
onClick={() => {
count.current += 1
tabs.active({
key: '/',
params: {
message: `hello, word - ${count.current}`
}
})
}}
>
点击跳转到首页
</Button>
<Button
onClick={() => {
count.current += 1
tabs.open({
item: {
key: `newHome${count.current}`,
path: '/',
name: 'New Home Tab'
},
params: {
message: `hello, word New - ${count.current} `
}
})
}}
>
打开新的首页信息
</Button>
</>
)
}

export default App
```
7 changes: 7 additions & 0 deletions development/frontend/leaflet/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [['@babel/preset-env', {
targets: {
node: 'current',
}
}], '@babel/preset-react', '@babel/preset-typescript']
};
Loading