index copy.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. style: {
  5. navigationBarTitleText: '安全检查记录详情',
  6. navigationStyle: 'custom',
  7. },
  8. }
  9. </route>
  10. <template>
  11. <view class="detail-container">
  12. <!-- 导航栏 -->
  13. <NavBar>
  14. <template #title>
  15. <HeadView v-if="renderCenter" title="操作指导书批准详情" :btn-array="btnArray" />
  16. <text v-else class="nav-title">安全检查记录详情</text>
  17. </template>
  18. </NavBar>
  19. <!-- PDF 预览区域 -->
  20. <view class="pdf-container">
  21. <view v-if="loading" class="loading-container">
  22. <text class="loading-text">加载中...</text>
  23. </view>
  24. <SpreadPDFViewer
  25. ref="spreadPdfViewerRef"
  26. :businessConfig="businessConfig"
  27. :templateData="templateData"
  28. :templateBlob="templateBlob"
  29. />
  30. </view>
  31. </view>
  32. </template>
  33. <script lang="ts" setup>
  34. import { ref, computed, onMounted } from 'vue'
  35. import { onLoad } from '@dcloudio/uni-app'
  36. import HeadView from '../components/HeadView.vue'
  37. import NavBar from '@/components/NavBar/NavBar.vue'
  38. import SpreadPDFViewer from '@/components/SpreadDesigner/SpreadPDFViewer.vue'
  39. import { useConfigStore } from '@/store/config'
  40. import { buildFileUrl } from '@/utils/index'
  41. import { requestFunc, SecurityCheckFuncName } from '@/api/ApiRouter/taskOrderSecurityCheck'
  42. import { getDynamicTbVal } from '@/api/task'
  43. import { getStandardTemplate } from '@/api'
  44. const configStore = useConfigStore()
  45. const equipType = configStore.getEquipType()
  46. // 路由参数
  47. const detailItem = ref<any>({})
  48. const orderId = ref('')
  49. const unitContact = ref('')
  50. const unitPhone = ref('')
  51. const receiverEmail = ref('')
  52. const templateId = ref('')
  53. const spreadPdfViewerRef = ref<any>(null)
  54. const templateBlob = ref<any>(null)
  55. const businessConfig = ref<any>({
  56. businessType: 'AQJC',
  57. title: '安全检查记录编辑',
  58. disableNavigate: true, // 是否禁用跳转,默认不禁用
  59. ui: {
  60. title: '安全检查记录',
  61. saveButtonText: '保存',
  62. cancelButtonText: '取消',
  63. showAdditionalToolbar: true,
  64. customButtons: [],
  65. },
  66. })
  67. const templateData = ref<any>({})
  68. onLoad((options) => {
  69. orderId.value = options.orderId || ''
  70. unitContact.value = options.unitContact || ''
  71. unitPhone.value = options.unitPhone || ''
  72. receiverEmail.value = options.receiverEmail || ''
  73. templateId.value = options.templateId || ''
  74. if (options.detailItem) {
  75. try {
  76. detailItem.value = JSON.parse(decodeURIComponent(options.detailItem))
  77. } catch (e) {
  78. console.error('解析 detailItem 失败:', e)
  79. }
  80. }
  81. })
  82. // 状态
  83. const loading = ref(false)
  84. // 是否显示操作按钮 (对应 PJ 中的 useMemo 计算)
  85. const renderCenter = computed(() => {
  86. const { id } = detailItem.value || {}
  87. if (!id) return false
  88. return true
  89. })
  90. // 操作按钮数组 (与 PJ 版本一致,空数组)
  91. const btnArray = computed(() => {
  92. const { signFilePdf, id } = detailItem.value || {}
  93. if (!id) return []
  94. return [
  95. // { value: signFilePdf ? '重新签名' : '签名', color: 'rgb(47,142,255)', click: handleToSign },
  96. ]
  97. })
  98. // 初始化
  99. const init = async () => {
  100. loading.value = true
  101. try {
  102. // const tplParams = await handleGetTemplate()
  103. // await getAppServiceOrderPDF(tplParams)
  104. const id = detailItem.value?.id || ''
  105. if (!id) return
  106. const defaultTemplateResp = await requestFunc(SecurityCheckFuncName.getTemplate, equipType, { orderId: orderId.value })
  107. const res = await getStandardTemplate({ id: defaultTemplateResp.data?.templateId })
  108. const resData = (res as any).data
  109. const dataMap: any = {}
  110. const dynamicTbValResp = await getDynamicTbVal({ refId: id })
  111. const dynamicTb: any = dynamicTbValResp.data
  112. for (let i = 0; i < dynamicTb.dynamicTbValRespVOList.length; i++) {
  113. const item = dynamicTb.dynamicTbValRespVOList[i]
  114. dataMap[item.colCode] = item.valValue
  115. }
  116. // 组装templateData
  117. templateData.value = {
  118. schema: resData.bindingPathSchema ? JSON.parse(resData.bindingPathSchema) : {},
  119. data: {
  120. ...dataMap,
  121. templateId,
  122. templateUrl: resData.fileUrl,
  123. },
  124. pathNameMapping: JSON.parse(resData.bindingPathNameJson),
  125. template: templateId,
  126. templateUrl: resData.fileUrl,
  127. }
  128. console.log(templateData.value)
  129. // 获取 template 文件
  130. const fileUri = resData.fileUrl
  131. const fileUrl = buildFileUrl(fileUri)
  132. const fileBase64 = await spreadPdfViewerRef.value.downloadFileAsBase64(fileUrl)
  133. templateBlob.value = fileBase64
  134. } catch (error) {
  135. console.error('[Page] 初始化失败:', error)
  136. uni.showToast({ title: 'PDF 加载失败', icon: 'none' })
  137. } finally {
  138. loading.value = false
  139. }
  140. }
  141. onMounted(async () => {
  142. await init()
  143. })
  144. </script>
  145. <style lang="scss" scoped>
  146. .detail-container {
  147. display: flex;
  148. flex-direction: column;
  149. height: 100vh;
  150. background-color: #f5f5f5;
  151. }
  152. .navigate-view {
  153. display: flex;
  154. flex-direction: row;
  155. align-items: center;
  156. justify-content: space-between;
  157. height: 44px;
  158. padding: 0 15px;
  159. background-color: #fff;
  160. border-bottom: 1px solid #eee;
  161. }
  162. .navigate-left {
  163. display: flex;
  164. align-items: center;
  165. width: 44px;
  166. }
  167. .back-icon {
  168. width: 20px;
  169. height: 20px;
  170. }
  171. .navigate-center {
  172. display: flex;
  173. flex: 1;
  174. justify-content: center;
  175. }
  176. .navigate-title {
  177. font-size: 17px;
  178. font-weight: 500;
  179. color: #333;
  180. }
  181. .navigate-right {
  182. display: flex;
  183. align-items: center;
  184. width: 44px;
  185. }
  186. .nav-title {
  187. font-size: 17px;
  188. font-weight: 500;
  189. color: #333;
  190. }
  191. .pdf-container {
  192. flex: 1;
  193. background-color: #f5f5f5;
  194. }
  195. /* #ifdef H5 */
  196. .pdf-viewer-container {
  197. box-sizing: border-box;
  198. width: 100%;
  199. height: 100%;
  200. padding: 10px;
  201. text-align: center;
  202. background-color: #fff;
  203. }
  204. /* #endif */
  205. .loading-container,
  206. .empty-container {
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. height: 100%;
  211. }
  212. .loading-text,
  213. .empty-text {
  214. font-size: 14px;
  215. color: #999;
  216. }
  217. </style>