Browse Source

init

master
lc18518571399 11 months ago
parent
commit
69a25f90b6
  1. 1
      api/.eslintignore
  2. 4
      api/.eslintrc
  3. 15
      api/.gitignore
  4. 31
      api/README.md
  5. 18
      api/agent.js
  6. 47
      api/app.js
  7. 10
      api/app/controller/user.js
  8. 46
      api/app/model/user.js
  9. 7
      api/app/router.js
  10. 67
      api/app/service/user.js
  11. 45
      api/config/config.default.js
  12. 11
      api/config/plugin.js
  13. 5
      api/jsconfig.json
  14. 41
      api/package.json
  15. 0
      api/read.me
  16. 23
      api/test/app/controller/home.test.js
  17. 25
      front/.gitignore
  18. 7
      front/README.md
  19. 12
      front/index.html
  20. 30
      front/package.json
  21. 9
      front/public/config.json
  22. 1
      front/public/vite.svg
  23. 16
      front/src/App.vue
  24. 27
      front/src/api/user.js
  25. 3
      front/src/assets/css/base.css
  26. 18
      front/src/main.js
  27. 39
      front/src/plugins/axios.js
  28. 79
      front/src/style.css
  29. 19
      front/src/utils/nprogress.js
  30. 42
      front/vite.config.js
  31. 0
      read.me

1
api/.eslintignore

@ -0,0 +1 @@
coverage

4
api/.eslintrc

@ -0,0 +1,4 @@
{
"extends": "eslint-config-egg",
"root": true
}

15
api/.gitignore

@ -0,0 +1,15 @@
logs/
npm-debug.log
yarn-error.log
node_modules/
*-lock.json
*-lock.yaml
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
typings/
.nyc_output/

31
api/README.md

@ -0,0 +1,31 @@
# back
back
## QuickStart
<!-- add docs here for user -->
see [egg docs][egg] for more detail.
### Development
```bash
npm i
npm run dev
open http://localhost:7001/
```
### Deploy
```bash
npm start
npm stop
```
### npm scripts
- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
[egg]: https://eggjs.org

18
api/agent.js

@ -0,0 +1,18 @@
// agent.js
const md5 = require('md5');
module.exports = agent => {
// 在这里写你的初始化逻辑。
// 你还可以通过 messenger 对象发送消息给 App Worker。
// 但是,需要等 App Worker 启动成功后才能发送,否则可能丢失消息。
agent.messenger.on('egg-ready', () => {
let params = {
subType: "add",
name: "admin",
password: md5("admin"),
email: "admin@admin.com",
allowRegist: true,
}
agent.messenger.sendToApp('createAdmin', params);
});
};

47
api/app.js

@ -0,0 +1,47 @@
// app.js
class AppBootHook {
constructor(app) {
this.app = app;
}
configWillLoad() {
// 此时 config 文件已经被读取并合并,但还并未生效
// 这是应用层修改配置的最后机会
// 注意:此函数只支持同步调用
}
async didLoad() {
// 所有配置已经加载完毕
// 可以用来加载应用自定义的文件,启动自定义服务
}
async willReady() {
// 所有插件已启动完毕,但应用整体尚未 ready
// 可进行数据初始化等操作,这些操作成功后才启动应用
}
async didReady() {
// 应用已启动完毕
}
async serverDidReady() {
// http/https 服务器已启动,开始接收外部请求
// 此时可以从 app.server 获取 server 实例
const ctx = await this.app.createAnonymousContext();
this.app.messenger.on('createAdmin', async params => {
let res = await ctx.model.User.find({ name: params.name });
if (!res.length) {
await ctx.service.user.index(params)
}
});
}
}
module.exports = AppBootHook;

10
api/app/controller/user.js

@ -0,0 +1,10 @@
const { Controller } = require('egg');
class UserController extends Controller {
async index() {
const { ctx } = this;
ctx.body = await ctx.service.user.index(ctx.request.body)
}
}
module.exports = UserController;

