tki-float-keyboard.vue 14 KB

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