password_login.vue 6.1 KB

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