com-input.vue 6.0 KB

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