tki-float-keyboard.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template xlang="wxml" minapp="mpvue">
  2. <view class="_flkey-body" :class="[keyShowAni?'_floatAniIn':'_floatAniOut']" v-if='keyShow'>
  3. <view class="_flkey-bar">
  4. <view class="_flkey-bar-l" @tap="_keySwUp" hover-class="_float-hover-c">
  5. <view class="_flkey-bar-btn" v-show="mode == 'keyboard' && keyInputSkin">{{isUp?'小写':'大写'}}</view>
  6. </view>
  7. <view class="_flkey-bar-c">
  8. <view class="_flkey-bar-title">{{title}}</view>
  9. </view>
  10. <view class="_flkey-bar-r" @tap="_keyHide" hover-class="_float-hover-c">
  11. <view class="_flkey-bar-btn">完成</view>
  12. </view>
  13. </view>
  14. <view class="_flkey" v-show="mode != 'number'">
  15. <view class="_flkey-h" v-show="!keyInputSkin && mode == 'car'">
  16. <view class="_flkey-row">
  17. <view class="_flkey-i" :class="{'_flkey-noac':!provinceCP_}" :data-ac="provinceCP_" v-for="v in province.row_1" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  18. <view class="_flkey-i-b">
  19. {{v}}
  20. </view>
  21. </view>
  22. </view>
  23. <view class="_flkey-row">
  24. <view class="_flkey-i" :class="{'_flkey-noac':!provinceCP_}" :data-ac="provinceCP_" v-for="v in province.row_2" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  25. <view class="_flkey-i-b">
  26. {{v}}
  27. </view>
  28. </view>
  29. </view>
  30. <view class="_flkey-row">
  31. <view class="_flkey-i" :class="{'_flkey-noac':!provinceCP_}" :data-ac="provinceCP_" v-for="v in province.row_3" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  32. <view class="_flkey-i-b">
  33. {{v}}
  34. </view>
  35. </view>
  36. </view>
  37. <view class="_flkey-row">
  38. <view class="_flkey-i" :class="{'_flkey-noac':!provinceCP_}" :data-ac="provinceCP_" v-for="v in province.row_4" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  39. <view class="_flkey-i-b">
  40. {{v}}
  41. </view>
  42. </view>
  43. <view class="_flkey-i" :class="{'_flkey-noac':!specialCP_}" :data-ac="specialCP_" v-for="v in province.row_5" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  44. <view class="_flkey-i-b">
  45. {{v}}
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="_flkey-h" v-show="!keyInputSkin && mode == 'keyboard'">
  51. <view class="_flkey-row">
  52. <view class="_flkey-i" :class="{'_flkey-noac':!symbolCP_}" :data-ac="symbolCP_" v-for="v in symbol.row_1" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  53. <view class="_flkey-i-b">
  54. {{v}}
  55. </view>
  56. </view>
  57. </view>
  58. <view class="_flkey-row">
  59. <view class="_flkey-i" :class="{'_flkey-noac':!symbolCP_}" :data-ac="symbolCP_" v-for="v in symbol.row_2" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  60. <view class="_flkey-i-b">
  61. {{v}}
  62. </view>
  63. </view>
  64. </view>
  65. <view class="_flkey-row">
  66. <view class="_flkey-i" :class="{'_flkey-noac':!symbolCP_}" :data-ac="symbolCP_" v-for="v in symbol.row_3" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  67. <view class="_flkey-i-b">
  68. {{v}}
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="_flkey-n" v-show="keyInputSkin">
  74. <view class="_flkey-row">
  75. <view class="_flkey-i" :class="{'_flkey-noac':!numCp_}" :data-ac="numCp_" v-for="v in number" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  76. <view class="_flkey-i-b">
  77. {{v}}
  78. </view>
  79. </view>
  80. </view>
  81. <view class="_flkey-row">
  82. <view class="_flkey-i" :class="{'_flkey-noac':!letterCp_}" :data-ac="letterCp_" v-for="v in letter.row_1" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  83. <view class="_flkey-i-b">
  84. {{v}}
  85. </view>
  86. </view>
  87. </view>
  88. <view class="_flkey-row">
  89. <view class="_flkey-i" :class="{'_flkey-noac':!letterCp_}" :data-ac="letterCp_" v-for="v in letter.row_2" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  90. <view class="_flkey-i-b">
  91. {{v}}
  92. </view>
  93. </view>
  94. </view>
  95. <view class="_flkey-row">
  96. <view class="_flkey-i" :class="{'_flkey-noac':!letterCp_}" :data-ac="letterCp_" v-for="v in letter.row_3" :key="v" :data-v="v" @tap="_keyInput" hover-class="_float-hover-c">
  97. <view class="_flkey-i-b">
  98. {{v}}
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="_flkey-tool">
  104. <view class="_flkey-tool-i tool-i-a" :class="{'_flkey-noac':!swCp_}" @tap="_keyInputSw" hover-class="_float-hover-c">
  105. <view class="_flkey-tool-i-b">{{keyInputSkin?swTxtCp_[0]:swTxtCp_[1]}}</view>
  106. </view>
  107. <view class="_flkey-tool-i tool-i-del" @tap="_keyInputDel" hover-class="_float-hover-c">
  108. <view class="_flkey-tool-i-b">删除</view>
  109. </view>
  110. </view>
  111. </view>
  112. <view class="_flkey-number" v-show="mode == 'number'">
  113. <view class="_flkey-number-row">
  114. <view class="_flkey-number-row-i" data-v="1" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">1</view>
  115. <view class="_flkey-number-row-i" data-v="2" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">2</view>
  116. <view class="_flkey-number-row-i" data-v="3" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">3</view>
  117. </view>
  118. <view class="_flkey-number-row">
  119. <view class="_flkey-number-row-i" data-v="4" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">4</view>
  120. <view class="_flkey-number-row-i" data-v="5" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">5</view>
  121. <view class="_flkey-number-row-i" data-v="6" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">6</view>
  122. </view>
  123. <view class="_flkey-number-row">
  124. <view class="_flkey-number-row-i" data-v="7" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">7</view>
  125. <view class="_flkey-number-row-i" data-v="8" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">8</view>
  126. <view class="_flkey-number-row-i" data-v="9" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">9</view>
  127. </view>
  128. <view class="_flkey-number-row">
  129. <view class="_flkey-number-row-i _number-tool" data-v="." :class="{'_flkey-noac':!dotCp_}" :data-ac="dotCp_" @tap="_keyInput" hover-class="_float-hover-c">.</view>
  130. <view class="_flkey-number-row-i" data-v="0" :class="{'_flkey-noac':!digitCp_}" :data-ac="digitCp_" @tap="_keyInput" hover-class="_float-hover-c">0</view>
  131. <view class="_flkey-number-row-i _number-tool" hover-class="_float-hover-c" @tap="_keyInputDel">删除</view>
  132. </view>
  133. </view>
  134. <view class="_flkey-bot">
  135. </view>
  136. </view>
  137. </template>
  138. <script>
  139. export default {
  140. name: "tki-float-keyboard",
  141. props: {
  142. 'title': {
  143. type: [String],
  144. default: '',
  145. },
  146. 'type': {
  147. type: [Number, String],
  148. default: 0,
  149. },
  150. 'mode': {
  151. type: [String],
  152. default: 'keyboard', // keyboard 普通键盘 car 汽车键盘 number 数字键盘
  153. }
  154. },
  155. data() {
  156. return {
  157. isUp: false, // 是否是大写
  158. swTxt: true, // 键盘切换按钮是否可用
  159. keyShow: false,
  160. keyShowAni: true, // true 进入 false 隐藏
  161. keyInputSkin: true, // true 显示 字母和数字 false 显示汉子
  162. symbol: {
  163. row_1: ['+', '-', '*', '/', '=', '^', '<', '>', '(', ')'],
  164. row_2: ['?', '!', '@', '#', '$', '&', ',', '.', '[', ']'],
  165. row_3: [':', ';', '\'', '"', '_', '~', '…'],
  166. },
  167. province: {
  168. row_1: ["京", "津", "沪", "渝", "蒙", "新", "藏", "宁", "桂", "黑"],
  169. row_2: ["吉", "辽", "晋", "冀", "青", "鲁", "豫", "苏", "皖", "浙"],
  170. row_3: ["闽", "赣", "湘", "鄂", "粤", "琼", "甘", "陕", "云", "贵"],
  171. row_4: ["川"],
  172. row_5: ["港", "澳", "学", "警", "领", "使"],
  173. },
  174. number: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
  175. letter: {
  176. row_1: ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
  177. row_2: ["A", "S", "D", "F", "G", "H", "J", "K", "L"],
  178. row_3: ["Z", "X", "C", "V", "B", "N", "M"],
  179. },
  180. symbolCP_: true,
  181. provinceCP_: true,
  182. specialCP_: true,
  183. numCp_: true,
  184. letterCp_: true,
  185. digitCp_: true,
  186. dotCp_: true,
  187. swCp_: true,
  188. swTxtCp_: ['省', 'ABC'],
  189. }
  190. },
  191. methods: {
  192. _keyInit() {
  193. if (this.mode == 'keyboard') {
  194. this.isUp = true
  195. this._keyTypeWacth(this.keyType)
  196. this._keySwUp()
  197. }
  198. if (this.mode == 'car') {
  199. this.isUp = false
  200. this._carTypeWacth(this.carType)
  201. this._keySwUp()
  202. }
  203. if (this.mode == 'number') {
  204. this._numberTypeWacth(this.numberType)
  205. }
  206. },
  207. _keySwUp(t) {
  208. if (this.mode != 'number' && this.keyInputSkin) {
  209. // 大小写切换
  210. for (const key in this.letter) {
  211. if (this.letter.hasOwnProperty(key)) {
  212. for (let index = 0; index < this.letter[key].length; index++) {
  213. if (!this.isUp) {
  214. let tp = this.letter[key][index].toUpperCase()
  215. this.letter[key][index] = tp
  216. } else {
  217. let tp = this.letter[key][index].toLowerCase()
  218. this.letter[key][index] = tp
  219. }
  220. }
  221. }
  222. }
  223. this.isUp = !this.isUp
  224. }
  225. },
  226. _keyInput(e) {
  227. let d = e.currentTarget.dataset
  228. if (d.ac) {
  229. this.$emit('val', String(d.v))
  230. }
  231. },
  232. _keyInputDel() {
  233. this.$emit('del', true)
  234. },
  235. _keyInputSw() {
  236. let that = this;
  237. if (that.swCp_) {
  238. that.keyInputSkin = !that.keyInputSkin
  239. }
  240. },
  241. _keyShow() {
  242. let that = this
  243. uni.hideKeyboard()
  244. that.keyShow = true
  245. that.keyShowAni = true
  246. setTimeout(() => {
  247. uni.createSelectorQuery().in(that).select('._flkey-body').boundingClientRect(function (rect) {
  248. that.$emit('show', rect)
  249. }).exec()
  250. }, 150);
  251. },
  252. _keyHide() {
  253. let that = this
  254. that.keyShowAni = false
  255. setTimeout(() => {
  256. that.$emit('hide', true)
  257. that.keyShow = false
  258. }, 166);
  259. },
  260. _carTypeWacth(n) {
  261. let v = Number(n)
  262. // 0 全部
  263. // 1 字母加数字
  264. // 2 省
  265. // 3 字母加数字加特
  266. // 4 字母
  267. // 5 数字
  268. switch (v) {
  269. case 0:
  270. this.provinceCP_ = true
  271. this.specialCP_ = true
  272. this.numCp_ = true
  273. this.letterCp_ = true
  274. this.swCp_ = true
  275. this.swTxtCp_ = ['省', 'ABC']
  276. this.keyInputSkin = true
  277. break;
  278. case 1:
  279. this.provinceCP_ = false
  280. this.specialCP_ = false
  281. this.numCp_ = true
  282. this.letterCp_ = true
  283. this.swCp_ = false
  284. this.swTxtCp_ = ['省', 'ABC']
  285. this.keyInputSkin = true
  286. break;
  287. case 2:
  288. this.provinceCP_ = true
  289. this.specialCP_ = false
  290. this.numCp_ = false
  291. this.letterCp_ = false
  292. this.swCp_ = false
  293. this.swTxtCp_ = ['省', 'ABC']
  294. this.keyInputSkin = false
  295. break;
  296. case 3:
  297. this.provinceCP_ = false
  298. this.specialCP_ = true
  299. this.numCp_ = true
  300. this.letterCp_ = true
  301. this.swCp_ = true
  302. this.swTxtCp_ = ['特', 'ABC']
  303. this.keyInputSkin = true
  304. break;
  305. case 4:
  306. this.provinceCP_ = false
  307. this.specialCP_ = false
  308. this.numCp_ = false
  309. this.letterCp_ = true
  310. this.swCp_ = false
  311. this.swTxtCp_ = ['省', 'ABC']
  312. this.keyInputSkin = true
  313. break;
  314. case 5:
  315. this.provinceCP_ = false
  316. this.specialCP_ = false
  317. this.numCp_ = true
  318. this.letterCp_ = false
  319. this.swCp_ = false
  320. this.swTxtCp_ = ['省', 'ABC']
  321. this.keyInputSkin = true
  322. break;
  323. default:
  324. this.provinceCP_ = true
  325. this.specialCP_ = true
  326. this.numCp_ = true
  327. this.letterCp_ = true
  328. this.swCp_ = true
  329. this.swTxtCp_ = ['省', 'ABC']
  330. this.keyInputSkin = true
  331. break;
  332. }
  333. },
  334. _keyTypeWacth(n) {
  335. let v = Number(n)
  336. // 0 全部
  337. // 1 字母加数字
  338. // 2 符号
  339. // 3 字母
  340. // 4 数字
  341. // 5 字母加符号
  342. // 6 数字加符号
  343. switch (v) {
  344. case 0:
  345. this.symbolCP_ = true
  346. this.numCp_ = true
  347. this.letterCp_ = true
  348. this.swCp_ = true
  349. this.swTxtCp_ = ['符', 'ABC']
  350. this.keyInputSkin = true
  351. break;
  352. case 1:
  353. this.symbolCP_ = false
  354. this.numCp_ = true
  355. this.letterCp_ = true
  356. this.swCp_ = false
  357. this.swTxtCp_ = ['符', 'ABC']
  358. this.keyInputSkin = true
  359. break;
  360. case 2:
  361. this.symbolCP_ = true
  362. this.numCp_ = false
  363. this.letterCp_ = false
  364. this.swCp_ = false
  365. this.swTxtCp_ = ['符', 'ABC']
  366. this.keyInputSkin = false
  367. break;
  368. case 3:
  369. this.symbolCP_ = false
  370. this.numCp_ = false
  371. this.letterCp_ = true
  372. this.swCp_ = false
  373. this.swTxtCp_ = ['符', 'ABC']
  374. this.keyInputSkin = true
  375. break;
  376. case 4:
  377. this.symbolCP_ = false
  378. this.numCp_ = true
  379. this.letterCp_ = false
  380. this.swCp_ = false
  381. this.swTxtCp_ = ['符', 'ABC']
  382. this.keyInputSkin = true
  383. break;
  384. case 5:
  385. this.symbolCP_ = true
  386. this.numCp_ = false
  387. this.letterCp_ = true
  388. this.swCp_ = true
  389. this.swTxtCp_ = ['符', 'ABC']
  390. this.keyInputSkin = true
  391. break;
  392. case 6:
  393. this.symbolCP_ = true
  394. this.numCp_ = true
  395. this.letterCp_ = false
  396. this.swCp_ = true
  397. this.swTxtCp_ = ['符', 'ABC']
  398. this.keyInputSkin = true
  399. break;
  400. default:
  401. this.symbolCP_ = true
  402. this.numCp_ = true
  403. this.letterCp_ = true
  404. this.swCp_ = true
  405. this.swTxtCp_ = ['符', 'ABC']
  406. this.keyInputSkin = true
  407. break;
  408. }
  409. },
  410. _numberTypeWacth(n) {
  411. let v = Number(n)
  412. // 0 全部
  413. // 1 禁用.
  414. switch (v) {
  415. case 0:
  416. this.digitCp_ = true
  417. this.dotCp_ = true
  418. break;
  419. case 1:
  420. this.digitCp_ = true
  421. this.dotCp_ = false
  422. break;
  423. default:
  424. this.digitCp_ = true
  425. this.dotCp_ = true
  426. break;
  427. }
  428. }
  429. },
  430. computed: {
  431. },
  432. watch: {
  433. type(n, o) {
  434. if (this.mode == 'car') {
  435. this._carTypeWacth(n)
  436. }
  437. if (this.mode == 'keyboard') {
  438. this._keyTypeWacth(n)
  439. }
  440. if (this.mode == 'number') {
  441. this._numberTypeWacth(n)
  442. }
  443. },
  444. mode(n, o) {
  445. if (n != o) {
  446. this._keyInit()
  447. }
  448. }
  449. },
  450. created() {
  451. this._keyInit()
  452. },
  453. }
  454. </script>
  455. <style>
  456. @import "style.css";
  457. </style>