46
api/app/model/user.js

@ -0,0 +1,46 @@
'use strict';
module.exports = app => {
const mongoose = app.mongoose;
const Schema = mongoose.Schema;
const UserSchema = new Schema({
create_at: {
type: Date,
default: Date.now
},
update_at: {
type: Date,
default: Date.now
},
name: {
type: String,
default: "",
},
phone: {
type: String,
default: ""
},
imgname: {
type: String,
default: ""
},
imgbase64: {
type: String,
default: ""
},
downCount: {
type: Number,
default: 0
},
down_time: {
type: Array,
default: []
},
isExit: {
type: Number,
default: 1
},
}, { strict: false });
return mongoose.model('User', UserSchema);
};

7
api/app/router.js

@ -0,0 +1,7 @@
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { router, controller } = app;
router.post('/v1/user', controller.user.index);
};

67
api/app/service/user.js

@ -0,0 +1,67 @@
'use strict';
const Service = require('egg').Service;
const _ = require("lodash")
class UserService extends Service {
async index(params) {
let { ctx } = this
let modelLocal = ctx.model.User
let returnData = { hasError: false, msg: "数据错误", list: [] }
//新增
let subType = params.subType
let returnComponent = params.returnData || []
let paramsLocal = _.omit(params, ["subType", "returnData"])
if (subType === "add") {
paramsLocal["update_at"] = Date.now();
let res = await modelLocal.create(paramsLocal)
returnData.hasError = false
returnData.msg = "数据新增成功"
returnData.list = res
} else if (subType === "multi") {
paramsLocal["update_at"] = Date.now();
let res = await modelLocal.insertMany(paramsLocal.list)
returnData.hasError = false
returnData.msg = "数据新增成功"
returnData.list = res
} else if (subType === "del") {
let res = await modelLocal.updateMany({ _id: { $in: paramsLocal.ids } }, { isExit: 0, update_at: Date.now() })
returnData.hasError = false
returnData.msg = "数据删除成功"
returnData.list = res
} else if (subType === "edit") {
paramsLocal["update_at"] = Date.now();
let res = await modelLocal.updateOne({ _id: paramsLocal._id }, paramsLocal)
returnData.hasError = false
returnData.msg = "数据更新成功"
returnData.list = res
} else if (subType === "get") {
let pageSize = paramsLocal.pageSize
let currentPage = paramsLocal.currentPage
let paramsLocalInfo = _.omit(paramsLocal, ["pageSize", "currentPage"])
let paramsLocalInfoNotDel = { ...paramsLocalInfo, isExit: 1 }
let res = await modelLocal.find(paramsLocalInfoNotDel).sort({ update_at: -1 }).skip((currentPage - 1) * pageSize).limit(pageSize)
let count = await modelLocal.find(paramsLocalInfoNotDel).count()
let resData = [];
for (let i = 0; i < res.length; i++) {
let elei = res[i];
let resObj = { _id: elei._id }
if (returnComponent.length) {
for (let j = 0; j < returnComponent.length; j++) {
let elej = returnComponent[j];
resObj[elej] = elei[elej]
}
} else {
resObj = elei
}
resData.push(resObj)
}
returnData.hasError = false
returnData.msg = "查询成功"
returnData.list = resData
returnData["count"] = count
}
return returnData
}
}
module.exports = UserService;

45
api/config/config.default.js

@ -0,0 +1,45 @@
/* eslint valid-jsdoc: "off" */
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1708915616027_8852';
// add your middleware config here
config.middleware = [];
config.mongoose = {
client: {
url: 'mongodb://127.0.0.1:27010/back',
options: {}
}
}
config.security = {
csrf: {
// 判断是否需要 ignore 的方法,请求上下文 context 作为第一个参数
// ignore: ctx => isInnerIp(ctx.ip),
ignore: '/',
},
};
config.bodyParser = {
formLimit: "100mb",
jsonLimit: "100mb",
textLimit: "100mb",
}
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
return {
...config,
...userConfig,
};
};

