BindWx.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogVisible"
  5. width="30%"
  6. destroy-on-close
  7. :close-on-click-modal="false"
  8. >
  9. <div class="content-container">
  10. <el-row type="flex" justify="center" align="middle">
  11. <div id="qrcodetemplate" ref="qrcodetemplate" style="margin: 5px 0;" />
  12. </el-row>
  13. <el-row type="flex" justify="center">
  14. <span>{{ viewData.note }}</span>
  15. </el-row>
  16. </div>
  17. </el-dialog>
  18. </template>
  19. <script>
  20. import { serverUrl, devServerUrl } from '@/settings'
  21. import QRCode from 'qrcodejs2'
  22. import { mapGetters } from 'vuex'
  23. import { isNotNull } from '@/utils'
  24. export default {
  25. name: 'BindWx',
  26. props: {
  27. title: {
  28. type: String,
  29. default: '微信绑定'
  30. }
  31. },
  32. data() {
  33. return {
  34. dialogVisible: false,
  35. userId: undefined,
  36. code: '',
  37. viewData: {
  38. note: ''
  39. }
  40. }
  41. },
  42. computed: {
  43. ...mapGetters([
  44. 'userData'
  45. ])
  46. },
  47. created() {
  48. },
  49. methods: {
  50. // 外部调用接口
  51. show(userId, objCode) {
  52. this.userId = userId
  53. if (isNotNull(objCode)) {
  54. this.viewData.note = '已有绑定'
  55. } else {
  56. this.viewData.note = '未绑定微信'
  57. }
  58. this.dialogVisible = true
  59. this.drawQrcode()
  60. },
  61. // 显示绑定二维码
  62. drawQrcode() {
  63. const ocId = this.userData.ocId
  64. const userId = this.userId
  65. const baseURL = process.env.NODE_ENV === 'development' ? devServerUrl : serverUrl
  66. const url = baseURL + '/wx/auth/' + ocId + '/' + userId
  67. if (!url) {
  68. this.$message.error('没有生产二维码的参数')
  69. return
  70. }
  71. this.$nextTick(() => {
  72. this.$refs.qrcodetemplate.innerHTML = ''
  73. new QRCode('qrcodetemplate', {
  74. width: 200,
  75. height: 200,
  76. text: url.toString()
  77. })
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. #qrcodetemplate{
  85. width: 200px;
  86. height: 200px;
  87. margin: 0 auto;
  88. }
  89. </style>