From b336539c1bb80ee5ff78e64151445e58c5553735 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 28 Feb 2024 08:51:15 +0800 Subject: [PATCH] first commit --- .gitignore | 24 ++++++++ README.md | 24 ++++++++ babel.config.js | 12 ++++ jsconfig.json | 19 +++++++ package.json | 52 ++++++++++++++++++ postcss.config.js | 10 ++++ public/favicon.ico | Bin 0 -> 4286 bytes public/index.html | 17 ++++++ src/App.vue | 81 +++++++++++++++++++++++++++ src/axios.js | 128 +++++++++++++++++++++++++++++++++++++++++++ src/main.js | 27 +++++++++ src/router/index.js | 66 ++++++++++++++++++++++ src/views/Detail.vue | 70 +++++++++++++++++++++++ src/views/Home.vue | 120 ++++++++++++++++++++++++++++++++++++++++ src/views/Login.vue | 89 ++++++++++++++++++++++++++++++ vue.config.js | 13 +++++ 16 files changed, 752 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 babel.config.js create mode 100644 jsconfig.json create mode 100644 package.json create mode 100644 postcss.config.js create mode 100644 public/favicon.ico create mode 100644 public/index.html create mode 100644 src/App.vue create mode 100644 src/axios.js create mode 100644 src/main.js create mode 100644 src/router/index.js create mode 100644 src/views/Detail.vue create mode 100644 src/views/Home.vue create mode 100644 src/views/Login.vue create mode 100644 vue.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51b3106 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.DS_Store +node_modules +/dist +package-lock.json + + +# 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? diff --git a/README.md b/README.md new file mode 100644 index 0000000..e8c956f --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# shop-tour-front + +## 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/). diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..ddd6de2 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,12 @@ +module.exports = { + // vuecli3 不需要配置transform-vue-jsx + presets: [ + [ + '@vue/app', + { + useBuiltIns: 'entry', + polyfills: ['es6.promise', 'es6.symbol'] + } + ] + ] +} \ No newline at end of file diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..4aafc5f --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "esnext", + "baseUrl": "./", + "moduleResolution": "node", + "paths": { + "@/*": [ + "src/*" + ] + }, + "lib": [ + "esnext", + "dom", + "dom.iterable", + "scripthost" + ] + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..48bd1a5 --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "shop-tour-front", + "version": "0.1.0", + "private": true, + "scripts": { + "serve": "vue-cli-service serve", + "build": "vue-cli-service build", + "lint": "vue-cli-service lint" + }, + "dependencies": { + "@babel/polyfill": "^7.12.1", + "amfe-flexible": "^2.2.1", + "ant-design-vue": "^1.7.8", + "axios": "^1.1.2", + "core-js": "^3.8.3", + "es6-promise": "^4.2.8", + "vue": "^2.6.14", + "vue-infinite-scroll": "^2.0.2", + "vue-router": "^3.5.2" + }, + "devDependencies": { + "@babel/core": "^7.12.16", + "@babel/eslint-parser": "^7.12.16", + "@vue/cli-plugin-babel": "~5.0.0", + "@vue/cli-plugin-eslint": "~5.0.0", + "@vue/cli-service": "~5.0.0", + "babel-plugin-import": "^1.13.5", + "eslint": "^7.32.0", + "eslint-plugin-vue": "^8.0.3", + "postcss-pxtorem": "^6.0.0", + "vue-template-compiler": "^2.6.14" + }, + "eslintConfig": { + "root": true, + "env": { + "node": true + }, + "extends": [ + "plugin:vue/essential", + "eslint:recommended" + ], + "parserOptions": { + "parser": "@babel/eslint-parser" + }, + "rules": {} + }, + "browserslist": [ + "> 1%", + "last 2 versions", + "not dead" + ] +} diff --git a/postcss.config.js b/postcss.config.js new file mode 100644 index 0000000..4737635 --- /dev/null +++ b/postcss.config.js @@ -0,0 +1,10 @@ +module.exports = { + plugins: { + autoprefixer: {}, + // flexible配置 + // "postcss-pxtorem": { + // "rootValue": 40, // 设计稿宽度的1/10 + // "propList": ["*"] // 需要做转化处理的属性,如`hight`、`width`、`margin`等,`*`表示全部 + // } + } +} \ No newline at end of file diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..df36fcfb72584e00488330b560ebcf34a41c64c2 GIT binary patch literal 4286 zcmds*O-Phc6o&64GDVCEQHxsW(p4>LW*W<827=Unuo8sGpRux(DN@jWP-e29Wl%wj zY84_aq9}^Am9-cWTD5GGEo#+5Fi2wX_P*bo+xO!)p*7B;iKlbFd(U~_d(U?#hLj56 zPhFkj-|A6~Qk#@g^#D^U0XT1cu=c-vu1+SElX9NR;kzAUV(q0|dl0|%h|dI$%VICy zJnu2^L*Te9JrJMGh%-P79CL0}dq92RGU6gI{v2~|)p}sG5x0U*z<8U;Ij*hB9z?ei z@g6Xq-pDoPl=MANPiR7%172VA%r)kevtV-_5H*QJKFmd;8yA$98zCxBZYXTNZ#QFk2(TX0;Y2dt&WitL#$96|gJY=3xX zpCoi|YNzgO3R`f@IiEeSmKrPSf#h#Qd<$%Ej^RIeeYfsxhPMOG`S`Pz8q``=511zm zAm)MX5AV^5xIWPyEu7u>qYs?pn$I4nL9J!=K=SGlKLXpE<5x+2cDTXq?brj?n6sp= zphe9;_JHf40^9~}9i08r{XM$7HB!`{Ys~TK0kx<}ZQng`UPvH*11|q7&l9?@FQz;8 zx!=3<4seY*%=OlbCbcae?5^V_}*K>Uo6ZWV8mTyE^B=DKy7-sdLYkR5Z?paTgK-zyIkKjIcpyO z{+uIt&YSa_$QnN_@t~L014dyK(fOOo+W*MIxbA6Ndgr=Y!f#Tokqv}n<7-9qfHkc3 z=>a|HWqcX8fzQCT=dqVbogRq!-S>H%yA{1w#2Pn;=e>JiEj7Hl;zdt-2f+j2%DeVD zsW0Ab)ZK@0cIW%W7z}H{&~yGhn~D;aiP4=;m-HCo`BEI+Kd6 z={Xwx{TKxD#iCLfl2vQGDitKtN>z|-AdCN|$jTFDg0m3O`WLD4_s#$S literal 0 HcmV?d00001 diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..ca21819 --- /dev/null +++ b/public/index.html @@ -0,0 +1,17 @@ + + + + + + + + 电力工程现行法律法规标准索引 + + + +
+ + + diff --git a/src/App.vue b/src/App.vue new file mode 100644 index 0000000..8bec0e0 --- /dev/null +++ b/src/App.vue @@ -0,0 +1,81 @@ + + + + + diff --git a/src/axios.js b/src/axios.js new file mode 100644 index 0000000..58066f1 --- /dev/null +++ b/src/axios.js @@ -0,0 +1,128 @@ +import axios from 'axios' + +// 请求url +axios.defaults.baseURL = 'http://47.92.229.12:8888' +// axios.defaults.baseURL = 'http://visitor.emaylearningsh.com/api' +axios.defaults.timeout = 10000 + +let cancel, promiseArr = {} +const CancelToken = axios.CancelToken; +// POST传参序列化 +axios.interceptors.request.use((config) => { + // 发起请求时,取消掉当前正在进行的相同请求 + if (promiseArr[config.url]) { + promiseArr[config.url]('操作取消') + promiseArr[config.url] = cancel + } else { + promiseArr[config.url] = cancel + } + // token + const token = JSON.parse(sessionStorage.getItem('token')) + if (token) { + config.headers.Authorization = token; + } + return config; +}, (error) => { + return Promise.reject(error); +}); + +//返回状态判断 +axios.interceptors.response.use(function (response) { + // 对响应数据做点什么 + if (response.data.retcode === 201) { + sessionStorage.removeItem('token'); + router.replace({ + path: 'login', + query: { redirect: router.currentRoute.fullPath } //登录成功后跳入浏览的当前页面 + }) + } + return response; +}, function (error) { + // 对响应错误做点什么 + if (error && error.response) { + switch (error.response.status) { + case 400: + error.message = '错误请求' + break; + case 401: + // 这里写清除token的代码 + sessionStorage.removeItem('token'); + router.replace({ + path: 'login', + query: { redirect: router.currentRoute.fullPath } //登录成功后跳入浏览的当前页面 + }) + error.message = '未授权,请重新登录' + break; + case 403: + error.message = '拒绝访问' + break; + case 404: + error.message = '请求错误,未找到该资源' + break; + case 405: + error.message = '请求方法未允许' + break; + case 408: + error.message = '请求超时' + break; + case 500: + error.message = '服务器端出错' + break; + case 501: + error.message = '网络未实现' + break; + case 502: + error.message = '网络错误' + break; + case 503: + error.message = '服务不可用' + break; + case 504: + error.message = '网络超时' + break; + case 505: + error.message = 'http版本不支持该请求' + break; + default: + error.message = `连接错误${error.response.status}` + } + } else { + error.message = "连接到服务器失败" + } + //Message.error({message: error.message}); + return Promise.resolve(error.response) +}); + +//export default axios; +export default { + //get请求 + get(url, param) { + return new Promise((resolve) => { + axios({ + method: 'get', + url, + params: param, + cancelToken: new CancelToken(c => { + cancel = c + }) + }).then(res => { + resolve(res) + }) + }) + }, + //post请求 + post(url, param) { + return new Promise((resolve) => { + axios({ + method: 'post', + url, + data: param, + cancelToken: new CancelToken(c => { + cancel = c + }) + }).then(res => { + resolve(res) + }) + }) + } +} \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..2120dd6 --- /dev/null +++ b/src/main.js @@ -0,0 +1,27 @@ +import '@babel/polyfill' +import Vue from 'vue' +import router from './router' +import App from './App.vue' +import axios from "./axios" +import 'ant-design-vue/dist/antd.css'; +import { Input, List, Spin, message, Button, Form } from 'ant-design-vue'; + +Vue.use(Input); +Vue.use(Button); +Vue.use(List); +Vue.use(Spin); +Vue.use(Form) + +import 'amfe-flexible' +Vue.config.productionTip = false + +Vue.prototype.$https = axios; +Vue.prototype.$message = message; +Vue.prototype.$form = Form; + +new Vue({ + el: '#app', + router, + // 注册仓库: + render: h => h(App), +}).$mount('#app') diff --git a/src/router/index.js b/src/router/index.js new file mode 100644 index 0000000..e446fce --- /dev/null +++ b/src/router/index.js @@ -0,0 +1,66 @@ +import Vue from 'vue' +import Router from 'vue-router' +import Home from '@/views/Home' +import Login from '@/views/Login' +import Detail from '@/views/Detail' + +Vue.use(Router) + +const routes = [ + { + path: '/login', + name: 'login', + component: Login, + meta: { + title: '登录', + } + }, + { + path: '/', + name: 'MyHome', + component: Home, + meta: { + title: '电力工程现行法律法规标准索引', + requireAuth: true, + } + }, + { + path: '/detail', + name: 'MyDetail', + component: Detail, + meta: { + title: '电力工程现行法律法规标准索引', + requireAuth: true, + } + }, +]; + +const router = new Router({ + routes +}); + +router.beforeEach((to, from, next) => { + if (to.meta.title) { + document.title = to.meta.title + } + if (to.meta.requireAuth) { // 如果路由项需要权限校验 + /* + 从Vuex拿出token码,说明已登陆 + (前端的token可伪造,所以这并不是完全靠谱,后面继续说) + */ + if (JSON.parse(sessionStorage.getItem('token'))) { + next() // 正常跳转页面 + } else { + let query = { returnUrl: to.path }; + next({ + path: '/login', + query: query + /* 将跳转的路由地址作为参数带给登陆页,登录成功后跳转回该页面 */ + }) + } + } else { // 如果不需要权限校验,直接进入路由页面 + next(); + } +}) + +export default router; diff --git a/src/views/Detail.vue b/src/views/Detail.vue new file mode 100644 index 0000000..8b40606 --- /dev/null +++ b/src/views/Detail.vue @@ -0,0 +1,70 @@ + + + + + diff --git a/src/views/Home.vue b/src/views/Home.vue new file mode 100644 index 0000000..8b2c6b7 --- /dev/null +++ b/src/views/Home.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/src/views/Login.vue b/src/views/Login.vue new file mode 100644 index 0000000..73a47c2 --- /dev/null +++ b/src/views/Login.vue @@ -0,0 +1,89 @@ + + + + + \ No newline at end of file diff --git a/vue.config.js b/vue.config.js new file mode 100644 index 0000000..3ffd8ad --- /dev/null +++ b/vue.config.js @@ -0,0 +1,13 @@ +// const { defineConfig } = require('@vue/cli-service') +// module.exports = defineConfig({ +// transpileDependencies: true +// }) +module.exports = { + publicPath: '/', + // 关闭打包生成map文件 + productionSourceMap: false, + // 关闭ESLINT校验工具 + lintOnSave: false, + css: {}, + configureWebpack: config => { config.entry.app = ["@babel/polyfill", "./src/main.js"]; }, +} \ No newline at end of file