0


第十六届蓝桥杯(Web 应用开发)模拟赛 2 期-大学组

持续更新中......

第一题:元素周期表

  1. /* TODO 待补充代码 Start*/
  2. .container .table {
  3. /* 请使用 flex布局,使元素周期表中的 18 列元素横向排列。 */
  4. display: flex;
  5. }
  6. .container .table .interval1 {
  7. /* 请使用 var、calc 函数设置第2、13~17列元素(class=interval1)的 margin-top 为 1 个元素的高度 */
  8. margin-top: var(--interval);
  9. }
  10. .container .table .interval3 {
  11. /* 设置第3~12列元素(class=interval3)的 margin-top 为 3 个元素的高度。 */
  12. margin-top: calc(var(--interval) * 3);
  13. }
  14. /* TODO End */

第二题:每日签到

  1. // TODO:请补充代码
  2. // 为每日签到按钮(id="sign_in_btn")绑定一个点击事件
  3. signInBtn.addEventListener("click", () => {
  4. // let currentAllDate = new Date().toISOString().split("T")[0]; 2024-11-23
  5. let currentDate = new Date().getDate();
  6. let paragraphs = daysBox.querySelectorAll("p");
  7. let foundFlag = false;
  8. // 实现在天数元素(id="days")下,为当前系统时间的日期相同的 p 标签添加一个 active 类,表示签到成功
  9. for (let i = 0; i < paragraphs.length; i++) {
  10. if (paragraphs[i].textContent == currentDate) {
  11. paragraphs[i].classList.add("active");
  12. foundFlag = true;
  13. break;
  14. }
  15. }
  16. // 为每日签到按钮(id="sign_in_btn")添加一个 no-active 类,表示按钮不可用,并将提示文字改为:明天也要记得来哦
  17. if (foundFlag) {
  18. signInBtn.classList.add("no-active");
  19. signInBtn.innerHTML = "明天也要记得来哦";
  20. }
  21. });

第三题:你还在等我吗

  1. class Storage {
  2. constructor() {
  3. this.storage = window.localStorage;
  4. }
  5. setItem(key, value, expired) {
  6. // TODO 待补充代码
  7. window.localStorage.setItem(key, value);
  8. setTimeout(() => {
  9. delete window.localStorage[key];
  10. }, expired);
  11. }
  12. getItem(key) {
  13. // TODO 待补充代码
  14. return window.localStorage[key] || null;
  15. }
  16. removeItem(key) {
  17. // TODO 待补充代码
  18. setbox.textContent = "";
  19. getbox.textContent = "";
  20. delete window.localStorage[key];
  21. }
  22. }
  23. const storage = new Storage();
  24. // 为了检测时使用,请勿删除
  25. if (window) {
  26. window.storage = storage;
  27. }

第四题:地址识别

  1. function parseContactInfo(text) {
  2. // TODO: 请补充代码
  3. // 定义正则表达式
  4. let nameRegex = /[\u4e00-\u9fa5]{2,4}/;
  5. let phoneRegex = /\d{11}/;
  6. let addressRegex = /^[\u4e00-\u9fa5][\u4e00-\u9fa5a-zA-Z0-9]{3,}$/;
  7. // 分割输入文本
  8. let parts = text.split(" ");
  9. // 初始化结果对象
  10. const result = {
  11. name: "",
  12. phone: "",
  13. address: "",
  14. };
  15. // 遍历每个部分,尝试匹配
  16. parts.forEach((part) => {
  17. if (part.length >= 2 && part.length < 4 && nameRegex.test(part)) {
  18. result.name = part;
  19. } else if (part.length == 11 && phoneRegex.test(part)) {
  20. result.phone = part;
  21. } else if (part.length >= 4 && addressRegex.test(part)) {
  22. result.address = part;
  23. }
  24. });
  25. return result;
  26. }

