index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <tki-qrcode class="jnpf-qrcode" v-if="qrcode&&showQrcode" ref="qrcode" :cid="cid" :val="qrcode" :size="width*2"
  3. :background="colorLight" :foreground="colorDark" onval loadMake :showLoading="false" />
  4. </template>
  5. <script>
  6. import tkiQrcode from "./tki-qrcode/tki-qrcode.vue"
  7. let unique = 0
  8. export default {
  9. name: 'qrcode',
  10. props: {
  11. dataType: {
  12. type: String,
  13. default: 'static'
  14. },
  15. colorLight: {
  16. type: String,
  17. default: "#fff"
  18. },
  19. colorDark: {
  20. type: String,
  21. default: "#000"
  22. },
  23. relationField: {
  24. type: String,
  25. default: ''
  26. },
  27. formData: {
  28. type: Object
  29. },
  30. width: {
  31. type: Number,
  32. default: 200
  33. },
  34. staticText: {
  35. type: String,
  36. default: ''
  37. }
  38. },
  39. components: {
  40. tkiQrcode
  41. },
  42. computed: {
  43. qrcode() {
  44. if (this.dataType === 'static') {
  45. return this.staticText
  46. } else if (this.dataType === 'relation') {
  47. return this.relationText?.toString()
  48. } else {
  49. if (this.formData && this.dynamicModelExtra && this.dynamicModelExtra.id && this.dynamicModelExtra
  50. .modelId) {
  51. const json = {
  52. t: 'DFD',
  53. id: this.dynamicModelExtra.id,
  54. mid: this.dynamicModelExtra.modelId,
  55. mt: this.dynamicModelExtra.type,
  56. fid: this.dynamicModelExtra.flowId || '',
  57. pid: this.dynamicModelExtra.processId || '',
  58. ftid: this.dynamicModelExtra.taskId || '',
  59. opt: this.dynamicModelExtra.opType
  60. }
  61. return JSON.stringify(json)
  62. }
  63. return ''
  64. }
  65. },
  66. dynamicModelExtra() {
  67. return uni.getStorageSync('dynamicModelExtra') || null
  68. }
  69. },
  70. data() {
  71. return {
  72. cid: '',
  73. relationText: "",
  74. showQrcode: false
  75. }
  76. },
  77. mounted() {
  78. this.cid = this.uuid()
  79. this.showQrcode = true
  80. uni.$on('updateCode', () => {
  81. this.showQrcode = false
  82. this.$nextTick(() => {
  83. this.showQrcode = true
  84. })
  85. })
  86. },
  87. watch: {
  88. formData: {
  89. handler(val) {
  90. const relationValue = val[this.relationField] || val[this.relationField] === 0 || val[this
  91. .relationField] === false ? val[this.relationField] : ''
  92. if (val && this.dataType === 'relation' && this.relationField) this.relationText = relationValue
  93. },
  94. deep: true,
  95. immediate: true
  96. },
  97. },
  98. methods: {
  99. uuid() {
  100. const time = Date.now()
  101. const random = Math.floor(Math.random() * 1000000000)
  102. unique++
  103. return 'qrcode_' + random + unique + String(time)
  104. }
  105. },
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .jnpf-qrcode {
  110. width: 100%;
  111. overflow: hidden;
  112. margin-bottom: -20rpx;
  113. }
  114. </style>