Browse Source

修复新标签页打开失效的问题

yanglzh 2 years ago
parent
commit
3b7467fb02

+ 1 - 0
src/api/device/index.ts

@@ -42,6 +42,7 @@ export default {
   },
   tabDeviceFucntion: {
     getList: (params: object) => get('/product/tsl/function/all', params),
+    do: (data: object) => post('/product/function/do', data),
   },
 
   model: {

+ 2 - 2
src/router/backEnd.ts

@@ -1,4 +1,4 @@
-import { store } from '/@/store/index.ts';
+import { store } from '/@/store/index';
 import { Session } from '/@/utils/storage';
 import { NextLoading } from '/@/utils/loading';
 import { setAddRoute, setFilterMenuAndCacheTagsViewRoutes } from '/@/router/index';
@@ -28,7 +28,7 @@ export async function initBackEndControlRoutes() {
 	// 界面 loading 动画开始执行
 	if (window.nextLoading === undefined) NextLoading.start();
 	// 无 token 停止执行下一步
-	if (!Session.get('token')) return false;
+	if (!localStorage.token) return false;
 	// 触发初始化用户信息
 	store.dispatch('userInfos/setUserInfos');
 	// store.dispatch('userInfos/setPermissions');

+ 1 - 2
src/router/frontEnd.ts

@@ -1,5 +1,4 @@
 import { store } from '/@/store/index';
-import { Session } from '/@/utils/storage';
 import { NextLoading } from '/@/utils/loading';
 import { setAddRoute, setFilterMenuAndCacheTagsViewRoutes } from '/@/router/index';
 
@@ -14,7 +13,7 @@ export async function initFrontEndControlRoutes() {
 	// 界面 loading 动画开始执行
 	if (window.nextLoading === undefined) NextLoading.start();
 	// 无 token 停止执行下一步
-	if (!Session.get('token')) return false;
+	if (!localStorage.token) return false;
 	// 触发初始化用户信息
 	store.dispatch('userInfos/setUserInfos');
 	store.dispatch('userInfos/setPermissions');

+ 2 - 2
src/router/index.ts

@@ -1,7 +1,7 @@
 import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
-import { store } from '/@/store/index.ts';
+import { store } from '/@/store/index';
 import { Session } from '/@/utils/storage';
 import { NextLoading } from '/@/utils/loading';
 import { staticRoutes, dynamicRoutes } from '/@/router/route';
@@ -219,7 +219,7 @@ router.beforeEach(async (to, from, next) => {
 
 
 	// 正常流程
-	const token = Session.get('token');
+	const token = localStorage.token;
 	if (to.path === '/login' && !token) {
 		next();
 		NProgress.done();

+ 2 - 2
src/utils/request.ts

@@ -14,8 +14,8 @@ const service = axios.create({
 service.interceptors.request.use(
 	(config) => {
 		// 在发送请求之前做些什么 token
-		if (Session.get('token')) {
-			(<any>config.headers).common['Authorization'] = `Bearer ${Session.get('token')}`;
+		if (localStorage.token) {
+			(<any>config.headers).common['Authorization'] = `Bearer ${localStorage.token}`;
 		}
 		return config;
 	},

+ 2 - 2
src/utils/request_modbus.ts

@@ -14,8 +14,8 @@ const service = axios.create({
 service.interceptors.request.use(
 	(config) => {
 		// 在发送请求之前做些什么 token
-		if (Session.get('token')) {
-			(<any>config.headers).common['Authorization'] = `Bearer ${Session.get('token')}`;
+		if (localStorage.token) {
+			(<any>config.headers).common['Authorization'] = `Bearer ${localStorage.token}`;
 		}
 		return config;
 	},

+ 0 - 4
src/views/iot/configuration/list/index.vue

@@ -44,7 +44,6 @@
 
 <script lang="ts" setup>
 import api from '/@/api/configuration';
-import { Session } from '/@/utils/storage';
 import { useSearch } from '/@/hooks/useCommon';
 import { ElMessageBox, ElMessage } from 'element-plus';
 import getOrigin from '/@/utils/origin'
@@ -58,15 +57,12 @@ const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, 'd
 getList();
 
 function getTokenUrl(url: string) {
-  localStorage.setItem('token', Session.get('token'));
   const tokenUrl = import.meta.env.VITE_TOPO_URL
-  // const tokenUrl = import.meta.env.VITE_TOPO_URL + '?token=' + encodeURIComponent(Session.get('token'))
   return getOrigin(tokenUrl + url)
 };
 
 const view = (row: any) => {
   const url = getTokenUrl('#/show/' + row.id);
-  // const url = import.meta.env.VITE_TOPO_URL + '?token=' + encodeURIComponent(Session.get('token')) + `&bgColor=FF9900` + '#/show/' + row.id;
   window.open(url);
 };
 

+ 0 - 5
src/views/iot/configuration/screen/index.vue

@@ -44,7 +44,6 @@ import { ref } from 'vue';
 import api from '/@/api/screen';
 import { ElMessageBox, ElMessage } from 'element-plus';
 import { useSearch } from '/@/hooks/useCommon';
-import { Session } from '/@/utils/storage';
 import EditForm from './edit.vue';
 
 const editFormRef = ref();
@@ -91,16 +90,12 @@ const add = async () => {
 };
 
 const edit = async (row: any) => {
-  localStorage.setItem('token', Session.get('token'));
   const url = import.meta.env.VITE_SCREEN_URL + '#/chart/home/' + row.id;
-  // const url = import.meta.env.VITE_SCREEN_URL + '?token=' + encodeURIComponent(Session.get('token')) + '#/chart/home/' + row.id;
   window.open(url);
 };
 
 const preview = async (row: any) => {
-  localStorage.setItem('token', Session.get('token'));
   const url = import.meta.env.VITE_SCREEN_URL + '#/chart/preview/' + row.id;
-  // const url = import.meta.env.VITE_SCREEN_URL + '?token=' + encodeURIComponent(Session.get('token')) + '#/chart/preview/' + row.id;
   window.open(url);
 };
 

+ 3 - 2
src/views/iot/device/instance/component/function.vue

@@ -27,6 +27,7 @@
 
 <script setup lang="ts">
 import { ref } from 'vue'
+import { ElMessage } from 'element-plus';
 import api from '/@/api/device'
 
 const props = defineProps({
@@ -43,13 +44,13 @@ interface IListItem {
 const list = ref<IListItem[]>([])
 
 api.tabDeviceFucntion.getList({ key: props.funKey }).then((res: IListItem[]) => {
-	console.log(res)
-	console.log(res[0])
 	res.forEach((item) => (item.result = ''))
 	list.value = res
 })
 
 function run(row: IListItem) {
+  const notValid = row.inputs.some(item => !item.value)
+  if(notValid) return ElMessage.info('请输入完整参数')
   row.result = JSON.stringify(row, null, 2)
  }
 

+ 1 - 3
src/views/iot/rule-engine/index.vue

@@ -49,7 +49,6 @@ import { ref } from 'vue';
 import api from '/@/api/rule';
 import { ElMessageBox, ElMessage } from 'element-plus';
 import { useSearch } from '/@/hooks/useCommon';
-import { Session } from '/@/utils/storage';
 import EditForm from './edit.vue';
 import axios from 'axios';
 
@@ -104,8 +103,7 @@ const setStatus = async (row: any, status: number) => {
 };
 
 const edit = async (row: any) => {
-	localStorage.setItem('auth-tokens', `{"access_token":"${Session.get('token')}"}`);
-	// const url = window.location.protocol + '//' + window.location.hostname + ':1880/rule-engine?access_token=' + Session.get('token') + '#flow/' + row.flowId;
+	localStorage.setItem('auth-tokens', `{"access_token":"${localStorage.token}"}`);
 	const url = '/rule-engine/#flow/' + row.flowId;
 	window.open(url);
 };

+ 1 - 3
src/views/iot/rule-engine/send.vue

@@ -49,7 +49,6 @@ import { ref } from 'vue';
 import api from '/@/api/rule';
 import { ElMessageBox, ElMessage } from 'element-plus';
 import { useSearch } from '/@/hooks/useCommon';
-import { Session } from '/@/utils/storage';
 import EditForm from './edit.vue';
 import axios from 'axios';
 
@@ -102,8 +101,7 @@ const setStatus = async (row: any, status: number) => {
 };
 
 const edit = async (row: any) => {
-  localStorage.setItem('auth-tokens', `{"access_token":"${Session.get('token')}"}`);
-  // const url = window.location.protocol + '//' + window.location.hostname + ':1880/rule-engine?access_token=' + Session.get('token') + '#flow/' + row.flowId;
+  localStorage.setItem('auth-tokens', `{"access_token":"${localStorage.token}"}`);
   const url = '/rule-engine/#flow/' + row.flowId;
   window.open(url);
 };

+ 0 - 1
src/views/login/component/account.vue

@@ -130,7 +130,6 @@ export default defineComponent({
 								const userInfos = res.userInfo;
 								userInfos.avatar = proxy.getUpFileUrl(userInfos.avatar);
 								// 存储 token 到浏览器缓存
-								Session.set('token', res.token);
 								localStorage.setItem('token', res.token);
 								// 存储用户信息到浏览器缓存
 								Session.set('userInfo', userInfos);