[测评系统]--前端(用户答题页面)
林致杰
2023-05-09 897ccf2ca09e5910c082a1032033afcf7b55c810
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
  <div class="demography">
    <div hidden>{{goLangType}}</div>
    <el-form class="align-center" style="padding: 3%">
      <h1 v-bind:class="{langKaiStyle : isLangKaiStyle}">{{langWelcome}}</h1>
      <h3 v-bind:class="{langKaiStyle : isLangKaiStyle}" style="color: #3a8ee6">{{langOption}}</h3>
            <el-select v-model="langSelectValue"   :placeholder= "$t('pleaseSelect')" style="width: 55%">
              <el-option
                v-for="itemIter in langTypes"
                :key="itemIter.dictValue"
                :label="itemIter.dictValue"
                :value="itemIter.dictValue">
              </el-option>
            </el-select>
      <el-footer class="do-align-center">
        <el-button @click="submitLangOption" type="danger">{{submissionLang}}</el-button>
      </el-footer>
    </el-form>
  </div>
</template>
 
<script>
import demographyApi from '@/api/demography'
import { mapMutations, mapState } from 'vuex'
// import examPaperApi from '@/api/examPaper'
// import QuestionEdit from "./childCompoment/QuestionEdit";
import examPaperApi from '@/api/examPaper'
 
export default {
  // components: { QuestionEdit },
  data () {
    return {
      langTypes: [],
      langSelectValue: this.$route.query.langSelectValue,
      langWelcome: this.$t('langWelcomeChinese'),
      langOption: this.$t('langOptionChinese'),
      timer: null,
      submissionLang: this.$t('submission'),
      isLangKaiStyle: false
    }
  },
  created: function () {
    let _this = this
    window.clearInterval(this.timer)
    _this.getLangType()
    _this.getLangAndRportTemplateId()
    let num = 0
    this.timer = setInterval(function () {
      if (num > 9) {
        num = 0
      }
      if (num === 0) {
        _this.langWelcome = _this.$t('langWelcomeChinese')
        _this.langOption = _this.$t('langOptionChinese')
        _this.isLangKaiStyle = true
      }
 
      if (num === 3) {
        _this.langWelcome = _this.$t('langWelcomeEnglish')
        _this.langOption = _this.$t('langOptionEnglish')
        _this.isLangKaiStyle = false
      }
 
      if (num === 6) {
        _this.langWelcome = _this.$t('langWelcomeThai')
        _this.langOption = _this.$t('langOptionThai')
        _this.isLangKaiStyle = false
      }
      num++
    }, 1000)
  },
  beforeDestroy () {
    window.clearInterval(this.timer)
  },
  methods: {
    submitLangOption: function () {
      let _this = this
      _this.setLangType(_this.langSelectValue)
      _this.$router.push({ path: '/demography/fill/index', query: { demographyMenber: _this.memberToken, isStart: false } })
      window.clearInterval(this.timer)
    },
    getLangAndRportTemplateId () {
      let _this = this
      if (_this.reportTemplateId.trim() === '' || _this.reportTemplateId.trim() === null) {
        examPaperApi.selectTokenId(_this.memberToken).then(re => {
          if (re.response.finish === 1) {
            _this.$router.push({ path: '/exam/finish', query: { name: '', content: _this.$t('finishMsg'), tokenId: _this.memberToken } })
          } else {
            _this.setReportTemplateId(re.response.reportTemplateId)
            demographyApi.queryLangList(_this.memberToken, _this.reportTemplateId).then(function (result) {
              if (result && result.code === 1) {
                _this.langTypes = result.response
              }
            }
            ).catch(e => {
              _this.$message.error(_this.$t('noquestionMsg'))
            })
          }
        }).catch(e => {
        })
      } else {
        demographyApi.queryLangList(_this.memberToken, _this.reportTemplateId).then(function (result) {
          if (result && result.code === 1) {
            _this.langTypes = result.response
          }
        }
        ).catch(e => {
          _this.$message.error(_this.$t('noquestionMsg'))
        })
      }
    },
    ...mapMutations('user', ['setMemberTocken']),
    ...mapMutations('user', ['setLangType']),
    ...mapMutations('user', ['getLangType']),
    ...mapMutations('exam', ['setReportTemplateId'])
  },
  computed: {
    ...mapState('user', { memberToken: state => state.memberToken }),
    ...mapState('exam', { doUrl: state => state.doUrl }),
    ...mapState('exam', { reportTemplateId: state => state.reportTemplateId }),
    ...mapState('user', { langType: state => state.langType }),
    goLangType: function () {
      // `this` 指向 vm 实例
      let _this = this
      if (_this.langSelectValue === 'Chinese') {
        _this.$i18n.locale = 'zh'
        _this.submissionLang = '提交'
      } else if (_this.langSelectValue === 'Thai') {
        _this.$i18n.locale = 'th'
        _this.submissionLang = 'เสนอ'
      } else {
        _this.$i18n.locale = 'en'
        _this.submissionLang = 'submit'
      }
      return _this.langType
    }
  }
}
</script>
 
<style lang="scss" scoped>
  .demography {
    width: 90%;
    margin: 0 auto;
    margin-top: 5%;
  }
 
  .align-center {
    text-align: center
  }
 
  .langKaiStyle {
    font-family: Kai
  }
</style>