first commit
This commit is contained in:
commit
e40b2117b5
21 changed files with 17956 additions and 0 deletions
15
backend/.eslintrc.js
Executable file
15
backend/.eslintrc.js
Executable file
|
@ -0,0 +1,15 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
commonjs: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: [
|
||||
'airbnb-base',
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 12,
|
||||
},
|
||||
rules: {
|
||||
},
|
||||
};
|
4
backend/.gitignore
vendored
Executable file
4
backend/.gitignore
vendored
Executable file
|
@ -0,0 +1,4 @@
|
|||
node_modules
|
||||
!.gitkeep
|
||||
csv/*
|
||||
public/*
|
119
backend/index.js
Executable file
119
backend/index.js
Executable file
|
@ -0,0 +1,119 @@
|
|||
const path = "./csv";
|
||||
const data = {};
|
||||
const column = {};
|
||||
let files = [];
|
||||
|
||||
const fs = require("fs");
|
||||
const papa = require("papaparse");
|
||||
const chokidar = require("chokidar");
|
||||
|
||||
chokidar.watch(path).on("all", () => {
|
||||
console.log("File changed. Reloading ...");
|
||||
files = fs.readdirSync(`${path}`).filter((file) => file.endsWith(".csv"));
|
||||
for (const file of files) {
|
||||
const csv = fs.readFileSync(`${path}/${file}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
const parsed = papa.parse(csv, {
|
||||
skipEmptyLines: true,
|
||||
}).data;
|
||||
|
||||
const header = parsed[0];
|
||||
column[file] = [];
|
||||
for (const h of header) {
|
||||
column[file].push({
|
||||
key: h,
|
||||
text: h,
|
||||
sorting: "",
|
||||
});
|
||||
}
|
||||
|
||||
const converted = [];
|
||||
for (let j = 1; j < parsed.length; ++j) {
|
||||
const d = parsed[j];
|
||||
const e = {};
|
||||
for (let i = 0; i < d.length; ++i) {
|
||||
e[header[i]] = d[i];
|
||||
}
|
||||
converted.push(e);
|
||||
}
|
||||
data[file] = converted;
|
||||
}
|
||||
});
|
||||
|
||||
const express = require("express");
|
||||
|
||||
const app = express();
|
||||
|
||||
const cors = require("cors");
|
||||
|
||||
app.use(cors());
|
||||
|
||||
const port = 3000;
|
||||
|
||||
app.get("/files", (_, res) => {
|
||||
res.send(files);
|
||||
});
|
||||
|
||||
function compare(a, b) {
|
||||
const m = a - b;
|
||||
if (isNaN(m)) {
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
app.get("/csv/:file", (req, res) => {
|
||||
const {
|
||||
file
|
||||
} = req.params;
|
||||
const raw = data[file];
|
||||
const col = column[file];
|
||||
let processed = raw;
|
||||
let query_key = "";
|
||||
let key = "";
|
||||
|
||||
const c = col.find((ele) => {
|
||||
key = ele.key;
|
||||
query_key = `sort_${key}`;
|
||||
return query_key in req.query;
|
||||
});
|
||||
if (!(c === "undefined")) {
|
||||
processed = [...raw];
|
||||
if (req.query[query_key] == "ASC") {
|
||||
processed.sort((a, b) => compare(a[key], b[key]));
|
||||
} else {
|
||||
processed.sort((a, b) => compare(b[key], a[key]));
|
||||
}
|
||||
}
|
||||
|
||||
if ("pSize" in req.query && "cPage" in req.query) {
|
||||
const size = req.query.pSize;
|
||||
const page = req.query.cPage;
|
||||
processed = processed.slice((page - 1) * size, page * size);
|
||||
}
|
||||
|
||||
res.send({
|
||||
totals: raw.length,
|
||||
data: processed,
|
||||
});
|
||||
});
|
||||
|
||||
app.use(express.static("public"));
|
||||
|
||||
app.get("/column/:file", (req, res) => {
|
||||
const {
|
||||
file
|
||||
} = req.params;
|
||||
res.send(column[file]);
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Listening at http://localhost:${port}`);
|
||||
});
|
2121
backend/package-lock.json
generated
Executable file
2121
backend/package-lock.json
generated
Executable file
File diff suppressed because it is too large
Load diff
22
backend/package.json
Executable file
22
backend/package.json
Executable file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "backend",
|
||||
"version": "0.1.0",
|
||||
"description": "backed of project csv2html",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"chokidar": "^3.5.2",
|
||||
"express": "^4.17.1",
|
||||
"papaparse": "^5.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"eslint": "^7.30.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-plugin-import": "^2.23.4"
|
||||
},
|
||||
"scripts": {
|
||||
"serve": "node index.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
2
frontend/.env.development
Executable file
2
frontend/.env.development
Executable file
|
@ -0,0 +1,2 @@
|
|||
VUE_APP_BASE_URL="/"
|
||||
VUE_APP_AXIOS_BASE_URL="http://localhost:3000"
|
2
frontend/.env.production
Executable file
2
frontend/.env.production
Executable file
|
@ -0,0 +1,2 @@
|
|||
VUE_APP_BASE_URL="/"
|
||||
VUE_APP_AXIOS_BASE_URL=""
|
23
frontend/.gitignore
vendored
Executable file
23
frontend/.gitignore
vendored
Executable file
|
@ -0,0 +1,23 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
24
frontend/README.md
Executable file
24
frontend/README.md
Executable file
|
@ -0,0 +1,24 @@
|
|||
# csv2html
|
||||
|
||||
## Project setup
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
```
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Lints and fixes files
|
||||
```
|
||||
npm run lint
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
12
frontend/babel.config.js
Executable file
12
frontend/babel.config.js
Executable file
|
@ -0,0 +1,12 @@
|
|||
module.exports = {
|
||||
presets: [["@babel/preset-env", { modules: false }]],
|
||||
plugins: [
|
||||
[
|
||||
"component",
|
||||
{
|
||||
libraryName: "element-ui",
|
||||
styleLibraryName: "theme-chalk",
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
BIN
frontend/dist.tar
Normal file
BIN
frontend/dist.tar
Normal file
Binary file not shown.
5
frontend/jsconfig.json
Executable file
5
frontend/jsconfig.json
Executable file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"include": [
|
||||
"./src/**/*"
|
||||
]
|
||||
}
|
15356
frontend/package-lock.json
generated
Executable file
15356
frontend/package-lock.json
generated
Executable file
File diff suppressed because it is too large
Load diff
54
frontend/package.json
Executable file
54
frontend/package.json
Executable file
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"name": "csv2html",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.4",
|
||||
"core-js": "^3.18.1",
|
||||
"element-ui": "^2.15.6",
|
||||
"gridmanager-vue": "^1.10.3",
|
||||
"lodash": "^4.17.21",
|
||||
"validator": "^13.6.0",
|
||||
"vue": "^2.6.11",
|
||||
"vue-axios": "^3.3.7",
|
||||
"vue-lodash": "^2.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.15.6",
|
||||
"@vue/cli-plugin-babel": "~4.5.0",
|
||||
"@vue/cli-plugin-eslint": "~4.5.0",
|
||||
"@vue/cli-service": "~4.5.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-plugin-component": "^1.1.1",
|
||||
"eslint": "^6.7.2",
|
||||
"eslint-plugin-html": "^6.2.0",
|
||||
"eslint-plugin-vue": "^6.2.2",
|
||||
"npm": "^7.24.1",
|
||||
"vue-cli-plugin-element": "~1.0.1",
|
||||
"vue-template-compiler": "^2.6.11"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"plugin:vue/essential",
|
||||
"eslint:recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"parser": "babel-eslint"
|
||||
},
|
||||
"rules": {}
|
||||
},
|
||||
"browserslist": [
|
||||
"> 1%",
|
||||
"last 2 versions",
|
||||
"not dead"
|
||||
]
|
||||
}
|
BIN
frontend/public/favicon.ico
Executable file
BIN
frontend/public/favicon.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
30
frontend/public/index.html
Executable file
30
frontend/public/index.html
Executable file
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
<style>
|
||||
* {
|
||||
font-family: "Helvetica Neue", Helvetica, "PingFang SC",
|
||||
"Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong
|
||||
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work
|
||||
properly without JavaScript enabled. Please enable it to
|
||||
continue.</strong
|
||||
>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
63
frontend/src/App.vue
Executable file
63
frontend/src/App.vue
Executable file
|
@ -0,0 +1,63 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-tabs type="border-card">
|
||||
<el-tab-pane :key="i" v-for="(csv, i) in csvFiles" :label="csv">
|
||||
<CSVTable :csv-file="csv" :paging="paging"></CSVTable>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<div class="options">
|
||||
<el-checkbox v-model="paging">分页</el-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CSVTable from "./components/CSVTable.vue";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
CSVTable,
|
||||
},
|
||||
data: function () {
|
||||
return {
|
||||
paging: true,
|
||||
csvFiles: [],
|
||||
};
|
||||
},
|
||||
created: function () {
|
||||
this.axios.get("/files").then((response) => {
|
||||
this.csvFiles = response.data;
|
||||
});
|
||||
},
|
||||
mounted: function () {
|
||||
if (localStorage.paging) {
|
||||
this.paging = localStorage.paging == "true";
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
paging: function () {
|
||||
localStorage.paging = this.paging;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-tabs {
|
||||
box-sizing: border-box;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.el-tabs >>> .el-tabs__content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.options {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
height: 40px;
|
||||
padding: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
</style>
|
60
frontend/src/components/CSVTable.vue
Executable file
60
frontend/src/components/CSVTable.vue
Executable file
|
@ -0,0 +1,60 @@
|
|||
<template>
|
||||
<grid-manager
|
||||
class="table"
|
||||
v-if="ready"
|
||||
:option="gridOption"
|
||||
:key="renderKey"
|
||||
></grid-manager>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
csvFile: String,
|
||||
paging: Boolean,
|
||||
},
|
||||
data: function () {
|
||||
return {
|
||||
ready: false,
|
||||
columnData: {},
|
||||
renderKey: 0,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
gridOption: function () {
|
||||
return {
|
||||
columnData: this.columnData,
|
||||
ajaxData: `${this.axios.defaults.baseURL}/csv/${this.csvFile}`,
|
||||
gridManagerName: this.csvFile,
|
||||
supportCheckbox: false,
|
||||
supportAjaxPage: this.paging,
|
||||
supportMenu: false,
|
||||
disableCache: false,
|
||||
height: "100vh - 40px",
|
||||
width: "100vw",
|
||||
};
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
paging: function () {
|
||||
this.renderKey++;
|
||||
},
|
||||
},
|
||||
created: function () {
|
||||
this.axios.get(`/column/${this.csvFile}`).then((response) => {
|
||||
for (let d of response.data) {
|
||||
d.template = (val) => {
|
||||
let escVal = this._.escape(val);
|
||||
if (this.validator.isURL(val)) {
|
||||
return `<el-link type="primary" href="${escVal}" target="_blank">${escVal}</el-link>`;
|
||||
} else {
|
||||
return escVal;
|
||||
}
|
||||
};
|
||||
}
|
||||
this.columnData = response.data;
|
||||
this.ready = true;
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
27
frontend/src/main.js
Executable file
27
frontend/src/main.js
Executable file
|
@ -0,0 +1,27 @@
|
|||
import Vue from "vue";
|
||||
|
||||
Vue.config.productionTip = false;
|
||||
|
||||
import "./plugins/element.js";
|
||||
|
||||
import GridManager from "gridmanager-vue";
|
||||
import "gridmanager-vue/css/gm-vue.css";
|
||||
Vue.use(GridManager);
|
||||
|
||||
import axios from "axios";
|
||||
import VueAxios from "vue-axios";
|
||||
axios.defaults.baseURL = process.env.VUE_APP_AXIOS_BASE_URL;
|
||||
Vue.use(VueAxios, axios);
|
||||
|
||||
import VueLodash from "vue-lodash";
|
||||
import lodash from "lodash";
|
||||
Vue.use(VueLodash, { name: "custom", lodash: lodash });
|
||||
|
||||
import validator from "validator";
|
||||
Vue.prototype.validator = validator;
|
||||
|
||||
import App from "./App.vue";
|
||||
|
||||
new Vue({
|
||||
render: (h) => h(App),
|
||||
}).$mount("#app");
|
7
frontend/src/plugins/element.js
Executable file
7
frontend/src/plugins/element.js
Executable file
|
@ -0,0 +1,7 @@
|
|||
import Vue from "vue";
|
||||
import { Tabs, TabPane, Link, Checkbox } from "element-ui";
|
||||
|
||||
Vue.use(Tabs);
|
||||
Vue.use(TabPane);
|
||||
Vue.use(Link);
|
||||
Vue.use(Checkbox);
|
10
frontend/vue.config.js
Executable file
10
frontend/vue.config.js
Executable file
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
publicPath: process.env.VUE_APP_BASE_URL,
|
||||
configureWebpack: {
|
||||
resolve: {
|
||||
alias: {
|
||||
vue$: "vue/dist/vue.esm.js",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue