userlogin.vue 11 KB

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