ding.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="page-message">
  3. <div class="flex-center position-ref full-height">
  4. <div class="message">{{ message }}</div>
  5. </div>
  6. </div>
  7. </template>
  8. <style lang="scss" scoped>
  9. .page-message {
  10. background-color: #fff;
  11. color: #636b6f;
  12. font-weight: 400;
  13. height: 100vh;
  14. margin: 0;
  15. .full-height {
  16. height: 100vh;
  17. }
  18. .flex-center {
  19. align-items: center;
  20. display: flex;
  21. justify-content: center;
  22. }
  23. .position-ref {
  24. position: relative;
  25. }
  26. .code {
  27. border-right: 2px solid;
  28. font-size: 26px;
  29. padding: 0 15px 0 15px;
  30. text-align: center;
  31. }
  32. .message {
  33. font-size: 18px;
  34. padding: 10px;
  35. text-align: center;
  36. }
  37. }
  38. </style>
  39. <script>
  40. import * as dd from 'dingtalk-jsapi';
  41. export default {
  42. data() {
  43. return {
  44. message: '钉钉登录中',
  45. loadIng: 0,
  46. code: ''
  47. }
  48. },
  49. watch: {
  50. code: function(newValue, oldValue) {
  51. $A.ajax({
  52. url: $A.apiUrl('ding/login?code='+newValue),
  53. data: "",
  54. complete: () => {
  55. this.loadIng--;
  56. },
  57. success: (res) => {
  58. if (res.ret === 1) {
  59. $A.storage("userInfo", res.data);
  60. $A.setToken(res.data.token);
  61. $A.triggerUserInfoListener(res.data);
  62. //
  63. this.loadIng--;
  64. this.goForward({path: '/todo'}, true);
  65. } else {
  66. alert(res.msg)
  67. this.goForward({path: '/'}, true);
  68. }
  69. }
  70. })
  71. }
  72. },
  73. mounted() {
  74. // $A.ajax({
  75. // url: $A.apiUrl('ding/login?code=dc5dc708a99c387c807d7b905c025fbd'),
  76. // data: "",
  77. // complete: () => {
  78. // this.loadIng--;
  79. // },
  80. // success: (res) => {
  81. // console.log(res)
  82. // if (res.ret === 1) {
  83. // $A.storage("userInfo", res.data);
  84. // $A.setToken(res.data.token);
  85. // $A.triggerUserInfoListener(res.data);
  86. //
  87. // this.loadIng--;
  88. // this.goForward({path: '/todo'}, true);
  89. // } else {
  90. // that.message = res.msg
  91. // if (res.data.code === 'need') {
  92. // this.codeNeed = true;
  93. // this.refreshCode();
  94. // }
  95. // }
  96. // }
  97. // })
  98. let query = this.$route.query,that = this;
  99. dd.ready(function() {
  100. dd.runtime.permission.requestAuthCode({
  101. corpId: query.corpId, // 企业id
  102. onSuccess: function (info) {
  103. //that.message = info.code
  104. that.code = info.code
  105. },
  106. onFail : function(err) {
  107. alert('dd error1: ' + JSON.stringify(err));
  108. }
  109. });
  110. });
  111. dd.error(function(error){
  112. alert('dd error: ' + JSON.stringify(error));
  113. });
  114. },
  115. }
  116. </script>