com-input.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view>
  3. <view class="mix-list-cell" :class="border" hover-class="cell-hover" :hover-stay-time="50">
  4. <text class="cell-tit">{{title}}</text>
  5. <input class="main-input" :value="value" :type="_type" placeholder-class="placeholder-class"
  6. :maxlength="maxlength" :placeholder="placeholder" :password="type==='password'&&!showPassword"
  7. @input="onInput" :disabled="readOnly" />
  8. <!-- 是否可见密码 -->
  9. <image v-if="_isShowPass&&type==='password'&&!_isShowCode" class="img cuIcon"
  10. :class="showPassword?'cuIcon-attention':'cuIcon-attentionforbid'" @tap="showPass"></image>
  11. <!-- 倒计时 -->
  12. <view v-if="_isShowCode&&!_isShowPass" :class="['vercode',{'vercode-run': second>0}]" @click="setCode">
  13. {{ getVerCodeSecond }}
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. var _this, countDown;
  20. /**
  21. * 简单封装了下, 应用范围比较狭窄,可以在此基础上进行扩展使用
  22. * 比如加入image, iconSize可控等
  23. */
  24. export default {
  25. data() {
  26. return {
  27. showPassword: false, //是否显示明文
  28. second: 0, //倒计时
  29. isRunCode: false, //是否开始倒计时
  30. typeList: {
  31. left: 'icon-zuo',
  32. right: 'icon-you',
  33. up: 'icon-shang',
  34. down: 'icon-xia'
  35. },
  36. }
  37. },
  38. props: {
  39. readOnly: {
  40. //是否显示获取验证码(二选一)
  41. type: [Boolean, String],
  42. default: false,
  43. },
  44. type: String, //类型
  45. logo: String, //类型
  46. value: String, //值
  47. placeholder: {
  48. type: String,
  49. default: ''
  50. }, //框内提示
  51. isShowCode: {
  52. //是否显示获取验证码(二选一)
  53. type: [Boolean, String],
  54. default: false,
  55. },
  56. codeText: {
  57. type: String,
  58. default: "获取验证码",
  59. },
  60. setTime: {
  61. //倒计时时间设置
  62. type: [Number, String],
  63. default: 60,
  64. },
  65. maxlength: {
  66. //最大长度
  67. type: [Number, String],
  68. default: 30,
  69. },
  70. isShowPass: {
  71. //是否显示密码图标(二选一)
  72. type: [Boolean, String],
  73. default: false,
  74. },
  75. icon: {
  76. type: String,
  77. default: ''
  78. },
  79. title: {
  80. type: String,
  81. default: '标题'
  82. },
  83. tips: {
  84. type: String,
  85. default: ''
  86. },
  87. navigateType: {
  88. type: String,
  89. default: 'right'
  90. },
  91. border: {
  92. type: String,
  93. default: 'b-b'
  94. },
  95. hoverClass: {
  96. type: String,
  97. default: 'cell-hover'
  98. },
  99. iconColor: {
  100. type: String,
  101. default: '#333'
  102. }
  103. },
  104. mounted() {
  105. _this = this
  106. //准备触发
  107. this.$on('runCodes', (val) => {
  108. this.runCodes(val);
  109. });
  110. clearInterval(countDown); //先清理一次循环,避免缓存
  111. },
  112. methods: {
  113. showPass() {
  114. //是否显示密码
  115. this.showPassword = !this.showPassword
  116. },
  117. onInput(e) {
  118. //传出值
  119. this.$emit('input', e.target.value)
  120. },
  121. setCode() {
  122. //设置获取验证码的事件
  123. if (this.isRunCode) {
  124. //判断是否开始倒计时,避免重复点击
  125. return false;
  126. }
  127. this.$emit('setCode')
  128. },
  129. runCodes(val) {
  130. console.error("runCodes")
  131. //开始倒计时
  132. if (String(val) == "0") {
  133. //判断是否需要终止循环
  134. this.second = 0; //初始倒计时
  135. clearInterval(countDown); //清理循环
  136. this.isRunCode = false; //关闭循环状态
  137. return false;
  138. }
  139. if (this.isRunCode) {
  140. //判断是否开始倒计时,避免重复点击
  141. return false;
  142. }
  143. this.isRunCode = true
  144. this.second = this._setTime //倒数秒数
  145. let _this = this;
  146. countDown = setInterval(function() {
  147. _this.second--
  148. if (_this.second == 0) {
  149. _this.isRunCode = false
  150. clearInterval(countDown)
  151. }
  152. }, 1000)
  153. }
  154. },
  155. computed: {
  156. _type() {
  157. //处理值
  158. const type = this.type
  159. return type == 'password' ? 'text' : type
  160. },
  161. _isShowPass() {
  162. //处理值
  163. return String(this.isShowPass) !== 'false'
  164. },
  165. _isShowCode() {
  166. //处理值
  167. return String(this.isShowCode) !== 'false'
  168. },
  169. _setTime() {
  170. //处理值
  171. const setTime = Number(this.setTime)
  172. return setTime > 0 ? setTime : 60
  173. },
  174. getVerCodeSecond() {
  175. //验证码倒计时计算
  176. if (this.second <= 0) {
  177. return this.codeText;
  178. } else {
  179. if (this.second < 10) {
  180. return '0' + this.second + "s";
  181. } else {
  182. return this.second + "s";
  183. }
  184. }
  185. }
  186. }
  187. }
  188. </script>
  189. <style lang='scss'>
  190. .main-input {
  191. flex: 1;
  192. text-align: left;
  193. /* color: white; */
  194. font-size: 16px;
  195. padding-right: 6px;
  196. margin-left: 10px;
  197. border: 1rpx solid #d9d9d9;
  198. height: 90rpx;
  199. border-radius: 10rpx;
  200. padding: 0rpx 20rpx;
  201. }
  202. .icon .mix-list-cell.b-b:after {
  203. left: 45px;
  204. }
  205. .placeholder-class {
  206. color: white;
  207. opacity: 0.5;
  208. }
  209. .mix-list-cell {
  210. border-radius: 32upx;
  211. margin-top: 1px;
  212. font-size: 32upx;
  213. background: #ffffff;
  214. text-align: left;
  215. display: flex;
  216. margin: 32upx;
  217. /* padding: 24upx 32upx; */
  218. position: relative;
  219. &.cell-hover {
  220. background: transparent;
  221. }
  222. &.b-b:after {
  223. left: 16px;
  224. }
  225. .cell-icon {
  226. align-self: center;
  227. width: 28px;
  228. max-height: 30px;
  229. font-size: 18px;
  230. }
  231. .cell-more {
  232. align-self: center;
  233. font-size: 16px;
  234. color: #606266;
  235. margin-left: 10px;
  236. }
  237. .cell-tit {
  238. width: 80px;
  239. font-size: 16px;
  240. /* color: white; */
  241. display: flex;
  242. align-items: center;
  243. }
  244. .cell-tip {
  245. font-size: 14px;
  246. color: white;
  247. }
  248. }
  249. .items {
  250. position: absolute;
  251. height: 48px;
  252. width: 100%;
  253. background: #FFFFFF;
  254. /*opacity:0.05;*/
  255. }
  256. .main-list {
  257. opacity: 0.8;
  258. z-index: 88;
  259. background: white;
  260. border: 1px solid white;
  261. display: flex;
  262. flex-direction: row;
  263. justify-content: space-between;
  264. align-items: center;
  265. height: 18px;
  266. /* Input 高度 */
  267. color: #333333;
  268. padding: 16px;
  269. margin-top: 12px;
  270. margin-bottom: 12px;
  271. }
  272. .img {
  273. width: 16px;
  274. height: 16px;
  275. font-size: 16px;
  276. }
  277. .vercode {
  278. color: #e10a07;
  279. font-size: 14px;
  280. }
  281. .vercode-run {
  282. color: black !important;
  283. }
  284. .oBorder {
  285. border-radius: 2.5rem;
  286. -webkit-box-shadow: 0 0 30px 0 rgba(43, 86, 112, .1);
  287. box-shadow: 0 0 30px 0 rgba(43, 86, 112, .1);
  288. }
  289. </style>