金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.9 KiB

  1. <template>
  2. <view>
  3. <!-- #ifdef MP-WEIXIN -->
  4. <canvas :canvas-id="item.id" :id="item.id" :style="{width:size,height: size}" v-for="(item,index) in listCode" :key="item.id" />
  5. <!-- #endif -->
  6. <!-- #ifndef MP-WEIXIN -->
  7. <canvas :canvas-id="id" :id="id" :style="{width:size,height: size}" />
  8. <!-- #endif -->
  9. </view>
  10. </template>
  11. <script>
  12. import QRCODE from './index.js';
  13. import { getUUid, deepClone } from './helper.js'
  14. export default {
  15. name: 'WQrcode',
  16. props:{
  17. options:{
  18. type: Object,
  19. required: true,
  20. default: () =>{
  21. return {
  22. }
  23. }
  24. }
  25. },
  26. data () {
  27. return {
  28. listCode:[],
  29. id: getUUid(),
  30. size: null,
  31. }
  32. },
  33. created() {
  34. // https://ext.dcloud.net.cn/plugin?id=4662
  35. this.size = this.options.size + 'rpx';
  36. this.SpecialTreatment(this.options)
  37. this.$nextTick(()=>{
  38. this.generateCode();
  39. })
  40. },
  41. watch: {
  42. options:{
  43. deep: true,
  44. handler (val) {
  45. this.size = val.size +'rpx';
  46. this.SpecialTreatment(val)
  47. // #ifdef H5
  48. setTimeout(()=>{// h5平台动态改变canvas大小
  49. this.generateCode();
  50. },50)
  51. // #endif
  52. // #ifdef APP-NVUE || APP-PLUS || MP || QUICKAPP-WEBVIEW || QUICKAPP-WEBVIEW-HUAWEI || QUICKAPP-WEBVIEW-UNION
  53. this.generateCode();
  54. // #endif
  55. }
  56. }
  57. },
  58. methods: {
  59. SpecialTreatment (val) {//微信小程序渲染多个canvas特殊处理
  60. // #ifdef MP-WEIXIN
  61. let obj = deepClone(val);
  62. this.id = obj.id = getUUid();
  63. this.listCode = [obj]
  64. // #endif
  65. },
  66. generateCode () {
  67. try{
  68. const parameter = {...this.options,id: this.id,ctx: this};
  69. QRCODE.QRCode(parameter,(res)=>{
  70. this.$emit('generate',res)
  71. })
  72. }catch(err){}
  73. },
  74. async saveImg (){
  75. try{
  76. const res = await QRCODE.SaveImg({id: this.id,width: this.size,height: this.size,ctx: this});
  77. return res
  78. }catch(e){}
  79. }
  80. }
  81. }
  82. </script>