logingzh.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="content">
  3. <view class="header">
  4. <image src="../../static/shilu-login/logo.png"></image>
  5. </view>
  6. <!-- <view class="list" style="margin-top: 50px; color: #666; font-size: 14px;text-align: center;">openid:{{openid}}</view>
  7. <view class="list" style="margin-top: 50px; color: #666; font-size: 14px;text-align: center;">unionid:{{unionid}}</view> -->
  8. <view class="button-login" style="margin-top: 30%;" hover-class="button-hover" @tap="bindLogin()">
  9. <text style="font-size: 40upx;">登录</text>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. mobile: '',
  18. password: '',
  19. openid:'',
  20. unionid:'',
  21. userinfowx:''
  22. };
  23. },
  24. onLoad(e) {
  25. if(e.openid){
  26. this.openid=e.openid;
  27. }
  28. if(e.unionid){
  29. this.unionid=e.unionid;
  30. }
  31. },
  32. methods: {
  33. dyxx(){
  34. //#ifdef MP-WEIXIN
  35. uni.requestSubscribeMessage({
  36. tmplIds: ['wAqsuRFgYS9XBJ2OmBgVYgZ-YrpOkS0dfo-WxQuv41c'],
  37. success (res) {
  38. /*uni.showModal({
  39. title: '提醒',
  40. content: JSON.stringify(res),
  41. showCancel: false,
  42. confirmText: "确定",
  43. success: function (res) {
  44. if (res.confirm) {
  45. //uni.navigateBack();
  46. } else if (res.cancel) {
  47. }
  48. }
  49. });*/
  50. },
  51. fail: (data) => {
  52. uni.showModal({
  53. title: '提醒',
  54. content: JSON.stringify(data),
  55. showCancel: false,
  56. confirmText: "确定",
  57. success: function (res) {
  58. if (res.confirm) {
  59. //uni.navigateBack();
  60. } else if (res.cancel) {
  61. }
  62. }
  63. });
  64. }
  65. })
  66. //#endif
  67. },
  68. async bindLogin() {
  69. let _this =this
  70. if(!this.openid){
  71. uni.showToast({ title: 'openid不能为空',icon:"none" });
  72. this.userfocus= true
  73. return false;
  74. }
  75. if(!this.unionid){
  76. uni.showToast({ title: 'unionid不能为空',icon:"none" });
  77. this.paswfocus= true
  78. return false;
  79. }
  80. let data = {'openid':this.openid,'unionid':this.unionid};
  81. let [err,res] =await this.$httpas.get('/api/user/logingzh',data);
  82. if (!this.$httpas.errorCheck(err,res)) return;
  83. if(res.data.code === 1){
  84. if(res.data.data.userinfo.avatar){
  85. var str = res.data.data.userinfo.avatar;
  86. if(str.indexOf("data:image") != -1){
  87. var avatar='';
  88. }else{
  89. if(str.indexOf("http") != -1){
  90. avatar=res.data.data.userinfo.avatar;
  91. }else{
  92. avatar=this.configs.imgUrl+res.data.data.userinfo.avatar;
  93. }
  94. }
  95. }else{
  96. var avatar='';
  97. }
  98. uni.setStorage({//缓存配置信息
  99. key: 'avatar',
  100. data: avatar
  101. })
  102. uni.setStorage({//缓存配置信息
  103. key: 'userinfo',
  104. data: res.data.data.userinfo
  105. })
  106. uni.setStorage({//缓存配置信息
  107. key: 'config',
  108. data: res.data.data.config
  109. })
  110. uni.showModal({
  111. title: '温馨提示',
  112. content: res.data.msg,
  113. showCancel: false,
  114. confirmText: "确定",
  115. success: function (res) {
  116. if (res.confirm) {
  117. //_this.dyxx()
  118. //window.open('/pages/client/member/index', "_self")
  119. uni.switchTab({
  120. url: '/pages/client/member/index'
  121. });
  122. } else if (res.cancel) {
  123. }
  124. }
  125. });
  126. }else{
  127. uni.showToast({ title: res.data.msg,icon:"none" });
  128. }
  129. },
  130. getuserinfo: function(){
  131. uni.showLoading({
  132. title: '授权中...'
  133. });
  134. var this_=this
  135. // wx登录
  136. wx.login({
  137. success (res) {
  138. if (res.code) {
  139. //发起网络请求
  140. var code = res.code
  141. // 获取微信用户信息
  142. wx.getUserInfo({
  143. success: function(res) {
  144. this_.userinfowx=res.userInfo
  145. this_.wxlogin()
  146. },
  147. fail:res=>{
  148. // 获取失败的去引导用户授权
  149. }
  150. })
  151. } else {
  152. }
  153. }
  154. })
  155. },
  156. wxlogin(){
  157. var userinfowx=this.userinfowx
  158. var this_=this
  159. uni.login({
  160. timeout: 10000,
  161. provider: 'weixin', //如果是uniapp,在这里需要标明平台的类型,支持的参数请查阅uniapp官网的uni.login()文档
  162. success: (res) => {
  163. //console.log(res);
  164. //登陆成功的回调
  165. uni.hideLoading();
  166. uni.request({
  167. url: this.configs.webUrl+'/api/user/getOpenid',
  168. method:'GET',
  169. data: {
  170. //token: uni.getStorageSync("userinfo").token, //你的小程序的secret,
  171. code: res.code //wx.login 登录成功后的code
  172. },
  173. success: (cts) => {
  174. if(cts.data.code==1){
  175. this_.openid=cts.data.data
  176. uni.showModal({
  177. title: '温馨提示',
  178. content: '授权成功',
  179. showCancel: false,
  180. confirmText: "确定",
  181. success: function (res) {
  182. if (res.confirm) {
  183. this_.opsdd()
  184. } else if (res.cancel) {
  185. }
  186. }
  187. });
  188. }else{
  189. uni.showModal({
  190. title: '温馨提示',
  191. content: JSON.stringify(cts.data),
  192. showCancel: false,
  193. confirmText: "确定",
  194. success: function (res) {
  195. if (res.confirm) {
  196. //uni.navigateBack();
  197. } else if (res.cancel) {
  198. }
  199. }
  200. });
  201. }
  202. },
  203. fail: (err1) => {
  204. console.log(err1);
  205. uni.hideLoading();
  206. }
  207. });
  208. },
  209. fail: (err) => {
  210. uni.hideLoading();
  211. }
  212. })
  213. },
  214. opsdd(){
  215. this.userinfowx.openid=this.openid
  216. uni.setStorage({//缓存配置信息
  217. key: 'userinfowx',
  218. data: this.userinfowx
  219. })
  220. uni.navigateTo({
  221. url:'/pages/login/loginwxxcx'
  222. })
  223. },
  224. onGetPhoneNumber(e) {
  225. var this_=this
  226. if(!this.openid){
  227. uni.showModal({
  228. title: '温馨提示',
  229. content: '请先授权',
  230. showCancel: false,
  231. confirmText: "确定",
  232. success: function (res) {
  233. //this_.getuserinfo()
  234. }
  235. });
  236. return false;
  237. }
  238. uni.login({
  239. timeout: 10000,
  240. provider: 'weixin', //如果是uniapp,在这里需要标明平台的类型,支持的参数请查阅uniapp官网的uni.login()文档
  241. success: (res) => {
  242. console.log(res);
  243. console.log("onGetPhoneNumber", e);
  244. uni.request({
  245. url: this.configs.webUrl+'/api/user/getphone',
  246. method:'GET',
  247. data: {
  248. openid:this.openid,
  249. userinfowx:this.userinfowx,
  250. code: res.code,
  251. iv: e.detail.iv,
  252. encryptedData:e.detail.encryptedData,
  253. },
  254. success: (cts) => {
  255. console.log(cts.data);
  256. uni.showModal({
  257. title: '温馨提示',
  258. content: JSON.stringify(cts.data),
  259. showCancel: false,
  260. confirmText: "确定",
  261. success: function (res) {
  262. if (res.confirm) {
  263. //uni.navigateBack();
  264. } else if (res.cancel) {
  265. }
  266. }
  267. });
  268. },
  269. fail: (err1) => {
  270. console.log(err1);
  271. //失败的回调
  272. }
  273. });
  274. },
  275. fail: (err) => {
  276. //登陆失败的回调
  277. },
  278. })
  279. }
  280. }
  281. }
  282. </script>
  283. <style>
  284. .content {
  285. display: flex;
  286. flex-direction: column;
  287. justify-content: center;
  288. }
  289. .header {
  290. width: 161rpx;
  291. height: 161rpx;
  292. background: rgba(63, 205, 235, 1);
  293. box-shadow: 0rpx 12rpx 13rpx 0rpx rgba(63, 205, 235, 0.47);
  294. border-radius: 50%;
  295. margin-top: 30rpx;
  296. margin-left: auto;
  297. margin-right: auto;
  298. }
  299. .header image {
  300. width: 161rpx;
  301. height: 161rpx;
  302. border-radius: 50%;
  303. }
  304. .list {
  305. display: flex;
  306. flex-direction: column;
  307. padding-top: 50rpx;
  308. padding-left: 70rpx;
  309. padding-right: 70rpx;
  310. }
  311. .list-call {
  312. display: flex;
  313. flex-direction: row;
  314. justify-content: space-between;
  315. align-items: center;
  316. height: 100rpx;
  317. color: #333333;
  318. border-bottom: 0.5px solid #e2e2e2;
  319. }
  320. .list-call .img {
  321. width: 40rpx;
  322. height: 40rpx;
  323. }
  324. .list-call .sl-input {
  325. flex: 1;
  326. text-align: left;
  327. font-size: 32rpx;
  328. margin-left: 16rpx;
  329. }
  330. .button-login {
  331. color: #FFFFFF;
  332. font-size: 34rpx;
  333. width: 470rpx;
  334. height: 100rpx;
  335. background: linear-gradient(-90deg, rgba(75, 196, 93, 1), rgba(188, 226, 158, 1));
  336. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
  337. border-radius: 50rpx;
  338. line-height: 100rpx;
  339. text-align: center;
  340. margin-left: auto;
  341. margin-right: auto;
  342. margin-top: 100rpx;
  343. }
  344. .button-login1 {
  345. color: #FFFFFF;
  346. font-size: 34rpx;
  347. width: 470rpx;
  348. height: 80rpx;
  349. background: linear-gradient(-90deg, rgba(75, 196, 93, 1), rgba(188, 226, 158, 1));
  350. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
  351. border-radius: 50rpx;
  352. line-height: 80rpx;
  353. text-align: center;
  354. margin-left: auto;
  355. margin-right: auto;
  356. margin-top: 30rpx;
  357. color: #fff;
  358. }
  359. .button-hover {
  360. background: linear-gradient(-90deg, rgba(63, 205, 235, 0.8), rgba(188, 226, 158, 0.8));
  361. }
  362. .agreenment {
  363. display: flex;
  364. flex-direction: row;
  365. justify-content: center;
  366. align-items: center;
  367. font-size: 30rpx;
  368. margin-top: 80rpx;
  369. color: #FFA800;
  370. text-align: center;
  371. height: 40rpx;
  372. line-height: 40rpx;
  373. }
  374. .agreenment text {
  375. font-size: 24rpx;
  376. margin-left: 15rpx;
  377. margin-right: 15rpx;
  378. }
  379. </style>