evaluation.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="maturity-game-page" v-loading="pageLoading">
  3. <head-component :headinfo=headinfo></head-component>
  4. <div class="page-content">
  5. <div class="content-left"></div>
  6. <div class="content-center">
  7. <div class="content-img">
  8. <img src="@/assets/images/wakeup/maturity/shadow-bg.png" >
  9. <div v-for="(item,index) in maturityAppraisalData">
  10. <p v-show="index===0?true:false">{{item.questionTitle}}</p>
  11. </div>
  12. </div>
  13. <div class="group-btn">
  14. <img src="@/assets/images/wakeup/maturity/btn1.png" @click="selectBtn('1')">
  15. <img src="@/assets/images/wakeup/maturity/btn2.png" @click="selectBtn('2')">
  16. <img src="@/assets/images/wakeup/maturity/btn3.png" @click="selectBtn('3')">
  17. <img src="@/assets/images/wakeup/maturity/btn4.png" @click="selectBtn('4')">
  18. <img src="@/assets/images/wakeup/maturity/btn5.png" @click="selectBtn('5')">
  19. </div>
  20. <div class="progress-container">
  21. <div class="progress-bar" :style="{ width: progress + '%' }">
  22. </div>
  23. <div class="progress-info">
  24. {{ newData.length }} / {{ questionSize }}
  25. </div>
  26. </div>
  27. </div>
  28. <div class="content-right">
  29. <img class="btn-img" v-show="newData.length>0" @click="previousQuestion" src="@/assets/images/wakeup/maturity/pre-qustion.png" >
  30. <div class="time">
  31. <img src="@/assets/images/wakeup/maturity/time.png" >
  32. <p> {{ formattedTime(elapsedTime) }}</p>
  33. </div>
  34. <img class="btn-img" v-show="newData.length >= questionSize" src="@/assets/images/wakeup/maturity/submit.png" >
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script setup>
  40. import headComponent from '@/views/xjc-integratedmachine/components/head_component.vue'
  41. import {exampleList, maturityAppraisalList} from "@/api/xjc-integratedmachine/wakeup/index.js";
  42. const router = useRouter()
  43. let pageLoading = ref(false)
  44. const headinfo = ref({})
  45. // const progress = ref(0)
  46. const draggedItem = ref(null);
  47. const maturityAppraisalData = ref([])
  48. const itemScore = ref('')
  49. const newData = ref([])
  50. const appraisalId = ref(null)
  51. const questionSize = ref(null);
  52. function dragStart(event) {
  53. draggedItem.value = event.target;
  54. }
  55. function drop(event) {
  56. event.preventDefault(); // 防止默认处理(例如打开链接)
  57. if (event.target !== draggedItem.value) {
  58. const target = event.target; // 获取放置的目标元素
  59. const item = draggedItem.value; // 获取被拖拽的元素
  60. // 交换位置或进行其他操作
  61. item.parentNode.insertBefore(item, target); // 将被拖拽的元素插入到目标元素之前
  62. }
  63. }
  64. function setHeadinfo(){
  65. headinfo.value = {
  66. title: '生涯成熟度测评',
  67. user: {
  68. avatar: '头像路径',
  69. nickName: '张三'
  70. },
  71. backUrl : '/index'
  72. }
  73. }
  74. function jumpTo(path) {
  75. router.push({
  76. path: path,
  77. query: {name: 123}
  78. })
  79. }
  80. function getMaturityAppraisalList() {
  81. pageLoading = true;
  82. let appraisalCode = "3001"
  83. maturityAppraisalList({appraisalCode:appraisalCode}).then(res => {
  84. if(res.data.questionList.length > 0){
  85. maturityAppraisalData.value = res.data.questionList;
  86. }
  87. appraisalId.value = res.data.appraisalId;
  88. questionSize.value = res.data.questionSize;
  89. pageLoading = false;
  90. }).catch((err)=>{
  91. console.log("error")
  92. pageLoading = false;
  93. })
  94. }
  95. //计时器
  96. const elapsedTime = ref(0);
  97. const timerId = ref(null);
  98. const isRunning = ref(false);
  99. const startTimer = () => {
  100. if (!isRunning.value) {
  101. isRunning.value = true;
  102. timerId.value = setInterval(() => {
  103. elapsedTime.value += 1000;
  104. }, 1000);
  105. }
  106. };
  107. const stopTimer = () => {
  108. if (isRunning.value) {
  109. isRunning.value = false;
  110. clearInterval(timerId.value);
  111. timerId.value = null;
  112. }
  113. };
  114. const resetTimer = () => {
  115. stopTimer();
  116. elapsedTime.value = 0;
  117. };
  118. const formattedTime = (ms) => {
  119. const totalSeconds = Math.floor(ms / 1000);
  120. const hours = String(Math.floor(totalSeconds / 3600)).padStart(2, '0');
  121. const minutes = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0');
  122. const seconds = String(totalSeconds % 60).padStart(2, '0');
  123. return `${hours}:${minutes}:${seconds}`;
  124. };
  125. onMounted(() => {
  126. // 可以在这里自动开始计时器,如果需要的话
  127. startTimer();
  128. setHeadinfo()
  129. getMaturityAppraisalList()
  130. });
  131. // onUnmounted(() => {
  132. stopTimer();
  133. // });
  134. // 定义当前完成题目数量和总题目数量
  135. const current = ref(34);
  136. const total = ref(100); // 假设总共有10道题
  137. // 计算进度
  138. const progress = computed(() => {
  139. return Math.floor((current.value / total.value) * 100);
  140. });
  141. // 更新当前完成题目数量的函数(例如,当用户完成一道题时调用)
  142. const updateCurrent = (newCurrent) => {
  143. if (newCurrent >= 0 && newCurrent <= total.value) {
  144. current.value = newCurrent;
  145. }
  146. };
  147. const selectBtn = (val) => {
  148. //将当前题目加入新数组,
  149. // 拼接选项数据
  150. if(newData.value.length != questionSize.value ){
  151. itemScore.value += val + '|'
  152. newData.value.push(maturityAppraisalData.value[0]);
  153. }
  154. //更换题卡;
  155. if(maturityAppraisalData.value.length >1 ){
  156. maturityAppraisalData.value.splice(0, 1);
  157. }
  158. };
  159. const previousQuestion = (val) => {
  160. //新数组中的最后一位从头插入旧数组
  161. //新数组删除最后一位
  162. maturityAppraisalData.value.unshift(newData.value.pop());
  163. // newData.value.push(maturityAppraisalData.value[0]);
  164. // maturityAppraisalData.value.splice(0, 1);
  165. //字符串删除后两位
  166. itemScore.value = itemScore.value.slice(0, -2);
  167. console.log("itemScore",itemScore.value,newData.value)
  168. };
  169. </script>
  170. <style scoped lang="scss">
  171. p{
  172. margin: 0;
  173. padding:0;
  174. }
  175. .maturity-game-page{
  176. background: url('@/assets/images/wakeup/maturity/maturity-game-bg.png') no-repeat;
  177. background-size: 1920px 1080px;
  178. z-index:10;
  179. width: 100%;
  180. height: 1080px;
  181. .page-content{
  182. width: 100%;
  183. position: absolute;
  184. top: 123px;
  185. bottom: 0;
  186. display: flex;
  187. justify-content: space-around;
  188. .content-left{
  189. width: 244px;
  190. }
  191. .content-center{
  192. height:910px;
  193. display: flex;
  194. flex-direction: column;
  195. .content-img{
  196. width: 1187px;
  197. height: 424px;
  198. //border: 1px solid;
  199. margin-top: 40px;
  200. position: relative;
  201. img{
  202. width: 1187px;
  203. height: 424px;
  204. }
  205. p{
  206. width: 930px;
  207. position: absolute;
  208. top: 150px;
  209. left: 130px;
  210. font-weight: 400;
  211. font-size: 30px;
  212. color: #000000;
  213. letter-spacing: 4px;
  214. text-align: center;
  215. }
  216. }
  217. .progress-container {
  218. width: 100%;
  219. //background-color: #f3f3f3;
  220. border-radius: 4px;
  221. margin-bottom: 10px;
  222. overflow: hidden;
  223. display: flex;
  224. justify-content: center;
  225. align-items: center;
  226. margin-top: 200px;
  227. }
  228. .progress-bar {
  229. height: 10px;
  230. background-color: #63FFA4;
  231. text-align: center;
  232. line-height: 20px;
  233. border-radius: 100px 100px 100px 100px;
  234. color: white;
  235. transition: width 0.3s ease;
  236. }
  237. .progress-info {
  238. font-weight: 400;
  239. font-size: 24px;
  240. color: #00DF5D;
  241. margin-left: 20px;
  242. }
  243. }
  244. .content-right{
  245. display: flex;
  246. flex-direction: column;
  247. align-items: center;
  248. .btn-img{
  249. width: 244px;
  250. height: 77px;
  251. margin-top: 20px;
  252. }
  253. .time{
  254. width:220px;
  255. height: 50px;
  256. //border: 1px solid;
  257. display: flex;
  258. justify-content: center;
  259. margin-top: 20px;
  260. img{
  261. width: 42px;
  262. height: 42px;
  263. //border: 1px solid;
  264. }
  265. p{
  266. width: 150px;
  267. font-weight: 300;
  268. font-size: 32px;
  269. color: #363a3d;
  270. margin-left: 10px;
  271. }
  272. }
  273. }
  274. }
  275. .group-btn{
  276. display: flex;
  277. justify-content: space-around;
  278. margin-top: 80px;
  279. img{
  280. width: 200px;
  281. height: 135px;
  282. }
  283. }
  284. }
  285. </style>