第五题:文本自动生成器

  1. /**
  2. * 组合多个中间件函数,形成一个新的中间件函数。
  3. * @param {...Function} middlewares - 要组合的中间件函数。
  4. * @return {Function} - 组合后的中间件函数。
  5. */
  6. function compose(...middlewares) {
  7. // TODO : 待补充代码
  8. // 返回一个新的中间件函数
  9. return function (initialValue, callback) {
  10. // 定义一个递归函数来依次执行中间件
  11. const dispatch = (index, value) => {
  12. // 如果已经到达最后一个中间件,则执行 callback
  13. if (index === middlewares.length) {
  14. return callback(value);
  15. }
  16. // 获取当前中间件函数
  17. const middleware = middlewares[index];
  18. // 调用当前中间件函数,并传递当前值和下一个中间件函数
  19. middleware(value, (nextValue) => {
  20. dispatch(index + 1, nextValue);
  21. });
  22. };
  23. // 开始执行第一个中间件函数
  24. dispatch(0, initialValue);
  25. };
  26. }

第六题:静态文件服务

  1. const fs = require("fs");
  2. const path = require("path");
  3. // 根据文件扩展名返回相应的 MIME 类型
  4. function getContentType(filePath) {
  5. const ext = path.extname(filePath).toLowerCase();
  6. const contentTypeMap = {
  7. ".html": "text/html",
  8. ".css": "text/css",
  9. ".js": "application/javascript",
  10. ".png": "image/png",
  11. // 在这里添加其他文件类型及其对应的 MIME 类型
  12. };
  13. return contentTypeMap[ext] || "application/octet-stream";
  14. }
  15. // 递归遍历目录并生成文件映射表
  16. function generateStaticFilesMap(dir) {
  17. // 初始化文件映射表
  18. const fileMap = {};
  19. // 定义一个辅助函数来遍历目录
  20. function traverseDir(currentDirPath) {
  21. // 读取当前目录中的所有文件和子目录
  22. const entries = fs.readdirSync(currentDirPath);
  23. // 遍历每个条目
  24. entries.forEach((entryName) => {
  25. // 获取当前条目的完整路径
  26. const fullPath = path.join(currentDirPath, entryName);
  27. // 获取当前条目的状态(是文件还是目录)
  28. const entryStat = fs.statSync(fullPath);
  29. if (entryStat.isFile()) {
  30. // 如果是文件,添加到映射表
  31. // 获取相对于根目录的路径
  32. const relativePath = path.relative(dir, fullPath);
  33. // 将相对路径转换为以斜杠开头的 URL 路径
  34. const urlPath = `/${relativePath}`;
  35. // 添加文件信息到映射表
  36. fileMap[urlPath] = {
  37. filePath: fullPath, // 文件的完整路径
  38. contentType: getContentType(fullPath), // 文件的内容类型
  39. };
  40. } else if (entryStat.isDirectory()) {
  41. // 如果是目录,则递归遍历
  42. traverseDir(fullPath);
  43. }
  44. });
  45. }
  46. // 从给定的根目录开始遍历
  47. traverseDir(dir);
  48. // 返回生成的文件映射表
  49. return fileMap;
  50. }
  51. // 使该函数可以被其他模块引用
  52. module.exports = generateStaticFilesMap;

第七题:企业微信会议助手

目标一:

  1. const fetchMeetingData = async () => {
  2. // TODO: 待补充代码
  3. return await fetch("js/meetings.json")
  4. .then((response) => {
  5. if (!response.ok) {
  6. throw new Error("网络响应错误");
  7. }
  8. return response.json();
  9. })
  10. .then((data) => {
  11. meeting.value = {
  12. title: data.title,
  13. time: data.time,
  14. location: data.location,
  15. };
  16. participants.value = data.participants;
  17. })
  18. .catch((error) => {
  19. console.error("请求失败:", error);
  20. });
  21. };
  22. const formatDate = (dateStr) => {
  23. // TODO: 待补充代码
  24. const date = new Date(dateStr);
  25. const year = date.getFullYear();
  26. const month = String(date.getMonth() + 1).padStart(2, "0");
  27. const day = String(date.getDate()).padStart(2, "0");
  28. return `${year}-${month}-${day}`;
  29. };

