diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fa713d8..5384447 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,8 +1,93 @@ - { - "keyToString": { - "settings.editor.selected.configurable": "preferences.editor" - } + + + + + + + + + + + + + + { + "associatedIndex": 1 } + + + + + + + + + + + + + + + 1735183249700 + + + + + + + + + + + + \ No newline at end of file diff --git a/cellsysSystem.js b/cellsysSystem.js index a28730b..356290b 100644 --- a/cellsysSystem.js +++ b/cellsysSystem.js @@ -13,7 +13,8 @@ import CellsysMemberType from './cellsysMemberType'; class CellsysSystem { constructor(params) {} - static token = null; + static token = null; //当前token + static adminToken = null; //管理员token static hostname = null; //在边缘工作站上查询设备列表 @@ -26,6 +27,7 @@ class CellsysSystem { queryTask .execute(query) .then((orgList) => { + debugger; resolve(orgList); }) .catch((err) => { diff --git a/package-lock.json b/package-lock.json index f7bb662..526a6ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,17 @@ { "name": "@airkoon/cellsys", - "version": "1.15.1", + "version": "1.15.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@airkoon/cellsys", - "version": "1.15.1", + "version": "1.15.3", "license": "ISC", "dependencies": { - "canvg": "~3.0.7" + "axios": "~1.4.0", + "canvg": "~3.0.7", + "dayjs": "~1.10.6" } }, "node_modules/@babel/runtime": { @@ -33,6 +35,21 @@ "resolved": "https://registry.npmmirror.com/@types/raf/-/raf-3.4.3.tgz", "integrity": "sha512-c4YAvMedbPZ5tEyxzQdMoOhhJ4RD3rngZIdwC2/qDN3d7JpEhB6fiBRKVY1lg5B7Wk+uPBjn5f39j1/2MY1oOw==" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.4.0", + "resolved": "https://registry.npmmirror.com/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/canvg": { "version": "3.0.10", "resolved": "https://registry.npmmirror.com/canvg/-/canvg-3.0.10.tgz", @@ -51,6 +68,17 @@ "node": ">=10.0.0" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/core-js": { "version": "3.38.0", "resolved": "https://registry.npmmirror.com/core-js/-/core-js-3.38.0.tgz", @@ -61,11 +89,80 @@ "url": "https://opencollective.com/core-js" } }, + "node_modules/dayjs": { + "version": "1.10.8", + "resolved": "https://registry.npmmirror.com/dayjs/-/dayjs-1.10.8.tgz", + "integrity": "sha512-wbNwDfBHHur9UOzNUjeKUOJ0fCb0a52Wx0xInmQ7Y8FstyajiV1NmK1e00cxsr9YrE9r7yAChE0VvpuY5Rnlow==" + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/performance-now": { "version": "2.1.0", "resolved": "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/raf": { "version": "3.4.1", "resolved": "https://registry.npmmirror.com/raf/-/raf-3.4.1.tgz", @@ -125,6 +222,21 @@ "resolved": "https://registry.npmmirror.com/@types/raf/-/raf-3.4.3.tgz", "integrity": "sha512-c4YAvMedbPZ5tEyxzQdMoOhhJ4RD3rngZIdwC2/qDN3d7JpEhB6fiBRKVY1lg5B7Wk+uPBjn5f39j1/2MY1oOw==" }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "axios": { + "version": "1.4.0", + "resolved": "https://registry.npmmirror.com/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "canvg": { "version": "3.0.10", "resolved": "https://registry.npmmirror.com/canvg/-/canvg-3.0.10.tgz", @@ -140,16 +252,67 @@ "svg-pathdata": "^6.0.3" } }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, "core-js": { "version": "3.38.0", "resolved": "https://registry.npmmirror.com/core-js/-/core-js-3.38.0.tgz", "integrity": "sha512-XPpwqEodRljce9KswjZShh95qJ1URisBeKCjUdq27YdenkslVe7OO0ZJhlYXAChW7OhXaRLl8AAba7IBfoIHug==" }, + "dayjs": { + "version": "1.10.8", + "resolved": "https://registry.npmmirror.com/dayjs/-/dayjs-1.10.8.tgz", + "integrity": "sha512-wbNwDfBHHur9UOzNUjeKUOJ0fCb0a52Wx0xInmQ7Y8FstyajiV1NmK1e00cxsr9YrE9r7yAChE0VvpuY5Rnlow==" + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, + "follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==" + }, + "form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "raf": { "version": "3.4.1", "resolved": "https://registry.npmmirror.com/raf/-/raf-3.4.1.tgz", diff --git a/package.json b/package.json index 6227c35..b8acf29 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "author": "gui", "license": "ISC", "dependencies": { - "canvg": "~3.0.7" + "canvg": "~3.0.7", + "axios": "~1.4.0", + "dayjs": "~1.10.6" } } diff --git a/utils/axios.js b/utils/axios.js index 959d2f8..88cb528 100644 --- a/utils/axios.js +++ b/utils/axios.js @@ -1,4 +1,6 @@ import axios from 'axios'; +import { AdminQueryType } from '../cellsysUtil'; +import cellsysSystem from '../cellsysSystem'; const service = axios.create({ baseURL: '/api', //api 的 base_url,根据开发生产环境配置文件配置 @@ -10,6 +12,47 @@ const service = axios.create({ responseType: 'json', }); +service.interceptors.request.use( + (config) => { + let url = config.url; + let token = cellsysSystem.token; + if (AdminQueryType.indexOf(url) !== -1) { + //这里应该再加一层用户身份判断才是正确的写法 + token = cellsysSystem.adminToken; + } + if (token && !config.headers['Authorization']) { + config.headers['Authorization'] = 'Bearer ' + token; + } + return config; + }, + (error) => { + console.error(error); + return Promise.reject(error); + }, +); + +service.interceptors.response.use( + (response) => { + let data; + if (response.data === undefined || response.data == null) { + switch (response.status) { + case 201: + data = { code: 201 }; + break; + default: + data = { code: 200 }; + break; + } + } else { + data = response.data; + } + return data; + }, + (err) => { + return Promise.reject(err); + }, +); + const post = (url, data, config) => { return service.post(url, data, config); };