oss秘钥加密

master
yujialong 4 months ago
parent eb85cf815f
commit a3015b8f92
  1. 10
      package-lock.json
  2. 2
      package.json
  3. 32
      src/components/upload/config.js
  4. 34
      src/components/upload/index.vue
  5. 15
      src/components/upload/upload.js
  6. 1
      src/utils/api.js
  7. 24
      src/utils/http.js
  8. 31
      src/views/Home.vue

10
package-lock.json generated

@ -4607,6 +4607,11 @@
"randomfill": "^1.0.3" "randomfill": "^1.0.3"
} }
}, },
"crypto-js": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
},
"css": { "css": {
"version": "2.2.4", "version": "2.2.4",
"resolved": "https://registry.npm.taobao.org/css/download/css-2.2.4.tgz", "resolved": "https://registry.npm.taobao.org/css/download/css-2.2.4.tgz",
@ -8637,6 +8642,11 @@
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=",
"dev": true "dev": true
}, },
"jsencrypt": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.3.2.tgz",
"integrity": "sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A=="
},
"jsesc": { "jsesc": {
"version": "2.5.2", "version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",

@ -11,8 +11,10 @@
"ali-oss": "^6.18.1", "ali-oss": "^6.18.1",
"axios": "^0.19.2", "axios": "^0.19.2",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"crypto-js": "^4.2.0",
"element-ui": "^2.14.0", "element-ui": "^2.14.0",
"image-webpack-loader": "^8.1.0", "image-webpack-loader": "^8.1.0",
"jsencrypt": "^3.3.2",
"lib-flexible": "^0.3.2", "lib-flexible": "^0.3.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mavon-editor": "^2.10.4", "mavon-editor": "^2.10.4",

@ -1,15 +1,41 @@
/** /**
* 阿里云oss配置 * 阿里云oss配置
* */ * */
import { get } from '@/utils/http'
import api from '@/utils/api'
import CryptoJS from 'crypto-js'
import JSEncrypt from 'jsencrypt'
export default { const A = (key, encryptedData) => {
const keyHex = CryptoJS.enc.Base64.parse(key)
const decrypted = CryptoJS.AES.decrypt(encryptedData, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return decrypted.toString(CryptoJS.enc.Utf8)
}
const R = (encryptedKey, privateKey) => {
const decrypt = new JSEncrypt()
decrypt.setPrivateKey(privateKey)
const decryptedKey = decrypt.decrypt(encryptedKey)
return decryptedKey
}
export default async function () {
try {
const res = await get(api.encrypt)
const RE = A(R(res.encryptedKey, res.privateKey), res.encryptedData).split('/')
return {
// oss账号信息 // oss账号信息
config: { config: {
region: 'oss-cn-shenzhen', region: 'oss-cn-shenzhen',
accessKeyId: 'LTAI4FzqQHnk4rozqLZ8jCNj', accessKeyId: RE[0],
accessKeySecret: 'mveW7B1OyFoKUkHm8WsxmrjHmkJWHq', accessKeySecret: RE[1],
bucket: 'huoran' bucket: 'huoran'
}, },
// 上传成功url前置部分(成功回调没有返回url) // 上传成功url前置部分(成功回调没有返回url)
preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/' preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/'
}
} catch (e) { }
} }

@ -1,24 +1,12 @@
<template> <template>
<el-upload :disabled="uploading" <el-upload :disabled="uploading" :before-upload="beforeUpload" :on-remove="onRemove" :on-error="uploadError"
:before-upload="beforeUpload" :limit="limit" action="" :on-exceed="handleExceed" :show-file-list="showFiles" :file-list="fileList"
:on-remove="onRemove" :http-request="handleRequest" name="file">
:on-error="uploadError"
:limit="limit"
action=""
:on-exceed="handleExceed"
:show-file-list="showFiles"
:file-list="fileList"
:http-request="handleRequest"
name="file">
<slot name="trigger"> <slot name="trigger">
<el-button size="small" <el-button size="small" :loading="uploading">{{ uploading ? '正在上传' : '上传文件' }}</el-button>
:loading="uploading">{{ uploading ? '正在上传' : '上传文件' }}</el-button>
</slot> </slot>
<div slot="tip" <div slot="tip" class="el-upload__tip">
class="el-upload__tip"> <el-progress v-if="uploading" class="upload-progress" :stroke-width="3"
<el-progress v-if="uploading"
class="upload-progress"
:stroke-width="3"
:percentage="uploadProgress"></el-progress> :percentage="uploadProgress"></el-progress>
<slot name="tip"> <slot name="tip">
<p>支持扩展名.rar .zip .doc .docx .pdf .jpg...</p> <p>支持扩展名.rar .zip .doc .docx .pdf .jpg...</p>
@ -68,7 +56,8 @@ export default {
client: null, client: null,
uploading: false, uploading: false,
uploadProgress: 0, uploadProgress: 0,
showFiles: this.showFileList showFiles: this.showFileList,
Oss: {},
}; };
}, },
mounted () { mounted () {
@ -76,8 +65,9 @@ export default {
}, },
methods: { methods: {
// oss // oss
initOss () { async initOss () {
this.client = new OSS(OssConfig.config) this.Oss = await OssConfig()
this.client = new OSS(this.Oss.config)
}, },
// //
beforeUpload (file) { beforeUpload (file) {
@ -106,7 +96,7 @@ export default {
}); });
this.uploading = false this.uploading = false
const url = OssConfig.preUrl + name const url = this.Oss.preUrl + name
this.changeFileList && this.$emit('update:fileList', [ this.changeFileList && this.$emit('update:fileList', [
...this.fileList, ...this.fileList,
{ {

@ -5,14 +5,17 @@ import OssConfig from './config'
import Core from '@/utils/core' import Core from '@/utils/core'
let client = null let client = null
let Oss
// 初始化oss // 初始化oss
const initOss = () => { const initOss = async () => {
if (!client) client = new OSS(OssConfig.config) Oss = await OssConfig()
if (!client) client = new OSS(Oss.config)
} }
initOss()
export default { export default {
// 上传文件 // 上传文件
upload(file) { upload (file) {
initOss() initOss()
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
@ -21,7 +24,7 @@ export default {
resolve({ resolve({
format: Core.getFileExt(file.name), format: Core.getFileExt(file.name),
name: file.name, name: file.name,
url: OssConfig.preUrl + res.name, url: Oss.preUrl + res.name,
size: file.size, size: file.size,
}) })
} catch (error) { } catch (error) {
@ -30,8 +33,8 @@ export default {
}) })
}, },
// 删除文件(传完整url,不是没有https的name,因为很多接口没有存name,只存url,所以统一使用url) // 删除文件(传完整url,不是没有https的name,因为很多接口没有存name,只存url,所以统一使用url)
async del(url) { async del (url) {
initOss() initOss()
await client.delete(url.replace(OssConfig.preUrl, '')); await client.delete(url.replace(Oss.preUrl, ''));
} }
} }

@ -1,6 +1,7 @@
let host1 = 'http://121.37.12.51:8080'; let host1 = 'http://121.37.12.51:8080';
export default { export default {
encrypt: `/nakadai/data/encrypt`,
// 交易类(流程类) // 交易类(流程类)
getAllBusiness: `/judgment/judgment/lcRecord/getAllBusiness`, // 获取流程记录列表(树) getAllBusiness: `/judgment/judgment/lcRecord/getAllBusiness`, // 获取流程记录列表(树)
getProcess: `/judgment/judgment/lcRecord/getProcess`, // 获取流程记录列表(树) getProcess: `/judgment/judgment/lcRecord/getProcess`, // 获取流程记录列表(树)

@ -13,10 +13,10 @@ if (isKd) {
let url = location.host; let url = location.host;
// 职站中台接口切换 // 职站中台接口切换
if (url.includes('124.71.12.62')) { if (url.includes('124.71.12.62')) {
host = 'http://124.71.12.62:9000'; // 巢湖版 host = 'http://124.71.12.62:9000' // 巢湖版
} else if (dev) { } else if (dev) {
host = 'http://121.37.12.51'; host = 'http://121.37.12.51'
host = 'http://192.168.31.217:9000'; host = 'http://192.168.31.217:9000'
} }
} }
@ -53,6 +53,13 @@ service.interceptors.response.use(
const res = response.data; const res = response.data;
if (res.status == 200 || res.status == 10000 || res.status == 30001) { if (res.status == 200 || res.status == 10000 || res.status == 30001) {
return Promise.resolve(res).catch(e => { }); return Promise.resolve(res).catch(e => { });
} else if (res.code === 401) {
// 账号互踢
if (!logouted) {
Message.error(res.msg.includes('顶') ? '您的账号已在其他设备登录,您已被迫下线!' : '登录过期,请重新登录!')
setTimeout(logouts, 1500)
logouted = 1
}
} else if (!res.status) { } else if (!res.status) {
return Promise.resolve(res).catch(e => { }); return Promise.resolve(res).catch(e => { });
} else { } else {
@ -78,17 +85,6 @@ service.interceptors.response.use(
case 500: case 500:
Message.error("网络错误"); Message.error("网络错误");
break; break;
// 403 token过期
// 登录过期对用户进行提示
// 清除本地token和清空vuex中token对象
// 跳转登录页面
case 403:
Message.error("登录过期,请重新登录");
// 清除token
// store.commit('loginSuccess', null);
// 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面
setTimeout(logouts, 1500)
break;
// 404请求不存在 // 404请求不存在
case 404: case 404:
Message.error("网络请求不存在!"); Message.error("网络请求不存在!");

@ -43,7 +43,7 @@
<div class="pagination"> <div class="pagination">
<el-pagination background @current-change="handleCurrentChange" :current-page="pageNum" :page-size="10" <el-pagination background @current-change="handleCurrentChange" :current-page="pageNum" :page-size="10"
layout="total,prev, pager, next, jumper" :total="dataTotal"></el-pagination> layout="total,prev, pager, next, jumper" :total="total"></el-pagination>
</div> </div>
</el-card> </el-card>
@ -53,7 +53,7 @@
<el-input size="small" placeholder="请输入判分点名称" v-model="form.name"></el-input> <el-input size="small" placeholder="请输入判分点名称" v-model="form.name"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="checkpointId" label="复制至关卡"> <el-form-item prop="checkpointId" label="复制至关卡">
<el-select size="small" v-model="form.checkpointId" placeholder="请选择要复制至的关卡"> <el-select size="small" v-model="form.checkpointId" placeholder="请选择关卡">
<el-option v-for="(item, i) in checkpoints" :key="i" :label="item.customsPassName" <el-option v-for="(item, i) in checkpoints" :key="i" :label="item.customsPassName"
:value="item.checkpointId"> :value="item.checkpointId">
</el-option> </el-option>
@ -77,7 +77,7 @@ export default {
keyword: '', keyword: '',
searchTimer: null, searchTimer: null,
tableData: [], tableData: [],
dataTotal: 0, total: 0,
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
currentPage: 1, currentPage: 1,
@ -119,11 +119,6 @@ export default {
this.getCheckpoint() this.getCheckpoint()
}, },
methods: { methods: {
handleCurrentChange (val) { //
this.$refs.table.clearSelection()
this.pageNum = val;
this.initData();
},
initData () { // initData () { //
let params = { let params = {
name: this.keyword, name: this.keyword,
@ -143,17 +138,22 @@ export default {
} }
} }
}, },
getProcessClassData (params) { // //
this.$post(`${this.api.queryAllJudgmentPoint}`, params).then(res => { getProcessClassData (params) {
this.$post(this.api.queryAllJudgmentPoint, params).then(res => {
if (res.status === 200) { if (res.status === 200) {
this.tableData = res.message.records; this.tableData = res.message.records;
this.dataTotal = res.message.total; this.total = res.message.total;
} else { } else {
this.$message.error(res.message); this.$message.error(res.message);
} }
}).catch(err => { }); }).catch(err => { });
}, },
// handleCurrentChange (val) { //
this.$refs.table.clearSelection()
this.pageNum = val;
this.initData();
},
handleSelectionChange (val) { handleSelectionChange (val) {
this.multipleSelection = val; this.multipleSelection = val;
}, },
@ -210,7 +210,7 @@ export default {
getProgrammingClassData (params) { // getProgrammingClassData (params) { //
this.$post(this.api.getBcJudgmentPoint, params).then(res => { this.$post(this.api.getBcJudgmentPoint, params).then(res => {
this.tableData = res.message.records; this.tableData = res.message.records;
this.dataTotal = res.message.total; this.total = res.message.total;
}).catch(err => { }).catch(err => {
}); });
}, },
@ -218,7 +218,7 @@ export default {
const { query } = this.$route const { query } = this.$route
this.$post(`${this.api.QueryPointOfJudgement}?systemId=${query.systemId}&userId=${query.userId}&pageNum=${query.pageNum}&pageSize=${query.pageSize}&queryName=${query.queryName}&userIdList=${query.userIdList}`).then(res => { this.$post(`${this.api.QueryPointOfJudgement}?systemId=${query.systemId}&userId=${query.userId}&pageNum=${query.pageNum}&pageSize=${query.pageSize}&queryName=${query.queryName}&userIdList=${query.userIdList}`).then(res => {
this.tableData = res.message.records; this.tableData = res.message.records;
this.dataTotal = res.message.total; this.total = res.message.total;
}).catch(err => { }); }).catch(err => { });
}, },
// //
@ -237,7 +237,7 @@ export default {
this.copyVisible = true this.copyVisible = true
} else { } else {
// //
this.$confirm('当前未选中任何数据,是否需要复制当前列表的全部数据?', '提示', { this.$confirm(`当前未选中任何数据,是否需要复制当前列表的全部${this.total}条数据?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
@ -295,6 +295,7 @@ export default {
this.initData() this.initData()
this.$message.success('复制成功!') this.$message.success('复制成功!')
this.copyVisible = false this.copyVisible = false
this.multipleSelection = []
} catch (e) { } catch (e) {
this.copying = false this.copying = false
} }

Loading…
Cancel
Save