目标二 :

  1. const statusClass = (status) => {
  2. // TODO: 待补充代码
  3. switch (status) {
  4. case "待确认":
  5. return "status-pending";
  6. case "已接受":
  7. return "status-ready";
  8. case "已拒绝":
  9. return "status-declined";
  10. default:
  11. return "unknown";
  12. }
  13. };

目标三:

  1. function myAllSettled(promises) {
  2. // TODO: 待补充代码
  3. // 不能使用 Promise.allSettled, Promise.all,Promise.race 等方法
  4. const results = [];
  5. let completed = 0;
  6. return new Promise((resolve) => {
  7. promises.forEach((promise, index) => {
  8. promise
  9. .then(
  10. (value) => {
  11. results[index] = { status: "fulfilled", value };
  12. },
  13. (reason) => {
  14. results[index] = { status: "rejected", reason };
  15. }
  16. )
  17. .finally(() => {
  18. completed++;
  19. if (completed === promises.length) {
  20. resolve(results);
  21. }
  22. });
  23. });
  24. });
  25. }

第八题:知识点统计图

  1. import { ref, onMounted, computed, reactive } from "vue";
  2. export default {
  3. setup() {
  4. const mockUrl = "./mock/question_bank.json";
  5. let knowledgePoints = [];
  6. const chartContainer = ref(),
  7. rawData = ref([]);
  8. const difficultyOptions = ["简单", "中等", "困难"];
  9. const progressOptions = [
  10. "选题待审核",
  11. "题目制作中",
  12. "题目待测试",
  13. "题目待修改",
  14. "题目完成",
  15. ];
  16. const filterObj = reactive({
  17. difficulty: "",
  18. progress: "",
  19. });
  20. //检测需要,请勿修改 Start
  21. window.setKnowledgePoints = function (data) {
  22. knowledgePoints = data;
  23. applyFilter();
  24. };
  25. window.getRawData = function () {
  26. return JSON.stringify(rawData.value);
  27. };
  28. window.setFilter = function (d, p) {
  29. filterObj.difficulty = d;
  30. filterObj.progress = p;
  31. applyFilter();
  32. };
  33. window.getExtractUniquePoints = function (data) {
  34. return extractUniquePoints(data);
  35. };
  36. //检测需要,请勿修改 End
  37. let chart;
  38. function applyFilter() {
  39. let data;
  40. // TODO 4 请在下面补充代码
  41. let filteredData = rawData.value.filter((item) => {
  42. return (
  43. (!filterObj.difficulty || item.difficulty === filterObj.difficulty) &&
  44. (!filterObj.progress || item.progress === filterObj.progress)
  45. );
  46. });
  47. // 初始化 data 数组,长度为 knowledgePoints 的长度,初始值为 0
  48. data = new Array(knowledgePoints.length).fill(0);
  49. // 遍历筛选后的数据,计算每个知识点的题目数量
  50. filteredData.forEach((item) => {
  51. if (item.points && Array.isArray(item.points)) {
  52. item.points.forEach((point) => {
  53. const index = knowledgePoints.indexOf(point);
  54. if (index !== -1) {
  55. data[index]++;
  56. }
  57. });
  58. }
  59. });
  60. window.filteredData = JSON.stringify(data);
  61. // TODO 4 END
  62. const option = {
  63. title: {
  64. text: "知识点统计图",
  65. },
  66. tooltip: {
  67. // TODO 6 请在下面补充代码
  68. trigger: "item",
  69. axisPointer: {
  70. type: "none",
  71. },
  72. valueFormatter: function (value, index) {
  73. return `${value} 个项目`;
  74. },
  75. // TODO 6 END
  76. },
  77. xAxis: {
  78. type: "category",
  79. axisLabel: {
  80. interval: 0,
  81. },
  82. data: knowledgePoints,
  83. },
  84. yAxis: {
  85. type: "value",
  86. },
  87. series: [
  88. // TODO 5 请在下面补充代码
  89. { type: "bar", data: data },
  90. // TODO 5 END
  91. ],
  92. };
  93. window.chartData = JSON.stringify(option);
  94. // TODO 3 请在下面补充代码
  95. // 使用 chart 变量来设置图表选项并渲染图表
  96. chart.setOption(option);
  97. // TODO 3 END
  98. }
  99. function extractUniquePoints(data) {
  100. // TODO 2 请在下面补充代码
  101. const pointsSet = new Set();
  102. data.forEach((item) => {
  103. if (item.points && Array.isArray(item.points)) {
  104. item.points.forEach((point) => {
  105. pointsSet.add(point);
  106. });
  107. }
  108. });
  109. return Array.from(pointsSet);
  110. // TODO 2 END
  111. }
  112. onMounted(async function () {
  113. chart = echarts.init(chartContainer.value);
  114. // TODO 1 请在下面补充代码
  115. try {
  116. const response = await axios.get(mockUrl);
  117. rawData.value = response.data;
  118. knowledgePoints = extractUniquePoints(response.data);
  119. applyFilter();
  120. } catch (error) {
  121. console.error("获取数据失败:", error);
  122. }
  123. // TODO 1 END
  124. });
  125. return {
  126. chartContainer,
  127. difficultyOptions,
  128. progressOptions,
  129. filterObj,
  130. applyFilter,
  131. };
  132. },
  133. template: `<div class="window">
  134. <main ref="chartContainer"></main>
  135. <aside>
  136. <h2>筛选数据</h2>
  137. <el-form label-width="auto">
  138. <el-form-item label="题目难度">
  139. <el-select placeholder="选择要显示的题目难度" v-model="filterObj.difficulty">
  140. <el-option v-for="(it, idx) in difficultyOptions" :key="idx" :value="it">{{ it }}</el-option>
  141. </el-select>
  142. </el-form-item>
  143. <el-form-item label="题目制作进度">
  144. <el-select placeholder="选择要显示的题目制作进度" v-model="filterObj.progress">
  145. <el-option v-for="(it, idx) in progressOptions" :key="idx" :value="it">{{ it }}</el-option>
  146. </el-select>
  147. </el-form-item>
  148. <el-form-item>
  149. <el-button type="primary" @click="applyFilter">应用筛选</el-button>
  150. </el-form-item>
  151. </el-form>
  152. </aside>
  153. </div>`,
  154. };

