diff --git a/README.md b/README.md index 78c690a0..88e5f979 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,18 @@

- - pr - commit + + pr + issues + + discussions- + docs diff --git a/web/package.json b/web/package.json index 0bacbc62..2f690bff 100644 --- a/web/package.json +++ b/web/package.json @@ -16,7 +16,7 @@ "axios": "^1.4.0", "clipboard": "^2.0.11", "core-js": "^3.8.3", - "crypto-js": "^4.1.1", + "crypto-js": "^4.2.0", "element-ui": "^2.15.13", "moment": "^2.29.4", "qrcode": "^1.5.3", diff --git a/web/src/render/App.vue b/web/src/render/App.vue index 9a78c7a7..3cf3796c 100644 --- a/web/src/render/App.vue +++ b/web/src/render/App.vue @@ -30,6 +30,7 @@ export default { computed: {}, created() { this.init(); + this.$store.dispatch('getEncryptInfo'); }, beforeCreate() {}, methods: { diff --git a/web/src/render/api/base.js b/web/src/render/api/base.js index 67c722b7..ed894fda 100644 --- a/web/src/render/api/base.js +++ b/web/src/render/api/base.js @@ -38,11 +38,11 @@ const getSignByData = (sourceData) => { // 请求中间件,对所有请求都生成签名 instance.interceptors.request.use((request) => { - let data; + let data = {}; if (request.method === 'get') { - data = request.params; + data = request.params || data; } else if (request.method === 'post') { - data = request.data; + data = request.data || data; } const sign = getSignByData(data); data.sign = sign; diff --git a/web/src/render/api/survey.js b/web/src/render/api/survey.js index a57dba81..e948f6e8 100644 --- a/web/src/render/api/survey.js +++ b/web/src/render/api/survey.js @@ -20,3 +20,7 @@ export const queryVote = ({ surveyPath, voteKeyList }) => { }, }); }; + +export const getEncryptInfo = () => { + return axios.get('/surveyPublish/getEncryptInfo'); +}; diff --git a/web/src/render/pages/index.vue b/web/src/render/pages/index.vue index 5538e239..4171bb05 100644 --- a/web/src/render/pages/index.vue +++ b/web/src/render/pages/index.vue @@ -15,6 +15,7 @@ import Header from '../components/header.vue'; import submit from '../components/submit.vue'; import mainRenderer from '../components/mainRenderer'; import { submitForm } from '@/render/api/survey'; +import encrypt from '../utils/encrypt'; export default { name: 'indexPage', @@ -46,6 +47,9 @@ export default { renderData() { return this.$store.getters.renderData; }, + encryptInfo() { + return this.$store.state.encryptInfo; + }, }, methods: { validate(cbk) { @@ -78,8 +82,14 @@ export default { difTime: Date.now() - this.$store.state.enterTime, clientTime: Date.now(), }; - result.encryptType = 'base64'; - result.data = btoa(encodeURIComponent(result.data)); + result.encryptType = this.encryptInfo?.encryptType || 'base64'; + result.data = encrypt[result.encryptType]({ + data: result.data, + code: this.encryptInfo?.data?.code, + }); + if (this.encryptInfo?.data?.sessionId) { + result.sessionId = this.encryptInfo.data.sessionId; + } return result; }, async submitForm() { diff --git a/web/src/render/store/actions.js b/web/src/render/store/actions.js index 490b2d7d..9ca9b004 100644 --- a/web/src/render/store/actions.js +++ b/web/src/render/store/actions.js @@ -1,6 +1,7 @@ import moment from 'moment'; import adapter from '../adapter'; -import { queryVote } from '@/render/api/survey'; +import { queryVote, getEncryptInfo } from '@/render/api/survey'; +import { CODE_MAP } from '@/management/api/base'; export default { // 初始化 @@ -32,7 +33,10 @@ export default { const todayStr = momentNow.format('yyyy-MM-DD'); const momentStartTime = moment(`${todayStr} ${answerBegTime}`); const momentEndTime = moment(`${todayStr} ${answerEndTime}`); - if (momentNow.isBefore(momentStartTime) || momentNow.isAfter(momentEndTime)) { + if ( + momentNow.isBefore(momentStartTime) || + momentNow.isAfter(momentEndTime) + ) { commit('setRouter', 'errorPage'); commit('setErrorInfo', { errorType: 'overTime', @@ -101,4 +105,10 @@ export default { commit('setVoteMap', voteRes.data); } }, + async getEncryptInfo({ commit }) { + const res = await getEncryptInfo(); + if (res.code === CODE_MAP.SUCCESS) { + commit('setEncryptInfo', res.data); + } + }, }; diff --git a/web/src/render/store/mutations.js b/web/src/render/store/mutations.js index 02b7a09f..ebfacfde 100644 --- a/web/src/render/store/mutations.js +++ b/web/src/render/store/mutations.js @@ -40,4 +40,7 @@ export default { setQuestionSeq(state, data) { state.questionSeq = data; }, + setEncryptInfo(state, data) { + state.encryptInfo = data; + }, }; diff --git a/web/src/render/store/state.js b/web/src/render/store/state.js index ac834459..b69de743 100644 --- a/web/src/render/store/state.js +++ b/web/src/render/store/state.js @@ -12,4 +12,5 @@ export default { enterTime: null, questionSeq: [], // 题目的顺序,因为可能会有分页的情况,所以是一个二维数组[[qid1, qid2], [qid3,qid4]] voteMap: {}, + encryptInfo: null, }; diff --git a/web/src/render/utils/encrypt.js b/web/src/render/utils/encrypt.js new file mode 100644 index 00000000..b393b8e2 --- /dev/null +++ b/web/src/render/utils/encrypt.js @@ -0,0 +1,14 @@ +import CryptoJS from 'crypto-js'; + +function base64({ data }) { + return btoa(encodeURIComponent(data)); +} + +function aes({ data, code }) { + return CryptoJS.AES.encrypt(encodeURIComponent(data), code).toString(); +} + +export default { + base64, + aes, +};