login.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="content" >
  3. <uni-nav-bar :fixed="true" shadow left-icon="left" title="技师登录" :statusBar="true" @clickLeft="handleToBack" />
  4. <view class="logo_wrap">
  5. <image src="/static/logo.png" class="logo" />
  6. </view>
  7. <view class="form_row">
  8. <view class="form_input_wrap">
  9. <image src="/static/login/phone.png" class="form_input_prefix" mode="aspectFill" />
  10. <input class="form_input" placeholder="请输入手机号" v-model="loginData.mobile" />
  11. </view>
  12. </view>
  13. <view class="form_row">
  14. <view class="form_input_wrap">
  15. <image src="/static/login/password.png" class="form_input_prefix" mode="aspectFill" />
  16. <input class="form_input" placeholder="请输入密码" :password="isPassword" v-model="loginData.password" />
  17. <image src="/static/login/hidden.png" class="form_input_suffix" mode="aspectFill" @tap="onChangePassword" v-if="isPassword" />
  18. <image src="/static/login/show.png" class="form_input_suffix" mode="aspectFill" @tap="onChangePassword" v-else />
  19. </view>
  20. </view>
  21. <view class="form_row">
  22. <view class="form_link" @tap="handleToForgot">忘记密码</view>
  23. <view class="form_link" @tap="handleToRegister">注册</view>
  24. </view>
  25. <view style="height: 100px"></view>
  26. <view class="agreement">
  27. <image src="/static/common/radio_selected.png" class="agreement_radio" @tap="handleAgreement" v-if="isAgreement"></image>
  28. <image src="/static/common/radio_unselect.png" class="agreement_radio" @tap="handleAgreement" v-else></image>
  29. <text @tap="handleAgreement">已阅读并同意</text>
  30. <text class="link_text" @tap="handleToServiceHtml">《用户协议》</text>
  31. <text class="link_text" @tap="handleToPravicyHtml">《隐私政策》</text>
  32. </view>
  33. <button type="primary" class="form_submit_btn" :loading="loading" @tap="handleLogin">登录</button>
  34. <uni-popup ref="alertDialog" type="dialog">
  35. <uni-popup-dialog type="info" cancelText="取消" confirmText="已阅读并同意" title="服务协议及隐私保护" @confirm="dialogConfirm" @close="dialogClose">
  36. <view>
  37. 为了保障您的合法权益,请阅读本平台以下协议
  38. <text style="color: #07d69e" @tap="handleToServiceHtml">《用户协议》</text>
  39. <text style="color: #07d69e" @tap="handleToPravicyHtml">《隐私政策》</text>
  40. </view>
  41. </uni-popup-dialog>
  42. </uni-popup>
  43. </view>
  44. </template>
  45. <script setup>
  46. import { ref, reactive } from 'vue';
  47. import { onLoad, onShow } from '@dcloudio/uni-app';
  48. import request from '/common/request.js';
  49. const loading = ref(false);
  50. const loginData = reactive({
  51. mobile: '',
  52. password: '',
  53. status: 1,
  54. type: 2
  55. });
  56. const isPassword = ref(true);
  57. const isAgreement = ref(false);
  58. const statusBarHeight = ref();
  59. const alertDialog = ref();
  60. onLoad((option) => {
  61. statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight;
  62. console.log('statusBarHeight', statusBarHeight.value);
  63. });
  64. onShow((option) => {
  65. uni.$emit('fastOrderNum', false);
  66. uni.$emit('receiveOrdernum', false);
  67. });
  68. const handleToBack = () => {
  69. const canNavBack = getCurrentPages();
  70. if (canNavBack && canNavBack.length > 1) uni.navigateBack();
  71. else history.back();
  72. };
  73. const showToast = (title) => {
  74. uni.showToast({ title, duration: 2000, icon: 'none' });
  75. };
  76. const verifyFormData = () => {
  77. let message = '';
  78. if (loginData.mobile == '') message = '请填写手机号';
  79. else if (loginData.password == '') message = '请填写密码';
  80. return message;
  81. };
  82. const onChangePassword = () => {
  83. isPassword.value = !isPassword.value;
  84. };
  85. const handleToRegister = () => {
  86. uni.redirectTo({
  87. url: '/pages/account/register'
  88. });
  89. };
  90. const handleToForgot = () => {
  91. uni.redirectTo({
  92. url: '/pages/account/forgot'
  93. });
  94. };
  95. //跳转到用户协议
  96. const handleToServiceHtml = () => {
  97. uni.navigateTo({
  98. url: '/pages/account/help?id=24'
  99. });
  100. };
  101. //跳转到隐私政策
  102. const handleToPravicyHtml = () => {
  103. uni.navigateTo({
  104. url: '/pages/account/help?id=23'
  105. });
  106. };
  107. const handleAgreement = () => {
  108. isAgreement.value = !isAgreement.value;
  109. };
  110. const dialogConfirm = () => {
  111. isAgreement.value = true;
  112. handleLogin();
  113. };
  114. const dialogClose = () => {};
  115. const dialogToggle = () => {
  116. alertDialog.value.open();
  117. };
  118. const handleLogin = async () => {
  119. let message = verifyFormData();
  120. if (message) {
  121. showToast(message);
  122. return;
  123. }
  124. if (!isAgreement.value) {
  125. dialogToggle();
  126. return;
  127. }
  128. uni.showLoading();
  129. request({
  130. url: '/api/login',
  131. method: 'POST',
  132. data: loginData,
  133. success: async (res) => {
  134. console.log('用户登录', res);
  135. showToast(res.data.msg);
  136. if (res.data.code == 1) {
  137. uni.setStorageSync('token', res.data?.data?.token);
  138. uni.setStorageSync('id', res.data?.data?.id);
  139. setTimeout(function () {
  140. const canNavBack = getCurrentPages();
  141. if (canNavBack && canNavBack.length > 1) {
  142. uni.navigateBack();
  143. } else {
  144. history.back();
  145. }
  146. uni.$emit('startPlayVoiceBroadcast', true);
  147. }, 1000);
  148. }
  149. },
  150. fail: () => {},
  151. complete: () => {
  152. // uni.hideLoading();
  153. }
  154. });
  155. };
  156. const handleWechartLogin = () => {
  157. uni.login({
  158. provider: 'weixin',
  159. success: function (loginRes) {
  160. console.log(loginRes.code);
  161. // 获取用户信息
  162. uni.getUserInfo({
  163. provider: 'weixin',
  164. success: function (infoRes) {
  165. console.log('用户昵称为:' + infoRes.userInfo.nickName);
  166. /* uni.showToast({
  167. title:JSON.stringify(infoRes),
  168. duration: 5000,
  169. icon: 'none'
  170. });*/
  171. uni.showLoading({
  172. content: '加载中',
  173. mask: true
  174. });
  175. request({
  176. url: '/api/wxlogin/wxLogin',
  177. method: 'POST',
  178. data: {
  179. openid: infoRes.userInfo.openId,
  180. avatar: infoRes.userInfo.avatarUrl,
  181. type: 2,
  182. nickname: infoRes.userInfo.nickName
  183. },
  184. success: (res) => {
  185. console.log(res);
  186. if (res.data.code == 1) {
  187. if (res.data.data.token) {
  188. uni.setStorage({
  189. key: 'token',
  190. data: res.data.data.token,
  191. success: function () {}
  192. });
  193. uni.setStorage({
  194. key: 'id',
  195. data: res.data.data.id,
  196. success: function () {}
  197. });
  198. uni.$emit('sxdd', {
  199. msg: '页面更新'
  200. });
  201. // uni.navigateBack();
  202. setTimeout(function () {
  203. uni.switchTab({
  204. url: '/pages/index/index'
  205. });
  206. }, 1000);
  207. } else {
  208. uni.navigateTo({
  209. url: '/pages/bangding/bangding?id=' + res.data.data.id
  210. });
  211. }
  212. } else {
  213. uni.showToast({
  214. title: res.data.msg,
  215. duration: 2000,
  216. icon: 'none'
  217. });
  218. }
  219. },
  220. fail: () => {},
  221. complete: () => {
  222. setTimeout(function () {
  223. uni.hideLoading();
  224. }, 2000);
  225. }
  226. });
  227. }
  228. });
  229. }
  230. });
  231. };
  232. </script>
  233. <style lang="scss" scoped>
  234. .content {
  235. width: 750upx;
  236. margin: 0 auto;
  237. background: #f9f9f9;
  238. position: relative;
  239. .logo_wrap {
  240. padding: 69upx 0;
  241. .logo {
  242. width: 160upx;
  243. height: 160upx;
  244. display: block;
  245. margin: 0 auto;
  246. border-radius: 40upx;
  247. }
  248. }
  249. .form_row {
  250. display: flex;
  251. justify-content: space-between;
  252. padding: 0 60upx;
  253. .form_input_wrap {
  254. width: 630upx;
  255. height: 80upx;
  256. background: #ffffff;
  257. border: 1upx solid #07d69e;
  258. border-radius: 40upx;
  259. margin: 0 auto 30upx;
  260. display: flex;
  261. padding: 18upx 35upx 22upx;
  262. .form_input_prefix {
  263. width: 40upx;
  264. height: 40upx;
  265. }
  266. .form_input {
  267. width: 430upx;
  268. height: 42upx;
  269. font-size: 28upx;
  270. font-weight: 400;
  271. color: #999999;
  272. line-height: 40upx;
  273. margin: 0 20upx;
  274. }
  275. .form_input_suffix {
  276. width: 40upx;
  277. height: 40upx;
  278. }
  279. }
  280. .form_link {
  281. font-size: 26upx;
  282. font-weight: 400;
  283. color: #07d69e;
  284. margin: 0 22upx;
  285. }
  286. }
  287. .form_submit_btn {
  288. width: 630upx;
  289. height: 80upx;
  290. background: linear-gradient(90deg, #37ecba 0%, #72afd3 100%);
  291. border-radius: 40upx;
  292. margin: 10upx auto;
  293. font-size: 32upx;
  294. font-weight: bold;
  295. color: #ffffff;
  296. }
  297. .agreement {
  298. font-size: 24upx;
  299. color: #666;
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. margin: 62upx 0;
  304. .agreement_radio {
  305. width: 28upx;
  306. height: 28upx;
  307. margin: 0 10upx;
  308. }
  309. .link_text {
  310. color: #07d69e;
  311. }
  312. }
  313. }
  314. :deep(.uni-modal) {
  315. .uni-modal__bd {
  316. padding: 30upx;
  317. }
  318. .uni-modal__ft {
  319. .uni-modal__btn_primary {
  320. color: #07d69e !important;
  321. }
  322. .uni-modal__btn_default {
  323. color: #999 !important;
  324. }
  325. }
  326. }
  327. </style>