login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <view class="container" style="background-color: #ffffff;padding-bottom: 100rpx;">
  3. <form @submit="bindSave">
  4. <view v-if="config.logo" class="login-logo">
  5. <image style="width: 300rpx;height: 300rpx;" :src="config.logo"></image>
  6. </view>
  7. <view class="tui-form">
  8. <view v-if="memberconfig.sms_status==1" class="tui-view-input">
  9. <tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
  10. <view class="tui-cell-input">
  11. <tui-icon name="mobile" color="#6d7a87" :size="20"></tui-icon>
  12. <input name="userphone" v-model="phone" :adjust-position="false" placeholder="手机号"
  13. placeholder-class="tui-phcolor" type="text" />
  14. </view>
  15. </tui-list-cell>
  16. <tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
  17. <view class="tui-cell-input">
  18. <tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
  19. <input name="captcha" v-model="captcha" :adjust-position="false" placeholder="验证码"
  20. placeholder-class="tui-phcolor" type="text" />
  21. <button class="code font-num" :class="disabled === true ? 'on' : ''" :disabled='disabled'
  22. @click="makecaptcha">
  23. {{verifyCodetext}}
  24. </button>
  25. </view>
  26. </tui-list-cell>
  27. </view>
  28. <view v-else class="tui-view-input">
  29. <tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
  30. <view class="tui-cell-input">
  31. <tui-icon name="people" color="#6d7a87" :size="20"></tui-icon>
  32. <input name="username" :adjust-position="false" placeholder="手机号/用户名"
  33. placeholder-class="tui-phcolor" type="text" />
  34. </view>
  35. </tui-list-cell>
  36. <tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
  37. <view class="tui-cell-input">
  38. <tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
  39. <input name="password" :adjust-position="false" placeholder="密 码" :password="true"
  40. placeholder-class="tui-phcolor" type="text" />
  41. </view>
  42. </tui-list-cell>
  43. </view>
  44. <view class="tui-btn-box">
  45. <button form-type="submit" class="btn86"
  46. :style="'background:'+ pagestyleconfig.appstylecolor">登录</button>
  47. </view>
  48. <!-- #ifdef MP-WEIXIN -->
  49. <view v-if="ptype=='member' && memberconfig.close_getPhone!=1" class="tui-wxloginbtn-box">
  50. <tui-button :disabledGray="true" @click="phonemodal=true" height="86rpx" type="white"
  51. shape="circle">自动登录
  52. </tui-button>
  53. </view>
  54. <!-- #endif -->
  55. <!-- #ifdef MP-WEIXIN -->
  56. <tui-modal :show="phonemodal" @cancel="phonemodalcancel" :custom="true" fadeIn>
  57. <view class="tui-modal-custom">
  58. <view class="tui-prompt-title">你可以使用自动登录</view>
  59. <view class="tui-modal__btn">
  60. <view class="tui-box">
  61. <button :style="'background:'+ pagestyleconfig.appstylecolor" class="tui-btn-danger"
  62. open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">自动登录</button>
  63. </view>
  64. <view class="tui-box" v-if="ptype=='member' && memberconfig.sms_status==1">
  65. <tui-button type="white" shape="circle" height="80rpx" :size="26"
  66. @click="phonemodalcancel">手机验码证登录</tui-button>
  67. </view>
  68. <view class="tui-box" v-else>
  69. <tui-button type="white" shape="circle" height="80rpx" :size="26"
  70. @click="phonemodalcancel">账号密码登录</tui-button>
  71. </view>
  72. </view>
  73. </view>
  74. </tui-modal>
  75. <!-- #endif -->
  76. </view>
  77. </form>
  78. <membetreg :show="membetregshow" :stylecolor="pagestyleconfig.appstylecolor" @loginnextpage="loginnextpage"
  79. @close="membetregClose"></membetreg>
  80. </view>
  81. </template>
  82. <script>
  83. import membetreg from "@/components/views/membetreg/membetreg"
  84. export default {
  85. components: {
  86. membetreg
  87. },
  88. data() {
  89. return {
  90. ptype: "",
  91. membetregshow: false,
  92. pagestyleconfig: [],
  93. gotopage: '',
  94. config: {},
  95. memberconfig: {},
  96. phone: '',
  97. captcha: '',
  98. disabled: false,
  99. phonemodal: false,
  100. verifyCodetext: "获取验证码"
  101. };
  102. },
  103. onLoad(e) {
  104. var _this = this;
  105. if (e.ptype) {
  106. this.ptype = e.ptype;
  107. }
  108. if (e.gotopage) {
  109. this.gotopage = e.gotopage;
  110. uni.setStorageSync("gotopage", this.gotopage);
  111. } else {
  112. this.gotopage = uni.getStorageSync('gotopage')
  113. }
  114. _this.$request.post('config', {
  115. mo: 'pagestyle'
  116. }).then(res => {
  117. if (res.errno == 0) {
  118. _this.pagestyleconfig = res.data
  119. }
  120. });
  121. _this.$util.getUserInfo(function(userInfo) {
  122. console.log(userInfo);
  123. })
  124. _this.$request.post('config', {
  125. samkey: (new Date()).valueOf()
  126. }).then(res => {
  127. if (res.errno == 0) {
  128. if (res.data) {
  129. _this.config = res.data
  130. }
  131. }
  132. });
  133. _this.$request.post('config', {
  134. mo: 'member'
  135. }).then(res => {
  136. if (res.errno == 0) {
  137. if (res.data) {
  138. _this.memberconfig = res.data
  139. if (_this.memberconfig.close_getPhone != 1) {
  140. _this.phonemodal = true
  141. }
  142. }
  143. }
  144. });
  145. },
  146. methods: {
  147. bindSave: function(e) {
  148. var _this = this;
  149. const username = e.detail.value.username;
  150. const password = e.detail.value.password;
  151. const userphone = e.detail.value.userphone;
  152. const captcha = e.detail.value.captcha;
  153. if (!userphone) {
  154. if (!username) {
  155. uni.showToast({
  156. title: '请输入用户名',
  157. icon: 'none'
  158. });
  159. return;
  160. }
  161. if (!password) {
  162. uni.showToast({
  163. title: '请输入密码',
  164. icon: 'none'
  165. });
  166. return;
  167. }
  168. } else {
  169. if (!captcha) {
  170. uni.showToast({
  171. title: '请输入验证码',
  172. icon: 'none'
  173. });
  174. return;
  175. }
  176. }
  177. _this.$request.post('login.index', {
  178. ptype: _this.ptype,
  179. username: username,
  180. password: password,
  181. userphone: userphone,
  182. captcha: captcha
  183. }).then(res => {
  184. if (res.errno != 0) {
  185. console.log(res);
  186. uni.showToast({
  187. title: res.msg,
  188. icon: 'none'
  189. });
  190. return;
  191. } else {
  192. uni.setStorageSync("uid", res.data.id);
  193. uni.setStorageSync("uuid", res.data.uuid);
  194. uni.showToast({
  195. title: res.msg,
  196. icon: 'none'
  197. });
  198. _this.reg();
  199. }
  200. });
  201. },
  202. loginnextpage() {
  203. var _this = this;
  204. let url = '/pages/index/index';
  205. if (_this.ptype == 'member' && _this.gotopage) {
  206. url = _this.gotopage
  207. }
  208. this.sam.navigateTo(url);
  209. },
  210. reg() {
  211. this.membetregshow = true;
  212. },
  213. membetregClose() {
  214. this.membetregshow = false;
  215. },
  216. phonemodalcancel() {
  217. this.phonemodal = false
  218. },
  219. // 获取手机号
  220. getPhoneNumber(e) {
  221. console.log(e);
  222. var _this = this;
  223. _this.$request.post('login.getphonenumber', {
  224. ptype: _this.ptype,
  225. code: e.detail.code
  226. }).then(res => {
  227. if (res.errno == 0) {
  228. if (res.data.id > 0) {
  229. uni.setStorageSync("telephone", res.data.telephone);
  230. this.phonemodal = false
  231. _this.reg();
  232. }
  233. }
  234. });
  235. },
  236. makecaptcha() {
  237. let _this = this;
  238. if (!_this.phone) {
  239. uni.showToast({
  240. title: '请填写手机号码!',
  241. icon: 'none'
  242. });
  243. return;
  244. }
  245. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(_this.phone))) {
  246. uni.showToast({
  247. title: '请输入正确的手机号码!',
  248. icon: 'none'
  249. });
  250. return;
  251. }
  252. _this.$request.post('login.captcha', {
  253. phone: _this.phone
  254. }).then(res => {
  255. console.log(res);
  256. if (res.errno == 0) {
  257. uni.showToast({
  258. title: res.msg,
  259. icon: 'none'
  260. });
  261. _this.sendCode();
  262. }
  263. });
  264. },
  265. sendCode() {
  266. if (this.disabled) return;
  267. this.disabled = true;
  268. let n = 60;
  269. this.verifyCodetext = "剩余 " + n + "s";
  270. const run = setInterval(() => {
  271. n = n - 1;
  272. if (n < 0) {
  273. clearInterval(run);
  274. }
  275. this.verifyCodetext = "剩余 " + n + "s";
  276. if (this.verifyCodetext < "剩余 " + 0 + "s") {
  277. this.disabled = false;
  278. this.verifyCodetext = "重新获取";
  279. }
  280. }, 1000);
  281. }
  282. },
  283. /**
  284. * 页面相关事件处理函数--监听用户下拉动作
  285. */
  286. onPullDownRefresh: function() {
  287. setTimeout(() => {
  288. uni.stopPullDownRefresh()
  289. }, 200);
  290. },
  291. };
  292. </script>
  293. <style lang="scss">
  294. page {
  295. background-color: #ffffff;
  296. }
  297. .container {
  298. .login-logo {
  299. margin-left: auto;
  300. margin-right: auto;
  301. text-align: center;
  302. }
  303. .tui-status-bar {
  304. width: 100%;
  305. height: var(--status-bar-height);
  306. }
  307. .bottom {
  308. height: 86rpx;
  309. border-radius: 43rpx;
  310. }
  311. .tui-header {
  312. width: 100%;
  313. padding: 40rpx;
  314. display: flex;
  315. align-items: center;
  316. justify-content: space-between;
  317. box-sizing: border-box;
  318. }
  319. .tui-page-title {
  320. width: 100%;
  321. font-size: 48rpx;
  322. font-weight: bold;
  323. color: $uni-text-color;
  324. line-height: 42rpx;
  325. padding: 40rpx;
  326. box-sizing: border-box;
  327. }
  328. .tui-form {
  329. padding-top: 50rpx;
  330. .tui-view-input {
  331. width: 100%;
  332. box-sizing: border-box;
  333. padding: 0 40rpx;
  334. .tui-cell-input {
  335. width: 100%;
  336. display: flex;
  337. align-items: center;
  338. padding-top: 48rpx;
  339. padding-bottom: $uni-spacing-col-base;
  340. input {
  341. flex: 1;
  342. padding-left: $uni-spacing-row-base;
  343. }
  344. }
  345. }
  346. .tui-cell-text {
  347. width: 100%;
  348. padding: $uni-spacing-col-lg $uni-spacing-row-lg;
  349. box-sizing: border-box;
  350. font-size: $uni-font-size-sm;
  351. color: $uni-text-color-grey;
  352. display: flex;
  353. align-items: center;
  354. justify-content: space-between;
  355. .tui-color-primary {
  356. color: $uni-color-primary;
  357. }
  358. .tui-regbutton {
  359. margin-left: auto;
  360. margin-right: auto;
  361. background-color: #ffffff;
  362. font-size: 28rpx;
  363. color: $uni-color-primary;
  364. }
  365. .tui-regbutton text {
  366. color: #666;
  367. }
  368. }
  369. .tui-btn-box {
  370. width: 100%;
  371. padding: 0 $uni-spacing-row-lg;
  372. box-sizing: border-box;
  373. margin-top: 60rpx;
  374. }
  375. .tui-wxloginbtn-box {
  376. width: 100%;
  377. padding: 0 $uni-spacing-row-lg;
  378. box-sizing: border-box;
  379. margin-top: 40rpx;
  380. }
  381. }
  382. .tui-login-way {
  383. width: 100%;
  384. font-size: 26rpx;
  385. color: $uni-color-primary;
  386. display: flex;
  387. justify-content: center;
  388. position: fixed;
  389. left: 0;
  390. bottom: 80rpx;
  391. view {
  392. padding: 12rpx 0;
  393. }
  394. }
  395. .tui-auth-login {
  396. width: 100%;
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. padding-bottom: 80rpx;
  401. padding-top: 20rpx;
  402. .tui-icon-platform {
  403. width: 90rpx;
  404. height: 90rpx;
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. position: relative;
  409. margin-left: 40rpx;
  410. &::after {
  411. content: '';
  412. position: absolute;
  413. width: 200%;
  414. height: 200%;
  415. transform-origin: 0 0;
  416. transform: scale(0.5, 0.5) translateZ(0);
  417. box-sizing: border-box;
  418. left: 0;
  419. top: 0;
  420. border-radius: 180rpx;
  421. border: 1rpx solid $uni-text-color-placeholder;
  422. }
  423. }
  424. .tui-login-logo {
  425. width: 60rpx;
  426. height: 60rpx;
  427. }
  428. }
  429. .code {
  430. font-size: 32rpx;
  431. }
  432. .code.on {
  433. color: #b9b9bc !important;
  434. }
  435. .tui-modal-custom {
  436. padding-top: 60rpx;
  437. padding-bottom: 50rpx;
  438. text-align: center;
  439. }
  440. .tui-prompt-title {
  441. padding-bottom: 20rpx;
  442. font-size: 34rpx;
  443. }
  444. .tui-modal__btn {
  445. align-items: center;
  446. justify-content: space-between;
  447. }
  448. .tui-box {
  449. padding: 15rpx 20rpx;
  450. box-sizing: border-box;
  451. }
  452. .btn86 {
  453. height: 86rpx;
  454. line-height: 86rpx;
  455. border-radius: 98rpx;
  456. color: #fff;
  457. }
  458. .tui-btn-danger {
  459. height: 80rpx;
  460. line-height: 80rpx;
  461. border-radius: 98rpx;
  462. color: #fff;
  463. }
  464. }
  465. </style>