tm-password.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="tm-password ">
  3. <view @click="show=!show" class="flex-center flex-between">
  4. <view class="tm-password-item flex-center "
  5. :class="[
  6. width>0?'':'mx-12',
  7. `round-${round}`,
  8. `shadow-${color_tmeme}-${shadow}`,
  9. model==='line'?black_tmeme?(strVal.length==index?' grey-darken-3 ':'border-grey-a-1 grey-darken-3 '):`border-${color_tmeme}-b-3`:'',
  10. model==='box'?(black_tmeme?(strVal.length==index?'grey-darken-3 ':'border-grey-a-1 grey-darken-3 '):(strVal.length==index?'':`border-${color_tmeme}-a-1 `)):'',
  11. model==='fill'?black_tmeme?'grey-darken-3 ':bgColor:'',
  12. ]"
  13. v-for="(item,index) in strLength"
  14. :key="index"
  15. :style="{
  16. width:width>0?'auto':(100/strLength)+'%',
  17. height:height+'rpx'
  18. }"
  19. >
  20. <view
  21. :style="{width:width>0?width+'rpx':'atuo'}"
  22. :class="[
  23. `round-${round}`,
  24. strVal.length==index?'aniOn '+(model!=='line'&&model!=='box'?`border-${color_tmeme}-a-2 shadow-${color_tmeme}-6`:''):'',
  25. strVal.length==index?(model=='box'?`border-${color_tmeme}-a-2 shadow-${color_tmeme}-6`:''):'',
  26. strVal.length==index?(model=='line'&&black_tmeme?`border-${color_tmeme}-a-2 shadow-${color_tmeme}-6`:''):'',
  27. ]" class=" fulled fulled-height flex-center">
  28. <text v-if="strVal[index]&&showVal"
  29. class="text-weight-b text-size-lg"
  30. :class="[
  31. black_tmeme?'text-white':`text-${textColor_tmeme}`
  32. ]"
  33. >
  34. {{strVal[index]?strVal[index]:""}}
  35. </text>
  36. <view
  37. v-if="(strVal[index]&&!showVal)||(!strVal[index]&&showVal)"
  38. class="tm-password-item-middle "
  39. :class="[
  40. noval==='mline'?'mline round-5 ':'',
  41. noval==='round'?'mround rounded':'',
  42. 'tm-password-item-middle-w',
  43. textColor_tmeme
  44. ]"
  45. ></view>
  46. </view>
  47. </view>
  48. </view>
  49. <tm-keyborad @confirm="$emit('confirm',strVal)" :ok-color="color_tmeme" :model="keyboradModel" :black="black_tmeme" v-model="strVal" :decimal="false" :show.sync="show"></tm-keyborad>
  50. </view>
  51. </template>
  52. <script>
  53. /**
  54. * 密码、验证码输入框
  55. * @property {String|Number} value = [] 默认:'',待输入内容,推荐使用v-model,或者value.sync
  56. * @property {String|Number} round = [] 默认:4,圆角
  57. * @property {String|Number} width = [] 默认:0,项目的宽,默认使用百分比的宽度。
  58. * @property {String|Number} height = [] 默认:100,项目的宽
  59. * @property {String|Number} shadow = [] 默认:0,投影
  60. * @property {Number} code-length = [] 默认:4,输入框数
  61. * @property {String} model = [line|box|fill] 默认:fill,外框的样式。line|box|fill
  62. * @property {String} noval = [mline|round] 默认:round,中间未填充数据的样式。。mline|round
  63. * @property {Boolean} show-val = [] 默认:false,是否展现/隐藏输入内容
  64. * @property {Boolean} black = [] 默认:false,暗黑模式
  65. * @property {String} color = [] 默认:primary,主题色
  66. * @property {String} bg-color = [] 默认:grey-lighten-4,输入背景主题色
  67. * @property {String} text-color = [] 默认:primary,文字颜色。
  68. * @property {String} keyborad-model = [number|password] 默认:number,键盘类型:number|password
  69. * @property {Function} input 输入内容时触发。
  70. * @property {Function} confirm 输入完内容,点击确认时触发
  71. * @example <tm-password v-model="num"></tm-password>
  72. */
  73. import tmKeyborad from "@/tm-vuetify/components/tm-keyborad/tm-keyborad.vue"
  74. export default {
  75. components:{tmKeyborad},
  76. name:"tm-password",
  77. model:{
  78. prop:'value',
  79. event:'input'
  80. },
  81. props:{
  82. value:{
  83. type:String|Number,
  84. default:''
  85. },
  86. codeLength:{
  87. type:Number,
  88. default:4
  89. },
  90. round:{
  91. type:Number,
  92. default:4
  93. },
  94. shadow:{
  95. type:Number,
  96. default:0
  97. },
  98. bgColor:{
  99. type:String,
  100. default:'grey-lighten-4'
  101. },
  102. height:{
  103. type:Number,
  104. default:100
  105. },
  106. width:{
  107. type:Number,
  108. default:0
  109. },
  110. // 外框的样式。
  111. model:{
  112. type:String,
  113. default:'fill' //外形形状 line|box|fill
  114. },
  115. // 中间未填充数据的样式。
  116. noval:{
  117. type:String,
  118. default:'round' //mline|round
  119. },
  120. // 是否展现内容
  121. showVal:{
  122. type:Boolean,
  123. default:false
  124. },
  125. black:{
  126. type:Boolean|String,
  127. default:null
  128. },
  129. color:{
  130. type:String,
  131. default:'primary'
  132. },
  133. textColor:{
  134. type:String,
  135. default:'grey-darken-3'
  136. },
  137. keyboradModel:{
  138. type:String,
  139. default:'number' //number|password
  140. },
  141. // 跟随主题色的改变而改变。
  142. fllowTheme:{
  143. type:Boolean|String,
  144. default:false
  145. }
  146. },
  147. computed:{
  148. black_tmeme: function() {
  149. if (this.black !== null) return this.black;
  150. return this.$tm.vx.state().tmVuetify.black;
  151. },
  152. color_tmeme:function(){
  153. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  154. return this.$tm.vx.state().tmVuetify.color;
  155. }
  156. return this.color;
  157. },
  158. textColor_tmeme:function(){
  159. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  160. return this.$tm.vx.state().tmVuetify.color;
  161. }
  162. return this.textColor;
  163. },
  164. strLength:function(){
  165. if(this.codeLength==0||!this.codeLength) return 1;
  166. return this.codeLength;
  167. },
  168. strVal:{
  169. get:function(){
  170. return this.value;
  171. },
  172. set:function(val){
  173. let p = val;
  174. if(val.length > this.strLength){
  175. p = val.substr(0,this.strLength);;
  176. }
  177. this.$emit("input",p )
  178. this.$emit("update:value",p )
  179. }
  180. },
  181. // strCode:function(){
  182. // let val = this.strVal;
  183. // let strlen = this.strLength - this.strVal.length;
  184. // for(let i=0;i<strlen;i++){
  185. // }
  186. // }
  187. },
  188. data() {
  189. return {
  190. show:false
  191. };
  192. }
  193. }
  194. </script>
  195. <style lang="scss">
  196. .tm-password{
  197. .tm-password-item{
  198. height: 100rpx;
  199. .aniOn{
  200. animation: easinOut 1.5s infinite linear;
  201. }
  202. .tm-password-item-middle{
  203. &.mline{
  204. width: 100%;
  205. height: 10upx;
  206. }
  207. &.mround{
  208. width: 20upx;
  209. height: 20upx;
  210. }
  211. &.tm-password-item-middle-w{
  212. width: 20upx;
  213. }
  214. }
  215. }
  216. }
  217. @keyframes easinOut {
  218. 0% {
  219. opacity: 1;
  220. }
  221. 50% {
  222. opacity: 0.4;
  223. }
  224. 100% {
  225. opacity: 1;
  226. }
  227. }
  228. </style>