11
api/config/plugin.js

@ -0,0 +1,11 @@
/** @type Egg.EggPlugin */
module.exports = {
// had enabled by egg
// static: {
// enable: true,
// }
mongoose: {
enable: true,
package: 'egg-mongoose',
},
};

5
api/jsconfig.json

@ -0,0 +1,5 @@
{
"include": [
"**/*"
]
}

41
api/package.json

@ -0,0 +1,41 @@
{
"name": "back",
"version": "1.0.0",
"description": "back",
"private": true,
"egg": {
"declarations": true
},
"dependencies": {
"egg": "^3.17.5",
"egg-mongoose": "^4.0.1",
"egg-scripts": "2",
"lodash": "^4.17.21",
"md5": "^2.3.0"
},
"devDependencies": {
"egg-bin": "6",
"egg-mock": "5",
"eslint": "8",
"eslint-config-egg": "13"
},
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-back",
"stop": "egg-scripts stop --title=egg-server-back",
"dev": "egg-bin dev",
"test": "npm run lint -- --fix && npm run test:local",
"test:local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov"
},
"repository": {
"type": "git",
"url": ""
},
"author": "lichong",
"license": "MIT"
}

0
api/read.me

23
api/test/app/controller/home.test.js

@ -0,0 +1,23 @@
const { strict: assert } = require('node:assert');
const path = require('node:path');
const { statSync } = require('node:fs');
const { app } = require('egg-mock/bootstrap');
describe('test/app/controller/home.test.js', () => {
it('should assert', async () => {
const pkg = require('../../../package.json');
assert(app.config.keys.startsWith(pkg.name));
});
it('should typings exists', async () => {
const typings = path.join(__dirname, '../../../typings');
assert(statSync(typings));
});
it('should GET /', async () => {
return app.httpRequest()
.get('/')
.expect('hi, egg')
.expect(200);
});
});

25
front/.gitignore

@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
package-lock.json
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

7
front/README.md

@ -0,0 +1,7 @@
# base
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

12
front/index.html

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

30
front/package.json

@ -0,0 +1,30 @@
{
"name": "base",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"axios": "^1.6.6",
"dayjs": "^1.11.10",
"element-plus": "^2.5.3",
"lodash": "^4.17.21",
"md5": "^2.3.0",
"nprogress": "^0.2.0",
"papaparse": "^5.4.1",
"qs": "^6.11.2",
"unplugin-auto-import": "^0.17.4",
"unplugin-vue-components": "^0.26.0",
"vue": "^3.3.11",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.6.2",
"vite": "^5.0.8"
}
}

9
front/public/config.json

@ -0,0 +1,9 @@
{
"title": "可视化预警平台",
"jianceduixiang1path": "@/assets/img/jianceduixiang1.gif",
"jianceduixiang2path": "@/assets/img/jianceduixiang2.jpg",
"jianceduixiang3path": "@/assets/img/jianceduixiang3.png",
"jianceduixiang4path": "@/assets/img/jianceduixiang4.png",
"jianceduixiang5path": "@/assets/img/jianceduixiang5.gif",
"jianceduixiang6path": "@/assets/img/jianceduixiang6.gif"
}