第九题:西游净霸

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>西游争霸</title>
  7. <link rel="stylesheet/less" href="./css/style.less" />
  8. <link rel="stylesheet" href="./lib/element-plus/index.css" />
  9. <script src="./lib/vue.min.js"></script>
  10. <script src="./lib/vueDemi.js"></script>
  11. <script src="./lib/element-plus/index.full.js"></script>
  12. <script src="./lib/axios.js"></script>
  13. <script src="./lib/less.module.js"></script>
  14. </head>
  15. <body>
  16. <div id="app">
  17. <div class="container">
  18. <div class="initialization" v-if="showNewGame">
  19. <div class="init-card">
  20. <div class="init-title">新游戏</div>
  21. <div class="option">
  22. <div class="item">
  23. <div class="head">游戏难度</div>
  24. <div class="difficulty-list">
  25. <button
  26. :class="{active:difficulty == '简单'}"
  27. @click="switchingDifficulty('简单')"
  28. >
  29. 简单
  30. </button>
  31. <button
  32. :class="{active:difficulty == '普通'}"
  33. @click="switchingDifficulty('普通')"
  34. >
  35. 普通
  36. </button>
  37. <button
  38. :class="{active:difficulty == '困难'}"
  39. @click="switchingDifficulty('困难')"
  40. >
  41. 困难
  42. </button>
  43. </div>
  44. </div>
  45. <div class="item">
  46. <div class="head">卡牌数量</div>
  47. <div class="card-list">
  48. <button
  49. :class="{active:cardNum == 3}"
  50. @click="switchingCardNum(3)"
  51. >
  52. 3 V 3
  53. </button>
  54. <button
  55. :class="{active:cardNum == 5}"
  56. @click="switchingCardNum(5)"
  57. >
  58. 5 V 5
  59. </button>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="footer">
  64. <button @click="startTheGame" class="goGanme">开始游戏</button>
  65. </div>
  66. </div>
  67. </div>
  68. <div class="mainEventPast" v-else>
  69. <div class="left">
  70. <el-card class="rule">
  71. <!-- TODO 待补充代码 -->
  72. <div class="rule-item" v-for="item in ruleList">
  73. <img src="./images/warning.png" alt="" />
  74. <p>{{item}}</p>
  75. </div>
  76. </el-card>
  77. </div>
  78. <div class="center">
  79. <div
  80. :style="{width:cardBoxWidth,padding:goodGuys.length == 0 ? '0' : '0 5px'}"
  81. class="top"
  82. >
  83. <div class="card">
  84. <div
  85. class="box bad"
  86. :class="{active:i.active,flipped:i.isflipped}"
  87. v-for="(i,index) in badGuys"
  88. >
  89. <img src="./images/bgc.png" />
  90. <div class="numerical">
  91. <div class="head">
  92. <img :src="i.imgUrl" alt="" />
  93. </div>
  94. <div class="name">{{i.name}}</div>
  95. <div class="attackPower">战斗力:{{i.attackPower}}</div>
  96. <div class="defensivePower">
  97. 防御力:{{i.defensivePower}}
  98. </div>
  99. <div class="attributeValue">
  100. 属性值:{{i.attributeValue}}
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. <div
  107. :style="{width:cardBoxWidth,padding:goodGuys.length == 0 ? '0' : '0 5px'}"
  108. class="bottom"
  109. >
  110. <div class="card">
  111. <div
  112. class="box flipped good"
  113. :class="{active:i.active}"
  114. v-for="(i,index) in goodGuys"
  115. >
  116. <div class="numerical" @click="playCards(i)">
  117. <div class="head">
  118. <img :src="i.imgUrl" alt="" />
  119. </div>
  120. <div class="name">{{i.name}}</div>
  121. <div class="attackPower">战斗力:{{i.attackPower}}</div>
  122. <div class="defensivePower">
  123. 防御力:{{i.defensivePower}}
  124. </div>
  125. <div class="attributeValue">
  126. 属性值:{{i.attributeValue}}
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="right">
  134. <el-card class="newGame">
  135. <el-button type="primary" class="newName" @click="newGame"
  136. >新游戏</el-button
  137. >
  138. <el-button
  139. type="success"
  140. class="startOver"
  141. :disabled="!newGameBtn"
  142. @click="startOver"
  143. >重新开始</el-button
  144. >
  145. </el-card>
  146. <el-card class="scoreboard">
  147. <div class="title">记分板</div>
  148. <div class="socre">
  149. <div class="win">胜:{{win}}</div>
  150. <div class="negative">负:{{negative}}</div>
  151. </div>
  152. </el-card>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </body>
  158. <script>
  159. const { createApp, ref, computed, onMounted, watch } = Vue;
  160. const { ElNotification, ElMessageBox } = ElementPlus;
  161. const app = createApp({
  162. setup() {
  163. const showNewGame = ref(true);
  164. const difficulty = ref("简单");
  165. const cardNum = ref(3);
  166. const num = ref(3);
  167. const win = ref(0);
  168. const negative = ref(0);
  169. const currentCardPlayed = ref(null);
  170. const currentCardsPlayedByHumansAndMachines = ref(null);
  171. const dataList = ref([]);
  172. const goodGuys = ref([]);
  173. const badGuys = ref([]);
  174. const ruleList = ref([]);
  175. const newGameBtn = ref(true);
  176. const getDataList = async () => {
  177. //TODO 待补充代码
  178. try {
  179. const response = await axios.get("./mock/data.json");
  180. const data = response.data;
  181. dataList.value = data;
  182. ruleList.value = response.data[2].content
  183. .split("。")
  184. .filter((item) => item !== "");
  185. } catch (error) {
  186. console.error("Error fetching data:", error);
  187. }
  188. };
  189. /**
  190. * 随机获取好人卡牌
  191. */
  192. const getRandomGoodGuysCards = () => {
  193. //TODO 待补充代码
  194. const goodPeople = dataList.value.find(
  195. (item) => item.name === "goodPeople"
  196. );
  197. if (goodPeople) {
  198. goodGuys.value = goodPeople.children
  199. .sort(() => 0.5 - Math.random())
  200. .slice(0, cardNum.value);
  201. }
  202. };
  203. /**
  204. * 随机获取坏人卡牌
  205. */
  206. const getRandomBadGuysCards = () => {
  207. //TODO 待补充代码
  208. const badPeople = dataList.value.find(
  209. (item) => item.name === "badPeople"
  210. );
  211. if (badPeople) {
  212. badGuys.value = badPeople.children
  213. .sort(() => 0.5 - Math.random())
  214. .slice(0, cardNum.value);
  215. }
  216. };
  217. // 根据难度获取当前人机需要出的牌
  218. const machinePlayCards = () => {
  219. let selectedCard = null;
  220. const attributeMap = {
  221. 火: "木",
  222. 木: "水",
  223. 水: "土",
  224. 土: "金",
  225. 金: "火",
  226. };
  227. if (difficulty.value === "简单") {
  228. selectedCard = badGuys.value.find(
  229. (card) =>
  230. attributeMap[currentCardPlayed.value.attributeValue] ==
  231. card.attributeValue
  232. );
  233. if (selectedCard) {
  234. return selectedCard;
  235. } else {
  236. return badGuys.value.sort(
  237. (a, b) => a.attackPower - b.attackPower
  238. )[0];
  239. }
  240. } else if (difficulty.value === "普通") {
  241. return badGuys.value.sort(
  242. (a, b) => b.attackPower - a.attackPower
  243. )[0];
  244. } else if (difficulty.value === "困难") {
  245. selectedCard = badGuys.value.find(
  246. (card) =>
  247. attributeMap[card.attributeValue] ==
  248. currentCardPlayed.value.attributeValue
  249. );
  250. if (selectedCard) {
  251. return selectedCard;
  252. } else {
  253. return badGuys.value.sort(
  254. (a, b) => b.attackPower - a.attackPower
  255. )[0];
  256. }
  257. }
  258. };
  259. /**
  260. * 判断输赢的函数
  261. * @param {object} goodCard
  262. * @param {object} badCard
  263. * @returns {string} result 结果
  264. */
  265. const judgeWinnerOrLoss = (goodCard, badCard) => {
  266. //TODO 待补充代码
  267. let goodSum =
  268. Number(goodCard.attackPower) + Number(goodCard.defensivePower);
  269. let badSum =
  270. Number(badCard.attackPower) + Number(badCard.defensivePower);
  271. // 判断属性克制关系
  272. if (
  273. goodCard.attributeValue === "火" &&
  274. badCard.attributeValue === "木"
  275. ) {
  276. goodSum *= 1.5;
  277. } else if (
  278. goodCard.attributeValue === "木" &&
  279. badCard.attributeValue === "水"
  280. ) {
  281. goodSum *= 1.5;
  282. } else if (
  283. goodCard.attributeValue === "水" &&
  284. badCard.attributeValue === "土"
  285. ) {
  286. goodSum *= 1.5;
  287. } else if (
  288. goodCard.attributeValue === "土" &&
  289. badCard.attributeValue === "金"
  290. ) {
  291. goodSum *= 1.5;
  292. } else if (
  293. goodCard.attributeValue === "金" &&
  294. badCard.attributeValue === "火"
  295. ) {
  296. goodSum *= 1.5;
  297. } else if (
  298. badCard.attributeValue === "火" &&
  299. goodCard.attributeValue === "木"
  300. ) {
  301. badSum *= 1.5;
  302. } else if (
  303. badCard.attributeValue === "木" &&
  304. goodCard.attributeValue === "水"
  305. ) {
  306. badSum *= 1.5;
  307. } else if (
  308. badCard.attributeValue === "水" &&
  309. goodCard.attributeValue === "土"
  310. ) {
  311. badSum *= 1.5;
  312. } else if (
  313. badCard.attributeValue === "土" &&
  314. goodCard.attributeValue === "金"
  315. ) {
  316. badSum *= 1.5;
  317. } else if (
  318. badCard.attributeValue === "金" &&
  319. goodCard.attributeValue === "火"
  320. ) {
  321. badSum *= 1.5;
  322. }
  323. return goodSum > badSum ? "win" : "loss";
  324. };
  325. //切换难度
  326. const switchingDifficulty = (val) => {
  327. difficulty.value = val;
  328. };
  329. //切换卡牌数量
  330. const switchingCardNum = (val) => {
  331. cardNum.value = val;
  332. num.value = val;
  333. };
  334. //开始新游戏
  335. const startTheGame = () => {
  336. showNewGame.value = false;
  337. };
  338. //重新开始
  339. const startOver = () => {
  340. getDataList();
  341. setTimeout(() => {
  342. num.value = cardNum.value;
  343. win.value = 0;
  344. negative.value = 0;
  345. goodGuys.value = [];
  346. badGuys.value = [];
  347. getRandomGoodGuysCards();
  348. getRandomBadGuysCards();
  349. }, 10);
  350. };
  351. const cardBoxWidth = computed(() => {
  352. if (num.value > 0) {
  353. return 120 * num.value + 20 + "px";
  354. } else {
  355. return 0;
  356. }
  357. });
  358. const cardImgWidth = computed(() => {
  359. return (1 / num.value) * 100;
  360. });
  361. const debounce = (func, delay) => {
  362. let timeout;
  363. return (...args) => {
  364. clearTimeout(timeout);
  365. timeout = setTimeout(() => {
  366. func.apply(this, args);
  367. }, delay);
  368. };
  369. };
  370. //出牌
  371. const playCards = (val) => {
  372. if (currentCardPlayed.value) {
  373. return;
  374. }
  375. val.active = true;
  376. currentCardPlayed.value = val;
  377. newGameBtn.value = false;
  378. playCardsByComputer();
  379. };
  380. const debouncedPlayCards = debounce(playCards, 1000);
  381. //人机出牌
  382. const playCardsByComputer = () => {
  383. const res = machinePlayCards();
  384. res.active = true;
  385. currentCardsPlayedByHumansAndMachines.value = res;
  386. setTimeout(() => {
  387. res.isflipped = true;
  388. judge();
  389. }, 1000);
  390. };
  391. const judge = () => {
  392. //得到当前出牌的数据伤害
  393. setTimeout(() => {
  394. const result = judgeWinnerOrLoss(
  395. currentCardPlayed.value,
  396. currentCardsPlayedByHumansAndMachines.value
  397. );
  398. if (result === "win") {
  399. win.value += 1;
  400. ElNotification({
  401. title: "Success",
  402. message: "本轮你赢了",
  403. type: "success",
  404. });
  405. } else {
  406. negative.value += 1;
  407. ElNotification({
  408. title: "Warning",
  409. message: "很遗憾,本轮你输了",
  410. type: "warning",
  411. });
  412. }
  413. //清除当前出的牌
  414. goodGuys.value = goodGuys.value.filter((item) => !item.active);
  415. badGuys.value = badGuys.value.filter((item) => !item.active);
  416. currentCardPlayed.value = null;
  417. currentCardsPlayedByHumansAndMachines.value = null;
  418. num.value -= 1;
  419. newGameBtn.value = true;
  420. }, 1500);
  421. };
  422. onMounted(() => {
  423. getDataList();
  424. document.body.style.backgroundColor = "rgb(79,201,249)";
  425. });
  426. const newGame = () => {
  427. getDataList();
  428. setTimeout(() => {
  429. num.value = 3;
  430. cardNum.value = 3;
  431. goodGuys.value = [];
  432. badGuys.value = [];
  433. win.value = 0;
  434. negative.value = 0;
  435. difficulty.value = "简单";
  436. showNewGame.value = true;
  437. }, 10);
  438. };
  439. watch(showNewGame, (newValue) => {
  440. if (!newValue) {
  441. getRandomGoodGuysCards();
  442. getRandomBadGuysCards();
  443. document.body.style.backgroundColor = "#f5f5f5";
  444. } else {
  445. document.body.style.backgroundColor = "rgb(79,201,249)";
  446. }
  447. });
  448. watch(num, (newValue) => {
  449. if (newValue == 0) {
  450. //对比胜负总数
  451. if (win.value > negative.value) {
  452. ElMessageBox.alert("你赢了", "胜负总和", {
  453. confirmButtonText: "OK",
  454. });
  455. } else {
  456. ElMessageBox.alert("你输了", "胜负总和", {
  457. confirmButtonText: "OK",
  458. });
  459. }
  460. }
  461. });
  462. return {
  463. showNewGame,
  464. cardNum,
  465. cardBoxWidth,
  466. num,
  467. cardImgWidth,
  468. dataList,
  469. goodGuys,
  470. badGuys,
  471. difficulty,
  472. ruleList,
  473. negative,
  474. currentCardPlayed,
  475. currentCardsPlayedByHumansAndMachines,
  476. win,
  477. newGameBtn,
  478. switchingDifficulty,
  479. switchingCardNum,
  480. startTheGame,
  481. playCards: debouncedPlayCards,
  482. startOver,
  483. newGame,
  484. judgeWinnerOrLoss,
  485. };
  486. },
  487. });
  488. app.use(ElementPlus);
  489. let vm = app.mount("#app");
  490. window.vm = vm;
  491. </script>
  492. </html>
  1. 目标 1 检测成功 5
  2. 目标 2 检测成功 5
  3. 目标 3 检测失败 0
  4. 目标 4 检测成功 5

第十题:消消乐

  1. // TODO 1 START 请在下面补充代码
  2. // 请求排行榜数据并显示消息的方法
  3. const fetchRanking = async () => {
  4. try {
  5. const response = await axios.get(mockUrl); // 发送 GET 请求
  6. const rankingData = response.data; // 获取响应数据
  7. // 使用 ElMessage 显示全服最高分信息
  8. ElMessage({
  9. message: `全服最高分为${rankingData.top.score},由${rankingData.top.name}创造`,
  10. duration: 0, // 设置为一直显示
  11. });
  12. } catch (error) {
  13. console.error("请求排行榜数据时出错:", error);
  14. // 请求出错时,显示错误消息
  15. ElMessage({
  16. message: "无法获取排行榜数据",
  17. duration: 3000, // 显示 3 秒
  18. });
  19. }
  20. };
  21. // 调用 fetchRanking 方法获取排行榜数据并显示
  22. fetchRanking();
  23. // TODO 1 END

本文转载自: https://blog.csdn.net/m0_63644111/article/details/143992989
版权归原作者 Emo猪 所有, 如有侵权,请联系我们删除。

“第十六届蓝桥杯(Web 应用开发)模拟赛 2 期-大学组”的评论:

还没有评论