From b55159de3901122136ed364b8e04d678dde4ffca Mon Sep 17 00:00:00 2001
From: wally <18603454788@163.com>
Date: Tue, 26 Oct 2021 14:54:10 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.env.development | 2 +-
.eslintrc.js | 3 +
package-lock.json | 8 ++
package.json | 11 +--
src/App.vue | 37 ++++++++++
src/apis/index.js | 14 ++++
src/components/device-edit.vue | 19 +++++
src/components/search-bar.vue | 31 ++++++++
src/main.js | 4 +-
src/routers/index.js | 6 ++
src/store/device.js | 58 +++++++++++++++
src/store/index.js | 11 +++
src/store/user.js | 53 +++++++++++++
src/utils/axios.js | 21 +++++-
src/views/device-create.vue | 8 +-
src/views/device-list.vue | 131 ++++++++++++++++++++++++++++-----
vite.config.js | 31 ++++----
17 files changed, 396 insertions(+), 52 deletions(-)
create mode 100644 src/components/device-edit.vue
create mode 100644 src/components/search-bar.vue
create mode 100644 src/store/device.js
create mode 100644 src/store/index.js
create mode 100644 src/store/user.js
diff --git a/.env.development b/.env.development
index 0000523..7e1746a 100644
--- a/.env.development
+++ b/.env.development
@@ -1 +1 @@
-API_URL=http://localhost:4001
+VITE_API_URL=http://localhost:4001
diff --git a/.eslintrc.js b/.eslintrc.js
index 1773dfd..34af86d 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -13,6 +13,9 @@ module.exports = {
'import/no-unresolved': 0,
'import/extensions': 0,
'vue/html-self-closing': 'off',
+ 'no-unused-expressions': 'off',
+ 'vue/no-mutating-props': 'off',
+ 'vue/no-multiple-template-root': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-param-reassign': 'off',
diff --git a/package-lock.json b/package-lock.json
index 6c03e59..2414c72 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4443,6 +4443,14 @@
"@vue/devtools-api": "^6.0.0-beta.18"
}
},
+ "vuex": {
+ "version": "4.0.2",
+ "resolved": "https://registry.nlark.com/vuex/download/vuex-4.0.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fvuex%2Fdownload%2Fvuex-4.0.2.tgz",
+ "integrity": "sha1-+Jbb1b8qDpY/AMZ+m2EN50nMrMk=",
+ "requires": {
+ "@vue/devtools-api": "^6.0.0-beta.11"
+ }
+ },
"webpack-virtual-modules": {
"version": "0.4.3",
"resolved": "https://registry.nlark.com/webpack-virtual-modules/download/webpack-virtual-modules-0.4.3.tgz?cache=0&sync_timestamp=1620993523325&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fwebpack-virtual-modules%2Fdownload%2Fwebpack-virtual-modules-0.4.3.tgz",
diff --git a/package.json b/package.json
index 46b7865..321193c 100644
--- a/package.json
+++ b/package.json
@@ -16,12 +16,15 @@
"element-plus": "^1.1.0-beta.21",
"vue": "^3.2.16",
"vue-router": "^4.0.12",
- "windicss": "^3.1.9"
+ "vuex": "^4.0.2",
+ "windicss": "^3.1.9",
+ "@vitejs/plugin-vue": "^1.9.3",
+ "vite": "^2.6.4",
+ "vite-plugin-windicss": "^1.4.11"
},
"devDependencies": {
"@commitlint/cli": "^13.2.1",
"@commitlint/config-angular": "^13.2.0",
- "@vitejs/plugin-vue": "^1.9.3",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.32.0",
@@ -34,9 +37,7 @@
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"unplugin-vue-components": "^0.15.6",
- "vite": "^2.6.4",
- "vite-plugin-linter": "^1.0.1",
- "vite-plugin-windicss": "^1.4.11"
+ "vite-plugin-linter": "^1.0.1"
},
"browserslist": [
"Android >= 4",
diff --git a/src/App.vue b/src/App.vue
index 7f8c10c..78ed659 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,8 +1,45 @@
diff --git a/src/apis/index.js b/src/apis/index.js
index e69de29..e4aa176 100644
--- a/src/apis/index.js
+++ b/src/apis/index.js
@@ -0,0 +1,14 @@
+import http from 'utils/axios';
+
+const apiUrl = import.meta.env.VITE_API_URL;
+const users = `${apiUrl}/gateway/tall3/v3.0/users`;
+const corrosion = `${apiUrl}/gateway/corrosion`;
+
+// 根据userId 获取token
+export const getToken = userId => http.get(`${users}/userId`, { params: { userId } });
+
+// 获取设备列表
+export const getDevices = () => http.get(`${corrosion}/devices`);
+
+// 获取设备列表 完整信息
+export const getDevicesAll = () => http.get(`${corrosion}/devices/all`);
diff --git a/src/components/device-edit.vue b/src/components/device-edit.vue
new file mode 100644
index 0000000..e469345
--- /dev/null
+++ b/src/components/device-edit.vue
@@ -0,0 +1,19 @@
+
+
+ This is a message
+
+
+
+
+
+
+
diff --git a/src/components/search-bar.vue b/src/components/search-bar.vue
new file mode 100644
index 0000000..d615e19
--- /dev/null
+++ b/src/components/search-bar.vue
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+ 查询
+
+
+
+
+
diff --git a/src/main.js b/src/main.js
index 781f94b..0d446f6 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,9 +1,11 @@
import 'virtual:windi.css';
+import 'element-plus/dist/index.css';
import { createApp } from 'vue';
import App from './App.vue';
import router from './routers/index';
+import store from './store/index';
const app = createApp(App);
-app.use(router).mount('#app');
+app.use(router).use(store).mount('#app');
diff --git a/src/routers/index.js b/src/routers/index.js
index b52177f..3d25c40 100644
--- a/src/routers/index.js
+++ b/src/routers/index.js
@@ -21,6 +21,12 @@ export const routes = [
meta: { title: '设备添加' },
component: () => import('@/views/device-create.vue'),
},
+ {
+ path: '/devices',
+ name: 'devices',
+ meta: { title: '设备管理' },
+ component: () => import('@/views/device-list.vue'),
+ },
{
path: '/test',
name: 'test',
diff --git a/src/store/device.js b/src/store/device.js
new file mode 100644
index 0000000..bdd5466
--- /dev/null
+++ b/src/store/device.js
@@ -0,0 +1,58 @@
+import { getDevices, getDevicesAll } from 'apis/index';
+
+const user = {
+ namespaced: true,
+
+ state: {
+ devices: [],
+ devicesAll: null,
+ },
+
+ getters: {},
+
+ mutations: {
+ /**
+ * 设置devices数据
+ * @param {*} state
+ * @param {array} devices
+ */
+ setDevices(state, devices) {
+ state.devices = devices;
+ },
+
+ /**
+ * 设置devicesAll的数据
+ * @param {*} state
+ * @param {*} devices
+ */
+ setDevicesAll(state, devices) {
+ state.devicesAll = devices;
+ },
+ },
+
+ actions: {
+ // 获取设备列表(站点列表)
+ async getDevices({ commit }) {
+ try {
+ const data = await getDevices();
+ commit('setDevices', data || []);
+ return data;
+ } catch (error) {
+ throw new Error(error);
+ }
+ },
+
+ // 获取设备列表(站点列表) 完整信息
+ async getDevicesAll({ commit }) {
+ try {
+ const data = await getDevicesAll();
+ commit('setDevicesAll', data || null);
+ return data;
+ } catch (error) {
+ throw new Error(error);
+ }
+ },
+ },
+};
+
+export default user;
diff --git a/src/store/index.js b/src/store/index.js
new file mode 100644
index 0000000..3397c1d
--- /dev/null
+++ b/src/store/index.js
@@ -0,0 +1,11 @@
+import { createStore } from 'vuex';
+import device from './device';
+import user from './user';
+
+export default createStore({
+ modules: { user, device },
+ state: {},
+ getters: {},
+ mutations: {},
+ actions: {},
+});
diff --git a/src/store/user.js b/src/store/user.js
new file mode 100644
index 0000000..47689fe
--- /dev/null
+++ b/src/store/user.js
@@ -0,0 +1,53 @@
+import { getToken } from 'apis/index';
+
+export default {
+ namespaced: true,
+
+ state: { user: null },
+
+ getters: {
+ token({ user }) {
+ if (!user) return null;
+ return user.token;
+ },
+ userId({ user }) {
+ if (!user) return null;
+ return user.userId;
+ },
+ },
+
+ mutations: {
+ /**
+ * 设置state.user
+ * @param {*} state
+ * @param {object|null} user 用户信息
+ */
+ setUser(state, user) {
+ state.user = user;
+ if (user) {
+ localStorage.setItem('token', user.token);
+ localStorage.setItem('user', user);
+ } else {
+ localStorage.removeItem('token');
+ localStorage.removeItem('user');
+ }
+ },
+ },
+
+ actions: {
+ /**
+ * 根据userId获取token级user信息
+ * @param {*} param0
+ * @param {string} userId 用户id
+ */
+ async getTokenByUserId({ commit }, userId) {
+ try {
+ const data = await getToken(userId);
+ commit('setUser', data || null);
+ return data;
+ } catch (error) {
+ throw new Error(error);
+ }
+ },
+ },
+};
diff --git a/src/utils/axios.js b/src/utils/axios.js
index c7ce794..eec965d 100644
--- a/src/utils/axios.js
+++ b/src/utils/axios.js
@@ -1,7 +1,8 @@
import Axios from 'axios';
import { ElMessage } from 'element-plus';
+import store from 'store';
-const baseUrl = 'http://api.github.com';
+const baseUrl = '/gateway';
const instance = Axios.create({
baseUrl,
@@ -10,8 +11,13 @@ const instance = Axios.create({
// request
instance.interceptors.request.use(
- response => {
- return response;
+ config => {
+ // console.log(`store.getters['user/token']: `, store.getters['user/token']);
+ const token = store.getters['user/token'] || localStorage.getItem('token');
+ if (token) {
+ config.headers.Authorization = `Bearer ${token}`;
+ }
+ return config;
},
error => {
return Promise.reject(error);
@@ -21,7 +27,14 @@ instance.interceptors.request.use(
// response
instance.interceptors.response.use(
response => {
- return response;
+ if (response.status !== 200 || !response.data) {
+ return Promise.reject(response.statusText);
+ }
+ const { code, data, msg } = response.data;
+ if (code === 200) {
+ return data;
+ }
+ return Promise.reject(msg);
},
error => {
if (error.response && error.response.data) {
diff --git a/src/views/device-create.vue b/src/views/device-create.vue
index a1ccda1..79014bd 100644
--- a/src/views/device-create.vue
+++ b/src/views/device-create.vue
@@ -1,5 +1,5 @@
-
+
@@ -159,17 +159,17 @@ const data = reactive({
remark: '', // 备注
});
-const networkForm = ref(null); // form
+const deviceCreate = ref(null); // form
// 提交表单
const onSubmit = () => {
- networkForm.value.validate(valid => {
+ deviceCreate.value.validate(valid => {
console.log(valid, { ...data });
});
};
// 重置表单
const onReset = () => {
- networkForm.value.resetFields();
+ deviceCreate.value.resetFields();
};
diff --git a/src/views/device-list.vue b/src/views/device-list.vue
index a935d6b..97bef5d 100644
--- a/src/views/device-list.vue
+++ b/src/views/device-list.vue
@@ -1,26 +1,117 @@
-
-
-
-
-
-
-
-
-
-
- Create
- Cancel
-
-
+
+
+
+
+
+
+
+ 链路地址:{{ props.row.linkAddress }}
+ 探头编号:{{ props.row.probNo }}
+ 设备朝向:{{ props.row.deviceDirection }}
+ 试样:{{ props.row.simple }}
+ 安装位置:{{ props.row.installLocation }}
+ sim1:{{ props.row.sim1 }}
+ 与主站后台联调情况:{{ props.row.joint }}
+ 备注:{{ props.row.remark }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 删除
+
+
+
+ 编辑
+
+
+
+
+
+
+
+
+
diff --git a/vite.config.js b/vite.config.js
index f99c9e6..fac506d 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -1,28 +1,25 @@
-import Components from 'unplugin-vue-components/vite'
-import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
+import Components from 'unplugin-vue-components/vite';
+import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import WindiCSS from 'vite-plugin-windicss';
-import { defineConfig } from 'vite'
+import { defineConfig } from 'vite';
import path from 'path';
-import vue from '@vitejs/plugin-vue'
+import vue from '@vitejs/plugin-vue';
const resolve = dir => path.join(__dirname, dir);
// https://vitejs.dev/config/
export default defineConfig({
- plugins: [
- vue(),
- WindiCSS(),
- Components({
- resolvers: [ElementPlusResolver()],
- }),
- ],
+ plugins: [vue(), WindiCSS(), Components({ resolvers: [ElementPlusResolver()] })],
resolve: {
alias: {
'~': __dirname,
'@': resolve('src'),
- 'views': resolve('src/views'),
- 'components': resolve('src/components'),
- 'assets': resolve('src/assets'),
- }
- }
-})
+ views: resolve('src/views'),
+ components: resolve('src/components'),
+ assets: resolve('src/assets'),
+ utils: resolve('src/utils'),
+ store: resolve('src/store'),
+ apis: resolve('src/apis'),
+ },
+ },
+});