oss秘钥加密

master
yujialong 4 months ago
parent eb85cf815f
commit a3015b8f92
  1. 10
      package-lock.json
  2. 2
      package.json
  3. 46
      src/components/upload/config.js
  4. 36
      src/components/upload/index.vue
  5. 49
      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"
}
},
"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": {
"version": "2.2.4",
"resolved": "https://registry.npm.taobao.org/css/download/css-2.2.4.tgz",
@ -8637,6 +8642,11 @@
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=",
"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": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",

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

@ -1,15 +1,41 @@
/**
* 阿里云oss配置
* */
import { get } from '@/utils/http'
import api from '@/utils/api'
import CryptoJS from 'crypto-js'
import JSEncrypt from 'jsencrypt'
export default {
// oss账号信息
config: {
region: 'oss-cn-shenzhen',
accessKeyId: 'LTAI4FzqQHnk4rozqLZ8jCNj',
accessKeySecret: 'mveW7B1OyFoKUkHm8WsxmrjHmkJWHq',
bucket: 'huoran'
},
// 上传成功url前置部分(成功回调没有返回url)
preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/'
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账号信息
config: {
region: 'oss-cn-shenzhen',
accessKeyId: RE[0],
accessKeySecret: RE[1],
bucket: 'huoran'
},
// 上传成功url前置部分(成功回调没有返回url)
preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/'
}
} catch (e) { }
}

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

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

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

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

@ -43,7 +43,7 @@
<div class="pagination">
<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>
</el-card>
@ -53,7 +53,7 @@
<el-input size="small" placeholder="请输入判分点名称" v-model="form.name"></el-input>
</el-form-item>
<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"
:value="item.checkpointId">
</el-option>
@ -77,7 +77,7 @@ export default {
keyword: '',
searchTimer: null,
tableData: [],
dataTotal: 0,
total: 0,
pageNum: 1,
pageSize: 10,
currentPage: 1,
@ -119,11 +119,6 @@ export default {
this.getCheckpoint()
},
methods: {
handleCurrentChange (val) { //
this.$refs.table.clearSelection()
this.pageNum = val;
this.initData();
},
initData () { //
let params = {
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) {
this.tableData = res.message.records;
this.dataTotal = res.message.total;
this.total = res.message.total;
} else {
this.$message.error(res.message);
}
}).catch(err => { });
},
//
handleCurrentChange (val) { //
this.$refs.table.clearSelection()
this.pageNum = val;
this.initData();
},
handleSelectionChange (val) {
this.multipleSelection = val;
},
@ -210,7 +210,7 @@ export default {
getProgrammingClassData (params) { //
this.$post(this.api.getBcJudgmentPoint, params).then(res => {
this.tableData = res.message.records;
this.dataTotal = res.message.total;
this.total = res.message.total;
}).catch(err => {
});
},
@ -218,7 +218,7 @@ export default {
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.tableData = res.message.records;
this.dataTotal = res.message.total;
this.total = res.message.total;
}).catch(err => { });
},
//
@ -237,7 +237,7 @@ export default {
this.copyVisible = true
} else {
//
this.$confirm('当前未选中任何数据,是否需要复制当前列表的全部数据?', '提示', {
this.$confirm(`当前未选中任何数据,是否需要复制当前列表的全部${this.total}条数据?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
@ -295,6 +295,7 @@ export default {
this.initData()
this.$message.success('复制成功!')
this.copyVisible = false
this.multipleSelection = []
} catch (e) {
this.copying = false
}

Loading…
Cancel
Save