| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <route lang="json5" type="page">
- {
- layout: 'default',
- style: {
- navigationBarTitleText: '',
- navigationStyle: 'custom',
- disableScroll: true,
- },
- }
- </route>
- <template>
- <div>
- <SpreadDesignerGeneric
- :businessConfig="businessConfig"
- :templateData="templateData"
- :templateBlob="templateBlob"
- />
- </div>
- </template>
- <script setup lang="ts">
- import { ref } from 'vue'
- import SpreadDesignerGeneric from '@/components/SpreadDesigner/spreadDesignerGeneric.vue'
- import { onLoad } from '@dcloudio/uni-app'
- import { getStandardTemplate } from '@/api/index'
- import { buildFileUrl } from '@/utils/index'
- import { createSecurityCheck } from '@/api/boiler/boilerTaskOrderSecurityCheck'
- import { getDynamicTbVal } from '@/api/task'
- const businessConfig = ref({
- businessType: 'AQJC',
- title: '安全检查记录编辑',
- disableNavigate: true, // 是否禁用跳转,默认不禁用
- ui: {
- title: '安全检查记录',
- saveButtonText: '保存',
- cancelButtonText: '取消',
- showAdditionalToolbar: true,
- customButtons: [],
- },
- })
- const templateBlob = ref<string>('')
- const templateData = ref<any>({})
- let templateId: string = ''
- let orderId: string = ''
- onLoad((options: any) => {
- templateId = options.templateId
- orderId = options.orderId
- init()
- })
- const init = async () => {
- if (!templateId) {
- return
- }
- const createResp = await createSecurityCheck({
- businessType: 300,
- conclusion: '',
- date: null,
- name: '进入现场(设备)前安全检查记录',
- orderId,
- templateId,
- })
- const refId = createResp.data
- const res = await getStandardTemplate({ id: templateId })
- const resData = (res as any).data
- const dataMap: any = {}
- const dynamicTbValResp = await getDynamicTbVal({ refId })
- const dynamicTb: any = dynamicTbValResp.data
- for (let i = 0; i < dynamicTb.dynamicTbValRespVOList.length; i++) {
- const item = dynamicTb.dynamicTbValRespVOList[i]
- dataMap[item.colCode] = item.valValue
- }
- templateData.value = {
- schema: resData.bindingPathSchema ? JSON.parse(resData.bindingPathSchema) : {},
- data: {
- ...dataMap,
- templateId,
- templateUrl: resData.fileUrl,
- },
- pathNameMapping: JSON.parse(resData.bindingPathNameJson),
- template: templateId,
- templateUrl: resData.fileUrl,
- }
- const fileUri = resData.fileUrl
- const fileUrl = buildFileUrl(fileUri)
- const fileBase64 = await downloadFileAsBase64(fileUrl)
- templateBlob.value = fileBase64
- }
- const downloadFileAsBase64 = (fileUrl: string): Promise<string> => {
- return new Promise((resolve, reject) => {
- uni.request({
- url: fileUrl,
- method: 'GET',
- responseType: 'arraybuffer',
- success: (res) => {
- if (res.statusCode === 200) {
- const arrayBuffer = res.data as ArrayBuffer
- const uint8Array = new Uint8Array(arrayBuffer)
- const binaryString = uint8Array.reduce((data, byte) => {
- return data + String.fromCharCode(byte)
- }, '')
- const base64 = btoa(binaryString)
- resolve(base64) // 成功时 resolve Base64 字符串
- } else {
- reject(new Error(`Request failed with status ${res.statusCode}`))
- }
- },
- fail: (err) => {
- reject(err) // 失败时 reject 错误
- },
- })
- })
- }
- </script>
|