ChineseRadical.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <!-- 选择偏旁部首组成汉字 -->
  3. <div class="ChineseRadical Book_enter_container" v-if="curQue">
  4. <el-form-item label="文字">
  5. <el-input
  6. :key="item + i"
  7. @blur="onBlur(item, 'con')"
  8. @change="changChinese"
  9. placeholder="请输入文字"
  10. style="width: 300px; margin-bottom: 10px"
  11. v-for="(item, i) in curQue.stem"
  12. v-model="item.con"
  13. />
  14. <Upload
  15. :changeFillId="changeMp3"
  16. :datafileList="curQue.stem.length > 0 && curQue.stem[0].mp3List"
  17. :filleNumber="filleNumber"
  18. :uploadType="'mp3'"
  19. />
  20. </el-form-item>
  21. <el-form-item label="拼音">
  22. <div class="Book_flex">
  23. <el-input
  24. :key="item + i"
  25. @blur="onBlur(item, 'pinyin')"
  26. placeholder="请输入拼音"
  27. style="width: 300px"
  28. v-for="(item, i) in curQue.stem"
  29. v-model="item.pinyin"
  30. />
  31. <div @click="getPinyin(item)" class="insert_pinyin">
  32. <img class="pinyin_icon" src="../../../assets/common/pinyin.png" />
  33. <span>插入拼音</span>
  34. </div>
  35. </div>
  36. </el-form-item>
  37. <el-form-item label>
  38. <div :key="i" class="itemlist" v-for="(item, i) in curQue.option">
  39. <span style="margin-right: 10px">选项{{ i + 1 }}</span>
  40. <el-select
  41. @change="handleChange(item)"
  42. placeholder="请选择"
  43. v-model="item.img_url"
  44. >
  45. <el-option
  46. :disabled="opitem.isDisable"
  47. :key="opitem.resource_key"
  48. :label="opitem.index_memo"
  49. :value="opitem.id"
  50. v-for="opitem in structureListRes"
  51. ></el-option>
  52. </el-select>
  53. <img :src="item.con" class="img_url" v-if="item.img_url" />
  54. <el-radio
  55. :label="i"
  56. @change="changeAnswer(i)"
  57. style="margin-left: 10px"
  58. v-model="item.isAnswer"
  59. >正确答案</el-radio
  60. >
  61. <div class="add">
  62. <div @click="removeOption(i)"></div>
  63. </div>
  64. </div>
  65. <div class="Remove">
  66. <div @click="addOption"></div>
  67. </div>
  68. </el-form-item>
  69. <!-- <el-form-item label="功能设置">
  70. <el-checkbox v-model="curQue.playStorkes">播放笔顺</el-checkbox>
  71. </el-form-item>-->
  72. <el-form-item style="text-align: right; padding-right: 20px">
  73. <el-button @click="saveCurque" style="margin-right: 10px" type="primary"
  74. >保存</el-button
  75. >
  76. <el-popconfirm @onConfirm="removeCurque" title="确定删除吗?">
  77. <el-button slot="reference" type="primary">删除</el-button>
  78. </el-popconfirm>
  79. <!-- <el-popconfirm title="这是一段内容确定删除吗?">
  80. <el-button type="primary" @click="removeCurque">刪除</el-button>
  81. </el-popconfirm>-->
  82. </el-form-item>
  83. </div>
  84. </template>
  85. <script>
  86. import Upload from "../../../components/inputModules/common/Upload";
  87. import "../../../utils/pinyin_dict_withtone";
  88. import "../../../utils/pinyinUtil";
  89. export default {
  90. name: "ChineseStrokes",
  91. props: [
  92. "curQue",
  93. "changeDataList",
  94. "saveCacheData",
  95. "removeCaheData",
  96. "hanziSideList",
  97. ],
  98. components: {
  99. Upload,
  100. },
  101. data() {
  102. return {
  103. item: [
  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. targetitem: {
  130. // mp3: "", //音频
  131. // option: [
  132. // {
  133. // con: "",
  134. // isAnswer: "",
  135. // },
  136. // ], //选项
  137. // correct: [], //正确答案
  138. // type: "", //题的类型
  139. // content: "", //题干
  140. },
  141. spellShow: false,
  142. optionIndex: null,
  143. filleNumber: 1,
  144. structureListRes: [],
  145. };
  146. },
  147. watch: {
  148. hanziSideList: {
  149. handler: function (val, oldVal) {
  150. let _this = this;
  151. if (val) {
  152. _this.structureListRes = _this.handleStructureList(val);
  153. }
  154. },
  155. // 深度观察监听
  156. deep: true,
  157. },
  158. },
  159. methods: {
  160. handleChange(opItem) {
  161. let option = this.curQue.option;
  162. this.structureListRes.map((item) => {
  163. if (item.id == opItem.img_url) {
  164. opItem.con = item.file_url;
  165. }
  166. let opArr = option.filter((opitem) => opitem.img_url == item.id);
  167. if (opArr.length > 0) {
  168. item.isDisable = true;
  169. } else {
  170. item.isDisable = false;
  171. }
  172. return item;
  173. });
  174. },
  175. // 去除首位的空格
  176. onBlur(item, field) {
  177. item[field] = item[field] ? item[field].trim() : "";
  178. },
  179. // 上传音频
  180. changeMp3(id, fileList, duration) {
  181. this.curQue.stem[0].mp3_url = id ? "[FID##" + id + "##FID]" : "";
  182. this.curQue.stem[0].duration = duration ? duration : 0;
  183. this.curQue.stem[0].mp3List = fileList;
  184. },
  185. // 修改文字
  186. changChinese(e) {
  187. if (e == "") {
  188. this.curQue.stem.forEach((item) => {
  189. item.pinyin = " ";
  190. });
  191. }
  192. },
  193. // 保存单个题
  194. saveCurque() {
  195. this.saveCacheData();
  196. },
  197. removeCurque() {
  198. this.removeCaheData();
  199. },
  200. // 点击生成拼音
  201. getPinyin() {
  202. let bool = false;
  203. let value = "";
  204. this.curQue.stem.forEach((item) => {
  205. if (item.con == "") {
  206. this.$message.info("请先输入内容,再生成拼音");
  207. bool = true;
  208. } else {
  209. value = item.con;
  210. }
  211. });
  212. if (bool) {
  213. return;
  214. }
  215. let result = pinyinUtil.getPinyin(value);
  216. this.curQue.stem.forEach((item) => {
  217. item.pinyin = result;
  218. });
  219. },
  220. changeAnswer(index) {
  221. this.curQue.option.forEach((item, i) => {
  222. if (i == index) {
  223. this.curQue.correct[0] = item.img_url;
  224. } else {
  225. this.$set(this.curQue.option[i], "isAnswer", "");
  226. }
  227. });
  228. },
  229. addOption(index) {
  230. let flag = false;
  231. this.curQue.option.forEach((item) => {
  232. if (item.con == "") {
  233. flag = true;
  234. }
  235. });
  236. if (flag) {
  237. this.$message.info("请先填空再增加选项");
  238. return;
  239. }
  240. let obj = {
  241. con: "",
  242. };
  243. this.curQue.option.push(obj);
  244. },
  245. removeOption(index) {
  246. if (this.curQue.option.length <= 2) {
  247. this.$message.info("至少要有两个选项");
  248. return;
  249. }
  250. this.curQue.option.splice(index, 1);
  251. this.handleChange();
  252. },
  253. handleStructureList(arr) {
  254. let _this = this;
  255. arr = arr.map((item, index) => {
  256. item.id = "[FID##" + item.file_id + "##FID]";
  257. let opArr = _this.curQue.option.filter(
  258. (opitem) => opitem.img_url == item.id
  259. );
  260. if (opArr.length > 0) {
  261. item.isDisable = true;
  262. } else {
  263. item.isDisable = false;
  264. }
  265. item.index = index + 1;
  266. item.index_memo = `${item.index}. ${item.memo}`;
  267. return item;
  268. });
  269. return arr;
  270. },
  271. },
  272. created() {},
  273. mounted() {
  274. let _this = this;
  275. _this.structureListRes = _this.handleStructureList(this.hanziSideList);
  276. },
  277. };
  278. </script>
  279. <style lang="scss" scoped>
  280. .ChineseRadical {
  281. .pinyin {
  282. width: 400px;
  283. height: 180px;
  284. background: #ebebeb;
  285. border-radius: 5.3566px;
  286. display: flex;
  287. justify-content: center;
  288. flex-wrap: wrap;
  289. padding: 8px 10px;
  290. }
  291. .pinyin > div {
  292. margin: 5px;
  293. width: 32px;
  294. height: 35px;
  295. line-height: 32px;
  296. text-align: center;
  297. background: #fcfcfe;
  298. box-shadow: 0px 0.732069px 0px #898a8d;
  299. border-radius: 5.3566px;
  300. cursor: pointer;
  301. }
  302. .Upload {
  303. cursor: pointer;
  304. margin-left: 10px;
  305. }
  306. .Upload img {
  307. position: relative;
  308. top: 4px;
  309. }
  310. .itemlist {
  311. margin-bottom: 10px;
  312. margin-left: 20px;
  313. display: flex;
  314. align-items: center;
  315. }
  316. .add > div,
  317. .Remove > div {
  318. width: 40px;
  319. height: 40px;
  320. border: 1px solid #000000;
  321. display: flex;
  322. justify-content: center;
  323. align-content: center;
  324. cursor: pointer;
  325. }
  326. .Remove > div {
  327. margin-left: 65px;
  328. margin-top: 10px;
  329. background: url("../../../assets/common/add.png") no-repeat 50%;
  330. }
  331. .add > div {
  332. margin-left: 10px;
  333. background: url("../../../assets/common/remove.png") no-repeat 50%;
  334. }
  335. .img_url {
  336. width: 38px;
  337. margin-left: 20px;
  338. border: 1px solid #dcdfe6;
  339. }
  340. }
  341. </style>