password_login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="content">
  3. <view class="title">密码登录</view>
  4. <view class="form vflex">
  5. <u-input v-model="userInfo.name" placeholder="用户名/手机号"></u-input>
  6. <u-input :type="pwd_type" v-model="userInfo.password" placeholder="请输入密码">
  7. <template slot="suffix">
  8. <view @click="show_pwd" v-if="pwd_type == 'password'">
  9. <image src="/static/images/login/biyanjing.png" class="pwd_icon"></image>
  10. </view>
  11. <view @click="show_pwd" v-if="pwd_type == 'text'">
  12. <image src="/static/images/login/yanjing.png" class="pwd_icon"></image>
  13. </view>
  14. </template>
  15. </u-input>
  16. </view>
  17. <view class="hflex acenter">
  18. <u-checkbox-group @change="checkboxChange">
  19. <u-checkbox v-model="agree" shape="circle"></u-checkbox>
  20. </u-checkbox-group>
  21. <view class="text">阅读并同意<span class="read" @click="open(0)">《用户服务协议》</span><span class="read" @click="open(1)">《个人信息保护政策》</span></view>
  22. </view>
  23. <view class="button hflex acenter jcenter" @click="login">
  24. <view>登录</view>
  25. </view>
  26. <view class="hflex acenter jcenter bottom">
  27. <view class="text_style1" @click="codeLogin">验证码登录</view>
  28. <view style="margin: 0 10rpx;">|</view>
  29. <view class="text_style2" @click="forgotPwd">忘记密码</view>
  30. </view>
  31. <!-- 弹出层 -->
  32. <u-modal :show="showProtocol" :title="protocolTitle" confirmColor="#2988FE" @confirm="isRead" confirmText="我已阅读">
  33. <view class="slot-content">
  34. <rich-text :nodes="protocolContent"></rich-text>
  35. </view>
  36. </u-modal>
  37. </view>
  38. </template>
  39. <script>
  40. import $api from '@/static/js/api.js'
  41. var that = ''
  42. export default {
  43. data() {
  44. return {
  45. userInfo: {
  46. name: '',
  47. password: ''
  48. },
  49. pwd_type: 'password',
  50. agree: false,
  51. showProtocol: false,
  52. protocolTitle: '',
  53. protocolContent: '',
  54. }
  55. },
  56. onLoad() {
  57. that = this
  58. },
  59. methods: {
  60. // 查看密码
  61. show_pwd() {
  62. if(that.pwd_type == 'text') {
  63. that.pwd_type = 'password'
  64. } else {
  65. that.pwd_type = 'text'
  66. }
  67. },
  68. // 阅读并同意
  69. checkboxChange(n) {
  70. this.agree = !this.agree
  71. },
  72. // 打开弹出层
  73. open(index) {
  74. const that = this
  75. $api.req({
  76. url: '/data/api.Login/getloginset'
  77. }, function(res) {
  78. if (res.code == 1) {
  79. if(index == 0) {
  80. uni.setStorageSync('xieyi',res.data.service_agreement)
  81. $api.jump('/pages/user/agreement?title=用户服务协议')
  82. } else {
  83. uni.setStorageSync('xieyi',res.data.protection_policy)
  84. $api.jump('/pages/user/agreement?title=个人隐私保护政策')
  85. }
  86. }
  87. })
  88. },
  89. // isRead() {
  90. // that.showProtocol = false
  91. // },
  92. // 登录
  93. login() {
  94. if ($api.formCheck(that.userInfo.name,"required") && $api.formCheck(that.userInfo.password, "password")) {
  95. if (!that.agree) {
  96. $api.info('请先阅读并同意用户协议和隐私协议')
  97. } else {
  98. wx.getSetting({
  99. success (res){
  100. if (res.authSetting['scope.userInfo']) {
  101. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  102. wx.login({
  103. success: function(res) {
  104. console.log("getUserInfo:",res);
  105. uni.request({
  106. url: $api.config.baseUrl + '/data/api.Login/getOpenid',
  107. method: 'POST',
  108. data: {
  109. code: res.code
  110. },
  111. header: {
  112. 'content-type': 'application/json',
  113. 'api-name': 'wxapp'
  114. },
  115. success: (res) => {
  116. if(res.data.code == 1) {
  117. $api.req({
  118. url: '/data/api.Login/in',
  119. method: 'POST',
  120. data: {
  121. phone: that.userInfo.name,
  122. password: that.userInfo.password,
  123. openid: res.data.data.openid
  124. }
  125. }, function(res) {
  126. console.log(res)
  127. if(res.code == 1) {
  128. wx.setStorageSync("token",res.data.token)
  129. wx.setStorageSync("id",res.data.id)
  130. var options = {
  131. user: res.data.huanxinID,
  132. pwd: '12345678',
  133. appKey: uni.WebIM.config.appkey,
  134. success: function (res2) {
  135. wx.setStorageSync("myUsername",res.data.huanxinID)
  136. },
  137. error: function(){
  138. }
  139. };
  140. uni.WebIM.conn.open(options);
  141. $api.jump('/pages/tabbar/mine/mine',3)
  142. } else {
  143. $api.info(res.info)
  144. }
  145. })
  146. }
  147. }
  148. })
  149. }
  150. })
  151. }
  152. }
  153. })
  154. }
  155. }
  156. },
  157. // 已阅读
  158. isRead() {
  159. that.showProtocol = false
  160. that.agree = true
  161. },
  162. // 去验证码登录
  163. codeLogin() {
  164. $api.jump('/pages/login/code_login')
  165. },
  166. // 忘记密码
  167. forgotPwd() {
  168. $api.jump('/pages/login/forgot_pwd')
  169. }
  170. },
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .content::v-deep {
  175. padding: 0 60rpx;
  176. .title {
  177. margin: 64rpx 0;
  178. font-size: 52rpx;
  179. color: #222;
  180. }
  181. .form {
  182. margin-bottom: 100rpx;
  183. .u-input {
  184. width: 630rpx !important;
  185. height: 104rpx !important;
  186. background-color: #f4f4f4;
  187. border-radius: 52rpx;
  188. font-size: 30rpx !important;
  189. box-sizing: border-box;
  190. padding: 30rpx 48rpx !important;
  191. margin: 26rpx 0;
  192. }
  193. .pwd_icon {
  194. width: 40rpx;
  195. height: 40rpx;
  196. }
  197. }
  198. .text {
  199. font-size: 24rpx;
  200. color: #9c9c9c;
  201. }
  202. .read {
  203. color: #2a63f3;
  204. }
  205. .button {
  206. width: 100%;
  207. height: 96rpx;
  208. background-color: #506dff;
  209. border-radius: 50rpx;
  210. box-shadow: 0 4rpx 28rpx 0 rgba(132,123,255,0.4);
  211. font-size: 40rpx;
  212. color: #fff;
  213. margin: 40rpx 0 36rpx;
  214. }
  215. .bottom {
  216. width: 100%;
  217. .text_style1 {
  218. font-size: 24rpx;
  219. color: #555;
  220. }
  221. .text_style2 {
  222. font-size: 24rpx;
  223. color: #506dff;
  224. }
  225. }
  226. }
  227. </style>