securityCheckEditor.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. style: {
  5. navigationBarTitleText: '',
  6. navigationStyle: 'custom',
  7. disableScroll: true,
  8. },
  9. }
  10. </route>
  11. <template>
  12. <div>
  13. <SpreadDesignerGeneric
  14. :businessConfig="businessConfig"
  15. :templateData="templateData"
  16. :templateBlob="templateBlob"
  17. />
  18. </div>
  19. </template>
  20. <script setup lang="ts">
  21. import { ref } from 'vue'
  22. import SpreadDesignerGeneric from '@/components/SpreadDesigner/spreadDesignerGeneric.vue'
  23. import { onLoad } from '@dcloudio/uni-app'
  24. import { getStandardTemplate } from '@/api/index'
  25. import { buildFileUrl } from '@/utils/index'
  26. import { createSecurityCheck } from '@/api/boiler/boilerTaskOrderSecurityCheck'
  27. import { getDynamicTbVal } from '@/api/task'
  28. const businessConfig = ref({
  29. businessType: 'AQJC',
  30. title: '安全检查记录编辑',
  31. disableNavigate: true, // 是否禁用跳转,默认不禁用
  32. ui: {
  33. title: '安全检查记录',
  34. saveButtonText: '保存',
  35. cancelButtonText: '取消',
  36. showAdditionalToolbar: true,
  37. customButtons: [],
  38. },
  39. })
  40. const templateBlob = ref<string>('')
  41. const templateData = ref<any>({})
  42. let templateId: string = ''
  43. let orderId: string = ''
  44. onLoad((options: any) => {
  45. templateId = options.templateId
  46. orderId = options.orderId
  47. init()
  48. })
  49. const init = async () => {
  50. if (!templateId) {
  51. return
  52. }
  53. const createResp = await createSecurityCheck({
  54. businessType: 300,
  55. conclusion: '',
  56. date: null,
  57. name: '进入现场(设备)前安全检查记录',
  58. orderId,
  59. templateId,
  60. })
  61. const refId = createResp.data
  62. const res = await getStandardTemplate({ id: templateId })
  63. const resData = (res as any).data
  64. const dataMap: any = {}
  65. const dynamicTbValResp = await getDynamicTbVal({ refId })
  66. const dynamicTb: any = dynamicTbValResp.data
  67. for (let i = 0; i < dynamicTb.dynamicTbValRespVOList.length; i++) {
  68. const item = dynamicTb.dynamicTbValRespVOList[i]
  69. dataMap[item.colCode] = item.valValue
  70. }
  71. templateData.value = {
  72. schema: resData.bindingPathSchema ? JSON.parse(resData.bindingPathSchema) : {},
  73. data: {
  74. ...dataMap,
  75. templateId,
  76. templateUrl: resData.fileUrl,
  77. },
  78. pathNameMapping: JSON.parse(resData.bindingPathNameJson),
  79. template: templateId,
  80. templateUrl: resData.fileUrl,
  81. }
  82. const fileUri = resData.fileUrl
  83. const fileUrl = buildFileUrl(fileUri)
  84. const fileBase64 = await downloadFileAsBase64(fileUrl)
  85. templateBlob.value = fileBase64
  86. }
  87. const downloadFileAsBase64 = (fileUrl: string): Promise<string> => {
  88. return new Promise((resolve, reject) => {
  89. uni.request({
  90. url: fileUrl,
  91. method: 'GET',
  92. responseType: 'arraybuffer',
  93. success: (res) => {
  94. if (res.statusCode === 200) {
  95. const arrayBuffer = res.data as ArrayBuffer
  96. const uint8Array = new Uint8Array(arrayBuffer)
  97. const binaryString = uint8Array.reduce((data, byte) => {
  98. return data + String.fromCharCode(byte)
  99. }, '')
  100. const base64 = btoa(binaryString)
  101. resolve(base64) // 成功时 resolve Base64 字符串
  102. } else {
  103. reject(new Error(`Request failed with status ${res.statusCode}`))
  104. }
  105. },
  106. fail: (err) => {
  107. reject(err) // 失败时 reject 错误
  108. },
  109. })
  110. })
  111. }
  112. </script>