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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="./js/vue.min.js"></script> <title>成语学习</title> <style> * { margin: 0; padding: 0; }
#app { margin: auto; }
.title { text-align: center; padding: 10px 0; background-image: linear-gradient(-225deg, #69EACB 0%, #EACCF8 48%, #6654F1 100%); }
.idiom_tips_box { text-align: center; margin: 30px 0; }
.detailed_description { border-radius: 20px; padding: 15px 30px; border-radius: 4px; font-size: 16px; }
.idiom_box { display: flex; align-items: center; justify-content: center; margin: 20px auto; }
.item_box { height: 120px; width: 120px; display: flex; align-items: center; justify-content: center; font-size: 50px; border-radius: 8px; margin-right: 10px; background: rgb(248, 243, 243); border: 1px solid #999 }
.optional_words_region { margin: auto; margin-top: 50px; text-align: center; display: flex; flex-wrap: wrap; }
.words { display: block; width: 50px; height: 50px; margin: 5px; background: orange; border: 1px solid black; border-radius: 4px; font-size: 40px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.words:hover { background: rgb(247, 113, 3); color: rgb(248, 243, 243); }
.confirm_btn_box { margin: 10px auto; display: flex; justify-content: center; cursor: pointer; }
.confirm_btn { margin-top: 30px; border-radius: 8px; padding: 10px 30px; color: white; background: #409eff } </style> </head>
<body> <!-- {word:"热泪盈眶",means:"形容非常感激或高兴"} --> <!-- {word:"才华横溢",means:"指才华充分显露出来"} --> <!-- {word:"聚沙成塔",means:"比喻积少成多"} --> <!-- {word:"名垂青史",means:"形容功业巨大,永远流传"} --> <!-- {word:"绝无仅有",means:"形容极其稀少"} --> <!-- {word:"衣衫褴褛",means:"形容身上衣服破破烂烂"} --> <!-- {word:"焕然一新",means:"形容呈现出崭新的面貌"} --> <!-- {word:"并驾齐驱",means:"比喻齐头并进,不分前后"} --> <!-- {word:"博大精深",means:"形容思想和学识广博高深"} --> <!-- {word:"忙里偷闲",means:"在繁忙中抽出空闲来"} --> <div id="app"> <div class="title">成语学习</div> <!-- 提示-描述 --> <div class="idiom_tips_box"> <span class="detailed_description">提示:{{tip}}</span> </div> <!-- 选中的成语 --> <div class="idiom_box"> <div class="item_box" v-for="item,index in idiom" @click="clear(index)">{{item}}</div> </div> <div :style="result == null ? 'color:#ccc' : result ? 'color : red' : ''" style="text-align:center"> {{result == null ? '请点击下方文字组织正确的成语(点击框内文字可清除)' : result ? '答案正确' : '答案错误'}}</div> <!-- 可选区域 --> <div class="optional_words_region"> <!-- <div>{{word}}</div> --> <span class="words" v-for="(item,index) in words.split('')" :key="index" @click="getSingleWord(item)"> {{item}} </span> </div> <!-- 确定 --> <div class="confirm_btn_box"> <span class="confirm_btn" @click="confirm">确定</span> </div> </div>
<script> var vm = new Vue({ el: '#app', data: { tip: "", arr: [ { word: "热泪盈眶", tip: "形容非常感激或高兴" }, { word: "才华横溢", tip: "指才华充分显露出来" }, { word: "聚沙成塔", tip: "比喻积少成多" }, { word: "名垂青史", tip: "形容功业巨大,永远流传" }, { word: "绝无仅有", tip: "形容极其稀少" }, { word: "衣衫褴褛", tip: "形容身上衣服破破烂烂" }, { word: "焕然一新", tip: "形容呈现出崭新的面貌" }, { word: "并驾齐驱", tip: "比喻齐头并进,不分前后" }, { word: "博大精深", tip: "形容思想和学识广博高深" }, { word: "忙里偷闲", tip: "在繁忙中抽出空闲来" } ], words: '', idiom: ["", "", "", ""], result: null }, created() { this.tip = this.arr[parseInt(Math.random() * this.arr.length)].tip this.arr.forEach(item => { this.words += item.word });
let words = this.words.split(""); words = this.shuffle(words) this.words = words.join("")
}, methods: { //乱序方法 shuffle(arr) { let temp, length = arr.length; for (let i = 0; i < length - 1; i++) { let index = Math.floor(Math.random() * (length--)); temp = arr[index]; arr[index] = arr[length]; arr[length] = temp; } return arr; }, //TODO 点击文字后,在idiom从左到右第一个空的位置加上改文字 getSingleWord(val) { this.idiom.splice(this.idiom.indexOf(''), 1, val) }, clear(i) { this.idiom[i] = "" this.$set(this.idiom, i, "") }, // TODO 校验成语是否输入正确答案 // 猜中成语 result 为 true; // 猜错成语 result 为 false; // 例1:tip=‘形容非常感激或高兴’,idiom=["热","泪","盈","眶"],则result返回true // 例2:tip=‘形容非常感激或高兴’,idiom=["泪","眼","盈","眶"],则result返回false // 例3:tip=‘在繁忙中抽出空闲来’,idiom=["忙","里","偷","闲"],则result返回true confirm() { this.result = null if (this.idiom.length !== 4) { this.result = false } const str = this.idiom.toString().split(',').join('') console.log(str); this.arr.forEach(item => { if (item.word === str && item.tip === this.tip) { this.result = true return } }) if (this.result === true) { return } this.result = false } } }) </script>
</body>
</html>
|