1
front/public/vite.svg

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.1 19.7L8.8 19L9 18.6C7.1 18.1 6 17.3 6 17V14.8C7.3 15.4 8.8 15.8 10.6 16C11.3 15.2 12.2 14.5 13.1 14H12C9.6 14 7.3 13.4 6 12.5V9.6C7.5 10.4 9.6 11 12 11S16.5 10.5 18 9.6V12.4C17.7 12.6 17.4 12.8 17 13C18 13 19 13.2 20 13.6V7C20 4.8 16.4 3 12 3S4 4.8 4 7V17C4 18.8 6.4 20.3 9.7 20.8C9.5 20.5 9.3 20.1 9.1 19.7M12 5C15.9 5 18 6.5 18 7S15.9 9 12 9 6 7.5 6 7 8.1 5 12 5M17 18C17.6 18 18 18.4 18 19S17.6 20 17 20 16 19.6 16 19 16.4 18 17 18M17 15C14.3 15 11.9 16.7 11 19C11.9 21.3 14.3 23 17 23S22.1 21.3 23 19C22.1 16.7 19.7 15 17 15M17 21.5C15.6 21.5 14.5 20.4 14.5 19S15.6 16.5 17 16.5 19.5 17.6 19.5 19 18.4 21.5 17 21.5Z" /></svg>

After

Width:  |  Height:  |  Size: 702 B

16
front/src/App.vue

@ -0,0 +1,16 @@
<template>h5</template>
<script>
export default {
name: "app",
data() {
return {};
},
async mounted() {},
methods: {},
watch: {},
computed: {},
};
</script>
<style scoped>
</style>

27
front/src/api/user.js

@ -0,0 +1,27 @@
import _axios from "@/plugins/axios";
//增加用户
export function addUser(data) {
return _axios({
url: `/v1/user`,
method: "POST",
data,
});
}
//删除用户
export function delUser(data) {
return _axios({
url: `/v1/user`,
method: "POST",
data,
});
}
//查找用户
export function getUser(data) {
return _axios({
url: `/v1/user`,
method: "POST",
data,
});
}

3
front/src/assets/css/base.css

@ -0,0 +1,3 @@
body {
margin: 0;
}

18
front/src/main.js

@ -0,0 +1,18 @@
import App from "./App.vue";
import { createApp } from "vue";
//全局引入lodash
import _ from "lodash";
//全局引入lodash
import dayjs from "dayjs";
// 引入css
import "@/assets/css/base.css";
//全局引入element-plus所有图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.config.globalProperties.$_ = _; //挂载到app实例上
app.config.globalProperties.$dayjs = dayjs; //挂载到app实例上
app.mount("#app");

39
front/src/plugins/axios.js

@ -0,0 +1,39 @@
import axios from "axios";
import qs from "qs";
let config = {
baseURL: "",
timeout: 600 * 1000,
withCredentials: true, // Check cross-site Access-Control
/* `paramsSerializer` `params`
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
*/
paramsSerializer: (params) => {
return qs.stringify(params, { arrayFormat: "indices" });
},
};
const _axios = axios.create(config);
_axios.interceptors.request.use(
(config) => {
return config;
},
(error) => {
return Promise.reject(error);
}
);
_axios.interceptors.response.use(
(response) => {
return Promise.resolve(response.data);
},
(error) => {
ElMessage.error(error.response.data.message);
return Promise.reject(error);
}
);
export default _axios;

79
front/src/style.css

@ -0,0 +1,79 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
.card {
padding: 2em;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

19
front/src/utils/nprogress.js

@ -0,0 +1,19 @@
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({
easing: 'ease', // 动画方式
speed: 1000, // 递增进度条的速度
showSpinner: false, // 是否显示加载ico
trickleSpeed: 200, // 自动递增间隔
minimum: 0.3, // 更改启动时使用的最小百分比
parent: 'body', //指定进度条的父容器
})
// 打开进度条
export const start = () => {
NProgress.start()
}
// 关闭进度条
export const close = () => {
NProgress.done()
}

42
front/vite.config.js

@ -0,0 +1,42 @@
// Plugins
import vue from "@vitejs/plugin-vue";
// Utilities
import { defineConfig } from "vite";
import { fileURLToPath, URL } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
define: { "process.env": {} },
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
extensions: [".js", ".json", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
},
server: {
port: 3000,
proxy: {
"/v1": {
target: "http://127.0.0.1:7001/v1",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/v1/, ""),
},
},
},
build: {
sourcemap: true,
},
});

0
read.me

Loading…
Cancel
Save