loginDialog.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view>
  3. <van-dialog title="请登录"
  4. show-cancel-button="true"
  5. :show="show"
  6. @cancel="cancelDialog" @confirm="confirmOrder"
  7. confirm-button-open-type="getUserInfo"
  8. confirm-button-color = "#323232"
  9. >
  10. </van-dialog>
  11. <!-- <button @click="wxlogion" open-type="getUserInfo">请点击授权</button> -->
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. mapMutations,mapState
  17. } from 'vuex'
  18. export default {
  19. props:{
  20. showdialog:{
  21. default: false,
  22. type: Boolean
  23. }
  24. },
  25. data() {
  26. return{
  27. show: false
  28. }
  29. },
  30. watch:{
  31. 'showdialog':function(val) {
  32. if(val) {
  33. this.show = true;
  34. }else {
  35. this.show = false;
  36. }
  37. }
  38. },
  39. methods:{
  40. ...mapMutations(['login','showDialog']),
  41. cancelDialog() {
  42. this.$msg('登录失败');
  43. this.login();
  44. this.$emit('cancelDiaolog')
  45. this.showDialog(false);
  46. },
  47. confirmOrder() {
  48. this.wxlogion();
  49. },
  50. wxlogion() {
  51. let that = this;
  52.     uni.getUserInfo({
  53.      success(res) {
  54. that.login(res.userInfo);
  55. that.showDialog(true);
  56. that.$emit('confirmDiaolog');
  57. that.$msg("登录成功")
  58.      },
  59.      fail(res) {
  60. console.log(res);
  61. that.$msg("登录失败")
  62.      }
  63.     })
  64. }
  65. }
  66. }
  67. </script>
  68. <style>
  69. </style>