tm-keyborad.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view class="tm-keyborad ">
  3. <tm-poup isClickbled :isFilter="false" over-color='none'
  4. :height="530" ref="pop"
  5. :bg-color="black_tmeme?'grey-darken-5':'grey-lighten-5'"
  6. v-model="showOpen">
  7. <view>
  8. <view v-if="model_code=='number'||model_code=='code'" class="tm-keyborad-html">
  9. <view class=" py-10" :class="[black_tmeme?'grey-darken-5':'grey-lighten-5']">
  10. <view class="text-size-xs text-align-center pb-20 pt-10 text-weight-b">
  11. <slot>
  12. <text>{{title}}</text>
  13. </slot>
  14. </view>
  15. <tm-row custom-class="px-5">
  16. <tm-col grid="3" padding="5" color="none">
  17. <tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(1,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">1</tm-button>
  18. </tm-col>
  19. <tm-col grid="3" padding="5" color="none">
  20. <tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(2,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">2</tm-button>
  21. </tm-col>
  22. <tm-col grid="3" padding="5" color="none">
  23. <tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(3,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">3</tm-button>
  24. </tm-col>
  25. <tm-col grid="3" padding="5" color="none">
  26. <tm-button :fontSize="42" :iconSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(null,'del')" icon="icon-caret-left" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" :font-color="black?'grey':'black'" height="100"></tm-button>
  27. </tm-col>
  28. </tm-row>
  29. <tm-row align="flex-start">
  30. <tm-col grid="9" color="none" custom-class="px-5">
  31. <tm-row>
  32. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(4,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">4</tm-button></tm-col>
  33. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(5,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">5</tm-button></tm-col>
  34. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(6,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">6</tm-button></tm-col>
  35. </tm-row>
  36. <tm-row>
  37. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(7,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">7</tm-button></tm-col>
  38. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(8,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">8</tm-button></tm-col>
  39. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(9,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">9</tm-button></tm-col>
  40. </tm-row>
  41. <tm-row v-if="model_code=='number'">
  42. <tm-col :grid="decimal?4:8" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(0,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">0</tm-button></tm-col>
  43. <tm-col v-if="decimal" grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo('.','dian')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">.</tm-button></tm-col>
  44. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(null,'cancel')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">关闭</tm-button></tm-col>
  45. </tm-row>
  46. <tm-row v-if="model_code=='code'">
  47. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(0,'num')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">0</tm-button></tm-col>
  48. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo('x','code-x')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">X</tm-button></tm-col>
  49. <tm-col grid="4" padding="5" color="none"><tm-button :fontSize="42" :fllowTheme="false" item-class="text-weight-b" @click="clickNumo(null,'cancel')" :black="black_tmeme" :round="round" block :shadow="shadown" :theme="black_tmeme?'grey-darken-4':color" height="100">关闭</tm-button></tm-col>
  50. </tm-row>
  51. </tm-col>
  52. <tm-col grid="3" color="none" custom-class="mt-5 mr-5">
  53. <tm-button :fontSize="42" item-class="text-weight-b" :round="round" label="确认" :theme="okColor" @click.stop="clickNumo(null,'confirm')" block :shadow="shadown" height="312"></tm-button>
  54. </tm-col>
  55. </tm-row>
  56. </view>
  57. </view>
  58. <view v-if="model_code=='car'" class="tm-keyborad-html">
  59. <view class=" py-10" :class="[black_tmeme?'grey-darken-5':'grey-lighten-5']">
  60. <view class="text-size-xs text-align-center pb-20 pt-10 text-weight-b">
  61. <slot>
  62. <text>{{title}}</text>
  63. </slot>
  64. </view>
  65. <tm-row custom-class="px-5">
  66. <tm-col grid="10" color="none">
  67. <tm-row >
  68. <block v-for="(item,index) in chepai[enIndex]" :key="index">
  69. <tm-col width="12.5%" padding="5" color="none">
  70. <tm-button :fontSize="32" :iconSize="32" :fllowTheme="false" item-class="text-weight-b"
  71. @click="clickNumo(item,'car')"
  72. :black="black_tmeme" :round="round"
  73. block :shadow="shadown"
  74. :theme="black_tmeme?'grey-darken-4':color"
  75. height="80">
  76. {{item}}
  77. </tm-button>
  78. </tm-col>
  79. </block>
  80. </tm-row>
  81. </tm-col>
  82. <tm-col grid="2" color="none">
  83. <tm-row>
  84. <tm-col grid="12" padding="5" color="none">
  85. <tm-button :fontSize="32" :iconSize="32" :fllowTheme="false" item-class="text-weight-b"
  86. @click="clickNumo(null,'del')" icon="icon-caret-left"
  87. :black="black_tmeme" :round="round"
  88. block shadow="0"
  89. theme="red"
  90. font-color="red"
  91. text
  92. height="80">
  93. </tm-button>
  94. </tm-col>
  95. <tm-col grid="12" padding="5" color="none">
  96. <tm-button item-class="text-weight-b"
  97. @click="clickNumo(null,'cancel')"
  98. :black="black_tmeme" :round="round"
  99. block shadow="0"
  100. :theme="okColor"
  101. :fontSize="32" :iconSize="32"
  102. text
  103. height="80">
  104. 关闭
  105. </tm-button>
  106. </tm-col>
  107. <tm-col grid="12" padding="5" color="none">
  108. <tm-button item-class="text-weight-b"
  109. @click="clickNumo(null,'car-zh')"
  110. :black="black_tmeme" :round="round"
  111. block :shadow="0"
  112. :theme="okColor"
  113. text
  114. :fontSize="32" :iconSize="32"
  115. height="80">
  116. 中/英
  117. </tm-button>
  118. </tm-col>
  119. <tm-col grid="12" padding="5" color="none">
  120. <tm-button item-class="text-weight-b"
  121. @click="clickNumo(null,'confirm')"
  122. :round="round"
  123. block :shadow="shadown"
  124. :theme="okColor"
  125. :fontSize="32" :iconSize="32"
  126. height="133">
  127. 确认
  128. </tm-button>
  129. </tm-col>
  130. </tm-row>
  131. </tm-col>
  132. </tm-row>
  133. </view>
  134. </view>
  135. <view v-if="model_code=='password'" class="tm-keyborad-html">
  136. <view class=" py-10" :class="[black_tmeme?'grey-darken-5':'grey-lighten-5']">
  137. <view class="text-size-xs text-align-center pb-20 pt-10 text-weight-b">
  138. <slot>
  139. <text>{{title}}</text>
  140. </slot>
  141. </view>
  142. <tm-row custom-class="px-5">
  143. <tm-col grid="10" color="none">
  144. <tm-row >
  145. <block v-for="(item,index) in password[enIndex]" :key="index">
  146. <tm-col width="12.5%" padding="5" color="none">
  147. <tm-button :fllowTheme="false" item-class="text-weight-b"
  148. @click="clickNumo(item,'password')"
  149. :black="black_tmeme" :round="round"
  150. block :shadow="shadown"
  151. :fontSize="32" :iconSize="32"
  152. :theme="black_tmeme?'grey-darken-4':color"
  153. height="80">
  154. {{item}}
  155. </tm-button>
  156. </tm-col>
  157. </block>
  158. </tm-row>
  159. </tm-col>
  160. <tm-col grid="2" color="none">
  161. <tm-row>
  162. <tm-col grid="12" padding="5" color="none">
  163. <tm-button :fllowTheme="false" item-class="text-weight-b"
  164. @click.stop="clickNumo(null,'del')" icon="icon-caret-left"
  165. :black="black_tmeme" :round="round"
  166. block shadow="0"
  167. theme="red"
  168. font-color="red"
  169. text
  170. :fontSize="32" :iconSize="32"
  171. height="80">
  172. </tm-button>
  173. </tm-col>
  174. <tm-col grid="12" padding="5" color="none">
  175. <tm-button item-class="text-weight-b"
  176. @click.stop="clickNumo(null,'cancel')"
  177. :black="black_tmeme" :round="round"
  178. block shadow="0"
  179. :theme="okColor"
  180. :fontSize="32" :iconSize="32"
  181. text
  182. height="80">
  183. 关闭
  184. </tm-button>
  185. </tm-col>
  186. <tm-col grid="12" padding="5" color="none">
  187. <tm-button item-class="text-weight-b"
  188. @click.stop="clickNumo(null,'password-fh')"
  189. :black="black_tmeme" :round="round"
  190. block :shadow="0"
  191. :theme="okColor"
  192. text
  193. :fontSize="32" :iconSize="32"
  194. height="80">
  195. 英/符
  196. </tm-button>
  197. </tm-col>
  198. <tm-col grid="12" padding="5" color="none">
  199. <tm-button item-class="text-weight-b"
  200. @click.stop="clickNumo(null,'confirm')"
  201. :round="round"
  202. block :shadow="shadown"
  203. :theme="okColor"
  204. :fontSize="32" :iconSize="32"
  205. height="133">
  206. 确认
  207. </tm-button>
  208. </tm-col>
  209. </tm-row>
  210. </tm-col>
  211. </tm-row>
  212. </view>
  213. </view>
  214. <!-- #ifdef H5 -->
  215. <view style="height: var(--window-bottom);"></view>
  216. <!-- #endif -->
  217. </view>
  218. </tm-poup>
  219. </view>
  220. </template>
  221. <script>
  222. /**
  223. * 输入键盘
  224. * @description 输入键盘分为:数字键盘,身份键盘,车牌键盘,密码键盘。
  225. * @property {String|Number} value = [] 默认:'',推荐使用v-model,也可使用value.sync双向绑定.
  226. * @property {Boolean} show = [] 默认:false,显示键盘,请使用show.sync双向绑定
  227. * @property {String} color = [] 默认:white,通用按钮主题色。
  228. * @property {String} title = [] 默认:'安全键盘放心输入',键盘顶部标题文字。
  229. * @property {String} ok-color = [] 默认:primary, 确认按钮的主题色
  230. * @property {Number} round = [] 默认:2, 按钮圆角。
  231. * @property {Number} shadown = [] 默认:5, 按钮按钮投影
  232. * @property {Boolean} black = [] 默认:false, 暗黑模式。
  233. * @property {Boolean} decimal = [] 默认:true, 是否显示小数点。
  234. * @property {String} model = [number|code|car|password] 默认:'number', 键盘类型数字键盘,身份证,车牌,密码number|code|car|password
  235. * @property {Function} confirm 点击确认或者返回时触发。
  236. * @example <tm-keyborad v-model="num" :show.sync="show"></tm-keyborad>
  237. */
  238. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  239. import tmButton from "@/tm-vuetify/components/tm-button/tm-button.vue"
  240. import tmRow from "@/tm-vuetify/components/tm-row/tm-row.vue"
  241. import tmCol from "@/tm-vuetify/components/tm-col/tm-col.vue"
  242. import tmPoup from "@/tm-vuetify/components/tm-poup/tm-poup.vue"
  243. export default {
  244. components:{tmIcons,tmButton,tmRow,tmCol,tmPoup},
  245. name:"tm-keyborad",
  246. model:{
  247. prop:'value',
  248. event:'input'
  249. },
  250. props:{
  251. value:{
  252. type:String|Number,
  253. default:''
  254. },
  255. // 键盘顶部标题文字。
  256. title:{
  257. type:String,
  258. default:'安全键盘放心输入'
  259. },
  260. show:{
  261. type:Boolean,
  262. default:false
  263. },
  264. // 通用按钮主题色。
  265. color:{
  266. type:String,
  267. default:'white'
  268. },
  269. // 确认按钮的主题色
  270. okColor:{
  271. type:String,
  272. default:'primary'
  273. },
  274. // 按钮圆角。
  275. round:{
  276. type:Number,
  277. default:3
  278. },
  279. // 按钮投影
  280. shadown:{
  281. type:Number,
  282. default:5
  283. },
  284. black:{
  285. type:Boolean,
  286. default:null
  287. },
  288. // 是否显示小数点。
  289. decimal:{
  290. type:Boolean,
  291. default:true
  292. },
  293. // 键盘类型数字键盘,身份证,车牌,密码
  294. model:{
  295. type:String,
  296. default:'number' //number|code|car|password
  297. },
  298. },
  299. computed:{
  300. black_tmeme: function() {
  301. if (this.black !== null) return this.black;
  302. return this.$tm.vx.state().tmVuetify.black;
  303. },
  304. model_code:function(){
  305. return this.model;
  306. }
  307. },
  308. watch:{
  309. show:function(val){
  310. this.showOpen = val;
  311. }
  312. },
  313. created() {
  314. this.showOpen = this.show
  315. },
  316. mounted() {
  317. },
  318. data() {
  319. return {
  320. showOpen:false,
  321. enIndex:0,
  322. chepai:[
  323. [
  324. '京','沪','津','渝','鲁','冀','晋','蒙','辽','吉','黑','苏','浙',
  325. '皖','闽','赣','豫','湘','鄂','粤','桂','琼','川','贵','云','藏',
  326. '陕','甘','青','宁','新','港','澳','台','新','使','学'
  327. ],
  328. [
  329. '1','2','A','B','C','D','E','F',
  330. '3','4','G','H','I','J','K','L',
  331. '5','6','M','N','O','P','Q','R',
  332. '7','8','S','T','U','V','W','X',
  333. '9','0','Y','Z'
  334. ]
  335. ],
  336. password:[
  337. [
  338. '1','2','A','B','C','D','E','F',
  339. '3','4','G','H','I','J','K','L',
  340. '5','6','M','N','O','P','Q','R',
  341. '7','8','S','T','U','V','W','X',
  342. '9','0','Y','Z'
  343. ],
  344. [
  345. '\"',"\'",'.','/',"\\",']','[','!','?','_','<','>','%',';',')','(','&','+','=','~','*','#','@'
  346. ]
  347. ],
  348. };
  349. },
  350. methods: {
  351. clickNumo(val,type){
  352. let oval = this.value;
  353. if(type=='del'){
  354. oval = oval.length<=0?'':oval.substring(0,oval.length-1)
  355. }else if(type=='num' || type=='code-x'|| type=='car' || type == 'password'){
  356. oval= oval +'' + val;
  357. }else if(type=='dian'){
  358. if(oval.indexOf('.')>-1 || !oval || oval.length==0){
  359. return;
  360. }
  361. oval= oval +'' + val;
  362. }else if(type=='car-zh'||type=='password-fh'){
  363. this.enIndex= this.enIndex?0:1
  364. }
  365. if(type == 'confirm' || type=='cancel'){
  366. if(this.model_code=='number'){
  367. if(oval.substring(oval.length-1)=='.'){
  368. oval = oval.substring(0,oval.length-1);
  369. }
  370. }
  371. this.$emit('update:show',false);
  372. if(type=='confirm'){
  373. this.$emit('input',oval.toUpperCase())
  374. this.$emit('update:value',oval.toUpperCase())
  375. this.$emit('confirm',this.value);
  376. }
  377. return;
  378. }
  379. this.$emit('input',oval.toUpperCase())
  380. this.$emit('update:value',oval.toUpperCase())
  381. // #ifdef MP || APP
  382. uni.vibrateShort({})
  383. // #endif
  384. },
  385. },
  386. }
  387. </script>
  388. <style lang="scss" scoped>
  389. </style>