logOn.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view>
  3. <u-notify ref="uNotify" message="Hi uView"></u-notify>
  4. <!-- 账号密码登录 -->
  5. <view v-if="type == 1">
  6. <!-- <view class="ver" @click="verificationShow">
  7. 验证码登录
  8. </view> -->
  9. <view class="title">
  10. 账号登录
  11. </view>
  12. <view class="inp">
  13. <input placeholder="请输入你的账号" v-model="account"/>
  14. </view>
  15. <view class="inp">
  16. <input placeholder="请输入密码" v-if="passShow" type="password" v-model="pwd" >
  17. <input placeholder="请输入密码" v-else type="text" v-model="pwd" >
  18. <u-icon v-if="passShow" class="i" name="eye-off" size="40rpx" @click="pass()"></u-icon>
  19. <u-icon v-else class="i" name="eye" size="40rpx" @click="pass()"></u-icon>
  20. </view>
  21. <view class="an" :class="[isBindAuth ? 'forbidden':'']" @click="to(1)">
  22. {{ isBindAuth? '正在授权中...':'登录' }}
  23. </view>
  24. </view>
  25. <!-- 验证码登录 -->
  26. <view v-if="type == 2">
  27. <!-- <view class="title" style="margin-top: 30rpx;">
  28. 验证码登录
  29. </view> -->
  30. <view class="inp" style="padding-left: 216rpx;">
  31. <input placeholder="请输入手机号" :type="passShow ? 'password' : 'text' " />
  32. <text>+86</text>
  33. </view>
  34. <view class="an" @click="toVer(1)">
  35. 下一步
  36. </view>
  37. </view>
  38. <!-- 验证码登录(输入验证码) -->
  39. <view v-if="type == 3">
  40. <view class="title" style="margin-top: 30rpx;">
  41. 输入验证码
  42. <view style="font-size: 28rpx; font-weight: 500; margin-top: 25rpx;">
  43. 已发送4位验证码至 +86 18899339922
  44. </view>
  45. </view>
  46. <view class="code-u">
  47. <view class="code"></view>
  48. <view class="code"></view>
  49. <view class="code"></view>
  50. <view class="code"></view>
  51. <u-code-input
  52. v-model="prove"
  53. mode="middleLine"
  54. :maxlength="4"
  55. space="58"
  56. class="prove"
  57. fontSize="40"
  58. ></u-code-input>
  59. </view>
  60. <view class="an" @click="to(1)">
  61. 登录
  62. </view>
  63. <view class="countDown" @click="upUtem">
  64. 重新获取<text v-if="item != 0">({{item}})</text>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import md5 from "../../utils/md5.js";
  71. export default {
  72. data() {
  73. return {
  74. type: 3, // 判断当前页面 1 = 账号登录 2 = 验证码登录(输入手机号) 3 = 验证码登录(输入验证码)
  75. passShow: true,
  76. prove: '',
  77. item: 60,
  78. account: '',
  79. isBindAuth: false,
  80. pwd: '',
  81. code: '',
  82. state: ''
  83. }
  84. },
  85. onLoad(e) {
  86. console.log(e)
  87. this.type = e.type
  88. },
  89. mounted() {
  90. this.code = ''
  91. this.state = 'index'
  92. this.code = this.getUrlCode().code // 截取code
  93. this.state = this.getUrlCode().state
  94. // 此时为授权回调
  95. if (this.code != null && this.code != ''){
  96. this.isBindAuth = true
  97. // 拿到CODE之后请求绑定微信号
  98. this.$request({
  99. url: this.$api.auth.bindWxId+`?wxcode=${this.code}`,
  100. method: 'get',
  101. }).then(res=>{
  102. console.log('res',res)
  103. if(res.code == 200) {
  104. uni.showToast({
  105. title:"绑定成功",
  106. icon: 'none'
  107. })
  108. // todo 跳转至首页
  109. uni.reLaunch({
  110. url:'/pages/index/index'
  111. })
  112. } else if(res.code == 201) {
  113. uni.showToast({
  114. title:'该账号已绑定其他账号',
  115. icon: 'none'
  116. })
  117. // 清空缓存并重新进入登录
  118. uni.clearStorageSync()
  119. setTimeout(()=>{
  120. uni.reLaunch({
  121. url: '/pages/signIn/logOn?type=1'
  122. })
  123. }, 1000);
  124. } else {
  125. uni.showToast({
  126. title:'请关注公众号后重试',
  127. icon: 'none'
  128. })
  129. // 清空缓存并重新进入登录
  130. uni.clearStorageSync()
  131. setTimeout(()=>{
  132. uni.reLaunch({
  133. url: '/pages/signIn/logOn?type=1'
  134. })
  135. }, 1000);
  136. }
  137. })
  138. }
  139. },
  140. methods: {
  141. pass(){
  142. this.passShow = !this.passShow
  143. },
  144. // 验证码登录显示
  145. verificationShow(){
  146. this.type = 2
  147. },
  148. getUrlCode() { // 截取url中的code方法
  149. var url = location.search
  150. this.winUrl = url
  151. var theRequest = new Object()
  152. if (url.indexOf("?") != -1) {
  153. var str = url.substr(1)
  154. var strs = str.split("&")
  155. for (var i = 0; i < strs.length; i++) {
  156. theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1])
  157. }
  158. }
  159. return theRequest
  160. },
  161. to(){
  162. if(this.account == '' || this.pwd == ''){
  163. this.$u.toast('请输入账号密码')
  164. return
  165. };
  166. if(this.isBindAuth) return
  167. let md5Pwd = md5.hex_md5(this.pwd)
  168. let appid = 'wxac0afae9104e5e4d'
  169. // let local = 'http://192.168.1.16:8081/pages/signIn/logOn?type=1'
  170. let local = 'https://xiaoyi.xunsoftware.com/pages/signIn/logOn?type=1'
  171. this.$request({
  172. url: (this.$api.auth.getToken+`?tenantId=&username=${this.account}&password=${md5Pwd}&grant_type=password&scope=all&type=account`),
  173. method:"post"
  174. }).then(res=>{
  175. console.log(res);
  176. // 如果是平台租户角色的话不允许登录
  177. if(res && res.tenant_id == '000000') {
  178. this.$refs.uNotify.show({
  179. top: 10,
  180. type: 'error',
  181. color: '#000',
  182. bgColor: '#e8e8e8',
  183. message: '该账号不属于学校医生',
  184. duration: 1000 * 3,
  185. fontSize: 20,
  186. safeAreaInsetTop:true
  187. })
  188. return
  189. }
  190. localStorage.setItem('tenant_id', res.tenant_id) // 获取登录之后的租户id
  191. localStorage.setItem("access_token", res.access_token)
  192. localStorage.setItem('user',JSON.stringify(res))
  193. // 请求绑定该账号和当前微信号
  194. uni.showLoading({
  195. title:"正在绑定到此微信号"
  196. })
  197. setTimeout(()=>{
  198. wx.hideLoading()
  199. let redirectType = 'index'
  200. window.location.href =
  201. // `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(local1)}&response_type=code&scope=snsapi_userinfo&state=${redirectType}#wechat_redirect`
  202. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&state=${redirectType}#wechat_redirect`
  203. },1500)
  204. }).catch(err => {
  205. this.$u.toast(err.error_description)
  206. })
  207. },
  208. toVer(){
  209. this.type = 3
  210. this.countDown()
  211. },
  212. countDown(){
  213. this.item = 60
  214. setInterval(()=>{
  215. if(this.item > 0){
  216. this.item--
  217. }
  218. }, 1000)
  219. },
  220. upUtem(){
  221. if(this.item != 0){
  222. this.$u.toast('短时间无法重复获取')
  223. return
  224. }
  225. this.countDown()
  226. },
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. page{
  232. padding: 50rpx 65rpx;
  233. /* background-color: #D9D9D9; */
  234. background-color: #fff !important;
  235. }
  236. .title{
  237. font-size: 56rpx;
  238. font-weight: 600;
  239. margin-bottom: 65rpx;
  240. margin-top: 80rpx;
  241. }
  242. .an{
  243. height: 112rpx;
  244. color: #fff;
  245. background-color: #846FFE;
  246. text-align: center;
  247. line-height: 112rpx;
  248. margin: 0 auto;
  249. border-radius: 64rpx;
  250. font-size: 32rpx;
  251. }
  252. .forbidden{
  253. background-color: #846FFE77;
  254. }
  255. .w{
  256. font-size: 25rpx;
  257. color: rgba(0,0,0,0.60);
  258. margin-top: 476rpx;
  259. }
  260. .inp{
  261. height: 100rpx;
  262. background: #ededed;
  263. border-radius: 64rpx;
  264. display: flex;
  265. align-items: center;
  266. padding-left: 95rpx;
  267. margin-bottom: 52rpx;
  268. position: relative;
  269. .i{
  270. position: absolute;
  271. right: 52rpx;
  272. }
  273. text{
  274. position: absolute;
  275. left: 96rpx;
  276. font-size: 32rpx;
  277. color: rgba(0,0,0,0.38);
  278. }
  279. }
  280. .ver{
  281. position: absolute;
  282. top: 10rpx;
  283. right: 64rpx;
  284. font-size: 28rpx;
  285. }
  286. .code-u{
  287. position: relative;
  288. display: flex;
  289. justify-content: space-between;
  290. margin-bottom: 52rpx;
  291. .code{
  292. width: 112rpx;
  293. height: 112rpx;
  294. background: #ededed;
  295. border-radius: 20rpx;
  296. }
  297. .prove{
  298. position: absolute;
  299. font-size: 52rpx;
  300. top: 25rpx;
  301. left: 28rpx;
  302. }
  303. }
  304. .countDown{
  305. text-align: center;
  306. font-size: 32rpx;
  307. color: rgba(0,0,0,0.60);
  308. margin-top: 38rpx;
  309. }
  310. </style>