Soduko.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes Sudoku" v-if="curQue">
  4. <div class="sodu-inner">
  5. <div class="item-box">
  6. <div :class="['item']" v-for="(item,index) in curQue.option" :key="index">
  7. <div v-for="(items,indexs) in item" :key="indexs"
  8. :class="[indexs%3==2?'noBorder':'',indexs>5?'noBorder-bottom':'',index==seletcItem[0]&&indexs==seletcItem[1]?'active':'',styleList[index][indexs],items.isHint?'notClick':'canClick']">
  9. <span v-if="items.isHint">
  10. {{items.value}}
  11. </span>
  12. <p v-else @click="handleCheck(index,indexs)">{{soduko[index][indexs]}}</p>
  13. <!-- <input v-else v-model="soduko[index][indexs]" maxlength="1" readonly> -->
  14. </div>
  15. </div>
  16. </div>
  17. <div class="item-right">
  18. <ul>
  19. <li v-for="(item,index) in selectList" :key="index" :class="[]" @click="handleClick(item)">
  20. {{item}}
  21. </li>
  22. </ul>
  23. <a class="resetBtn" @click="handleData">重做</a>
  24. <a class="submitBtn" @click="handleSubmit">提交</a>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. components: {},
  32. props: ["curQue"],
  33. data() {
  34. return {
  35. soduko:[],
  36. selectList:['1','6','2','7','3','8','4','9','5','?'],
  37. seletcItem:[],
  38. styleList:[]
  39. };
  40. },
  41. computed: {},
  42. watch: {},
  43. //方法集合
  44. methods: {
  45. // 处理数据
  46. handleData(){
  47. let _this = this
  48. _this.soduko = []
  49. _this.seletcItem = []
  50. _this.styleList = []
  51. _this.curQue.option.forEach(item => {
  52. let arr = []
  53. item.forEach(items=>{
  54. if(items.isHint){
  55. arr.push(items.value)
  56. }else{
  57. arr.push('')
  58. }
  59. })
  60. _this.soduko.push(arr)
  61. _this.styleList.push(JSON.parse(JSON.stringify(arr)))
  62. });
  63. },
  64. changeNumber(item,index,indexs) {
  65. let value = item.replace(/[^\d]/g, "")
  66. this.$set(this.soduko[index],indexs,value)
  67. },
  68. // 点击九宫格元素
  69. handleCheck(index,indexs){
  70. this.seletcItem = []
  71. this.seletcItem.push(index)
  72. this.seletcItem.push(indexs)
  73. },
  74. // 点击右侧数字
  75. handleClick(item){
  76. if(this.seletcItem.length>0){
  77. this.$set(this.soduko[this.seletcItem[0]],this.seletcItem[1],item)
  78. }
  79. },
  80. // 提交
  81. handleSubmit(){
  82. let _this = this
  83. _this.curQue.option.forEach((item,index) => {
  84. item.forEach((items,indexs)=>{
  85. if(!items.isHint){
  86. if(items.value &&_this.soduko[index][indexs] && _this.soduko[index][indexs] == items.value){
  87. this.$set(this.styleList[index],indexs,'right')
  88. }else if(items.value &&_this.soduko[index][indexs] && _this.soduko[index][indexs] != items.value){
  89. this.$set(this.styleList[index],indexs,'error')
  90. }
  91. }
  92. })
  93. });
  94. this.seletcItem = []
  95. }
  96. },
  97. //生命周期 - 创建完成(可以访问当前this实例)
  98. created() {
  99. this.handleData()
  100. },
  101. //生命周期 - 挂载完成(可以访问DOM元素)
  102. mounted() {},
  103. beforeCreate() {}, //生命周期 - 创建之前
  104. beforeMount() {}, //生命周期 - 挂载之前
  105. beforeUpdate() {}, //生命周期 - 更新之前
  106. updated() {}, //生命周期 - 更新之后
  107. beforeDestroy() {}, //生命周期 - 销毁之前
  108. destroyed() {}, //生命周期 - 销毁完成
  109. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  110. };
  111. </script>
  112. <style lang='scss' scoped>
  113. //@import url(); 引入公共css类
  114. .Big-Book-prev-Textdes{
  115. .sodu-inner{
  116. display: flex;
  117. border: 1px solid rgba(0, 0, 0, 0.1);
  118. border-radius: 8px;
  119. }
  120. .item-box{
  121. display: flex;
  122. flex-flow: wrap;
  123. width: 550px;
  124. border-bottom: 1px solid #000000;
  125. border-right: 1px solid #000000;
  126. margin: 24px;
  127. background: #E6E6E6;
  128. .item{
  129. display: flex;
  130. flex-flow: wrap;
  131. width: 183px;
  132. height: 183px;
  133. border-top: 1px solid #000000;
  134. border-left: 1px solid #000000;
  135. box-sizing: border-box;
  136. div{
  137. width: 60px;
  138. height: 60px;
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. border: 1px solid #FFFFFF;
  143. background: #FFFFFF;
  144. // border-bottom: 1px solid #E6E6E6;
  145. // border-right: 1px solid #E6E6E6;
  146. margin-bottom: 1px;
  147. margin-right: 1px;
  148. box-sizing: border-box;
  149. &.noBorder{
  150. // border-right: none;
  151. margin-right: 0px;
  152. }
  153. &.noBorder-bottom{
  154. // border-bottom: none;
  155. margin-bottom: 0px;
  156. }
  157. &.canClick:hover{
  158. border-color: #737373;
  159. }
  160. &.canClick.active{
  161. border-color: #0086FF;
  162. }
  163. &.right{
  164. background: #F5FFF9;
  165. border-color: #F5FFF9;
  166. p{
  167. color: #00BC4B;
  168. }
  169. }
  170. &.error{
  171. background: #FFF8F8;
  172. border-color: #FFF8F8;
  173. p{
  174. color: #DE4444;
  175. }
  176. }
  177. span{
  178. font-size: 16px;
  179. line-height: 150%;
  180. color: rgba(0, 0, 0, 0.85);
  181. font-family: 'robot';
  182. font-weight: 700;
  183. }
  184. p{
  185. width: 100%;
  186. height: 100%;
  187. text-align: center;
  188. color: #1890FF;
  189. font-size: 16px;
  190. font-weight: 700;
  191. font-family: 'robot';
  192. background: initial;
  193. line-height: 58px;
  194. margin: 0;
  195. cursor: pointer;
  196. }
  197. }
  198. }
  199. }
  200. .item-right{
  201. background: rgba(0, 0, 0, 0.04);
  202. width: 164px;
  203. padding: 12px 10px;
  204. ul{
  205. display: flex;
  206. flex-flow: wrap;
  207. li{
  208. width: 60px;
  209. height: 60px;
  210. background: #FFFFFF;
  211. border: 1px solid #E6E6E6;
  212. margin: 12px 6px;
  213. font-size: 20px;
  214. font-weight: bold;
  215. color: rgba(0, 0, 0, 0.85);
  216. font-family: 'robot';
  217. text-align: center;
  218. line-height: 60px;
  219. cursor: pointer;
  220. &:hover {
  221. border: 1px solid #0086FF;
  222. box-shadow: 0px 0px 0px 2px rgba(24, 144, 255, 0.5);
  223. }
  224. }
  225. }
  226. .resetBtn,.submitBtn{
  227. width: 132px;
  228. height: 40px;
  229. background: #DE4444;
  230. border: 1px solid rgba(0, 0, 0, 0.1);
  231. box-sizing: border-box;
  232. border-radius: 8px;
  233. color: #FFFFFF;
  234. text-align: center;
  235. line-height: 38px;
  236. font-size: 16px;
  237. display: block;
  238. margin: 0 auto;
  239. margin-top: 54px;
  240. }
  241. .submitBtn{
  242. background: #00BC4B;
  243. margin-top: 8px;
  244. }
  245. }
  246. }
  247. </style>