editTable.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <hc-sys id="app-sys" class="h-full hc-uni-app-table-form" :isNavBar="false">
  3. <view id="title-bar" class="title-bar z-24">
  4. <button type="primary" class="title-bar-btn" @click="editTypeClick">切换</button>
  5. <button type="primary" class="title-bar-btn" @click="toCopyClick">复制</button>
  6. <button type="primary" class="title-bar-btn" @click="toHideClick">隐藏</button>
  7. <button type="primary" class="title-bar-btn" @click="previewClick">预览</button>
  8. <button type="primary" class="title-bar-btn" @click="toFileUp">{{pageNode.tabFileType === 2?'已上传':'上传'}}</button>
  9. </view>
  10. <template v-if="webviewShow">
  11. <web-view :update-title="false" :webview-styles="webViewStyle" :style="webViewStyle" :src="webSrc" name="exceliframe" @message="handleMessage"/>
  12. </template>
  13. <view id="action-bar" class="action-bar z-24">
  14. <button type="primary" class="action-bar-btn" @click="formSaveClick">保 存</button>
  15. </view>
  16. </hc-sys>
  17. </template>
  18. <script setup>
  19. import {ref, getCurrentInstance} from "vue";
  20. import {onLoad, onShow, onReady, onUnload} from '@dcloudio/uni-app'
  21. import {errorToast, successToast, toPdfPreview, querySelect} from "@/utils/tools";
  22. import {getStorage} from "@/utils/storage";
  23. import {useAppStore} from "@/store";
  24. import wbsApi from '~api/data-fill/wbs';
  25. import {getFormApiUrl} from '@/config/envApi';
  26. import api from '~api/api';
  27. const store = useAppStore()
  28. const instance = getCurrentInstance().proxy
  29. let wv; //计划创建的webview
  30. //初始变量
  31. const contractInfo = ref(store.contractInfo);
  32. const projectId = ref(store.projectId);
  33. const contractId = ref(store.contractId);
  34. const pageNode = ref({});
  35. const webViewStyle = ref({})
  36. const webviewShow = ref(true)
  37. onLoad((option) => {
  38. // #ifdef H5
  39. window.addEventListener('message', handleMessage);
  40. // #endif
  41. const user = encodeURIComponent(JSON.stringify(getStorage('login_user_info')))
  42. if (option.node) {
  43. uni.showLoading({title: '加载中...', mask: true});
  44. const res = JSON.parse(decodeURIComponent(option.node));
  45. uni.setNavigationBarTitle({
  46. title: res.title
  47. })
  48. pageNode.value = res
  49. webSrc.value = `${htmlsrc}&user=${user}&node=${option.node}`
  50. queryNodeStatus()
  51. } else {
  52. errorToast('参数错误');
  53. setTimeout(() => {
  54. toBack()
  55. },1500)
  56. }
  57. })
  58. onShow(() => {
  59. webviewShow.value = true
  60. })
  61. //表格地址
  62. const webSrc = ref('');
  63. const envUrl = getFormApiUrl()
  64. const htmlsrc = `${envUrl}/#/app/table-form?date=${new Date().getTime()}&source=app&type=data-fill`
  65. //渲染完成
  66. onReady(() => {
  67. setWebViewStyle()
  68. })
  69. const setWebViewStyle = async () => {
  70. // #ifdef APP-PLUS
  71. await initWebview()
  72. // #endif
  73. const appSys = await querySelect(instance, 'app-sys')
  74. const appSysHeight = appSys.height
  75. //顶部
  76. const titleBar = await querySelect(instance, 'title-bar')
  77. const titleBarHeight = titleBar?.height ?? 48
  78. // #ifdef H5
  79. webViewStyle.value.top = titleBarHeight + 'px'
  80. // #endif
  81. // #ifdef APP-PLUS
  82. const {statusBarHeight} = uni.getSystemInfoSync()
  83. webViewStyle.value.top = statusBarHeight + 45 + titleBarHeight
  84. // #endif
  85. //底部
  86. const actionBar = await querySelect(instance,'action-bar')
  87. const actionBarHeight = actionBar?.height ?? 80
  88. webViewStyle.value.height = (appSysHeight - titleBarHeight - actionBarHeight - 3) + 'px'
  89. }
  90. //初始化webview
  91. const initWebview = async () => {
  92. return new Promise((resolve) => {
  93. let currentWebview = instance.$scope.$getAppWebview()
  94. //如果是页面初始化调用时,需要延时一下
  95. setTimeout(() => {
  96. wv = currentWebview.children()[0]
  97. wv.setStyle({scalable:true})
  98. // #ifdef APP-PLUS
  99. //ios 禁用缓存,测试生效!!
  100. let cache1 = plus.ios.newObject('NSURLCache');
  101. let cache = plus.ios.invoke(cache1, 'sharedURLCache');
  102. plus.ios.invoke(cache, 'removeAllCachedResponses');
  103. plus.ios.invoke(cache, 'setDiskCapacity:', 0);
  104. plus.ios.invoke(cache, 'setMemoryCapacity:', 0);
  105. //安卓端缓存清理。
  106. plus.cache.clear();
  107. // #endif
  108. resolve(true)
  109. }, 1000);
  110. })
  111. }
  112. const isFormRender = ref(false)
  113. const handleMessage = async (event) => {
  114. let msg = {};
  115. // #ifdef H5
  116. if (event.data && event.data.data && event.data.data.arg) {
  117. msg = event.data.data.arg
  118. }
  119. // #endif
  120. // #ifdef APP-PLUS
  121. msg = event.detail.data[0]
  122. // #endif
  123. if (msg.source === 'web') {
  124. if (msg.type === 'formRender') {
  125. uni.hideLoading();
  126. isFormRender.value = true
  127. }
  128. if (msg.type === 'back') {
  129. toBack() //收到通知,刷新列表去
  130. }
  131. //保存成功
  132. if (msg.type === 'saveSuccess') {
  133. uni.hideLoading();
  134. await queryNodeStatus()
  135. await previewClick()
  136. }
  137. //消息提示
  138. if (msg.type === 'msg') {
  139. uni.hideLoading();
  140. const { title, icon } = msg.data
  141. uni.showToast({
  142. title: title,
  143. duration: 2000,
  144. icon: icon,
  145. mask: true
  146. });
  147. }
  148. }
  149. }
  150. //当前节点状态, 1 未填报,2待上报,3已上报
  151. const queryNodeStatus = async () => {
  152. const {classify, treeId, status} = pageNode.value
  153. let url = `blade-business/informationWriteQuery/${classify === 1?'queryNodeStatus': 'queryNodeStatus-jl'}`;
  154. //查询节点状态
  155. const { error, code, data } = await api.post({
  156. url: url,
  157. params: {
  158. primaryKeyId: treeId ?? '',
  159. classify: classify,
  160. }
  161. })
  162. if (!error && code === 200) {
  163. pageNode.value.status = data ?? status
  164. }
  165. }
  166. const toBack = () => {
  167. webviewShow.value = false
  168. uni.navigateBack()
  169. }
  170. onUnload(()=>{
  171. // #ifdef H5
  172. window.removeEventListener('message', handleMessage);
  173. // #endif
  174. })
  175. //切换显示模式
  176. const editType = ref('form')
  177. const editTypeClick = () => {
  178. if (isFormRender.value === false) {
  179. errorToast('表单未渲染完成,请稍后再试');
  180. return
  181. }
  182. const type = editType.value === 'form' ? 'table' : 'form'
  183. // #ifdef H5
  184. window.frames["exceliframe"].postMessage({
  185. type: 'editTypeClick',
  186. source: 'app',
  187. data: type
  188. }, envUrl);
  189. // #endif
  190. // #ifdef APP-PLUS
  191. wv.evalJS(`editTypeClick('${type}')`)
  192. // #endif
  193. editType.value = type
  194. }
  195. //复制本表
  196. const toCopyClick = async () => {
  197. if (isFormRender.value === false) {
  198. errorToast('表单未渲染完成,请稍后再试');
  199. return
  200. }
  201. const { pkeyId, status } = pageNode.value
  202. if (!pkeyId) {
  203. errorToast('pkeyId为空');
  204. return
  205. } else if (status === '3') {
  206. errorToast('已上报的资料,不允许复制');
  207. return
  208. }
  209. uni.showLoading({title: '复制中...', mask: true});
  210. const { error, code, msg } = await wbsApi.copeBussTab({
  211. pkeyId: pkeyId,
  212. })
  213. uni.hideLoading();
  214. if (!error && code === 200) {
  215. successToast('复制成功');
  216. setTimeout(() => {
  217. toBack()
  218. }, 1500)
  219. } else {
  220. errorToast('复制失败:' + msg);
  221. }
  222. }
  223. //隐藏表单
  224. const toHideClick = async () => {
  225. if (isFormRender.value === false) {
  226. errorToast('表单未渲染完成,请稍后再试');
  227. return
  228. }
  229. const { pkeyId, status } = pageNode.value
  230. if (!pkeyId) {
  231. errorToast('pkeyId为空');
  232. return
  233. } else if (status === '3') {
  234. errorToast('已上报的资料,不允许隐藏示');
  235. return
  236. }
  237. uni.showLoading({title: '隐藏中...', mask: true});
  238. const { error, code, msg } = await wbsApi.showBussTab({
  239. pkeyId: pkeyId,
  240. status: 2,
  241. })
  242. uni.hideLoading();
  243. if (!error && code === 200) {
  244. successToast('隐藏成功');
  245. setTimeout(() => {
  246. toBack()
  247. }, 1500)
  248. } else {
  249. errorToast('隐藏失败:' + msg);
  250. }
  251. }
  252. //预览表单
  253. const previewClick = async () => {
  254. if (isFormRender.value === false) {
  255. errorToast('表单未渲染完成,请稍后再试');
  256. return
  257. }
  258. const { pkeyId, isBussShow, isTabPdf, pdfUrl } = pageNode.value
  259. if (!pkeyId) {
  260. errorToast('pkeyId为空');
  261. return
  262. } else if (isBussShow === 2 || isTabPdf === 1 || pdfUrl === '') {
  263. errorToast('当前状态无法预览');
  264. return
  265. }
  266. uni.showLoading({title: '获取PDF中...', mask: true});
  267. const { error, code, data, msg } = await wbsApi.getBussPdfInfo({
  268. pkeyId: pkeyId,
  269. })
  270. uni.hideLoading();
  271. if (!error && code === 200 && data) {
  272. toPdfPreview(data).then()
  273. } else {
  274. errorToast('获取失败:' + msg);
  275. }
  276. }
  277. //保存
  278. const formSaveClick = () => {
  279. if (isFormRender.value === false) {
  280. errorToast('表单未渲染完成,请稍后再试');
  281. return
  282. }
  283. uni.showLoading({title: '保存中...', mask: true})
  284. // #ifdef H5
  285. window.frames["exceliframe"].postMessage({
  286. type: 'formSave',
  287. source: 'app',
  288. data: {}
  289. }, envUrl);
  290. // #endif
  291. // #ifdef APP-PLUS
  292. wv.evalJS(`formSave()`)
  293. // #endif
  294. }
  295. //上传
  296. const toFileUp = () => {
  297. if (isFormRender.value === false) {
  298. errorToast('表单未渲染完成,请稍后再试');
  299. return
  300. }
  301. const { pkeyId, status } = pageNode.value
  302. if (!pkeyId) {
  303. errorToast('pkeyId为空');
  304. return
  305. } else if (status === '3') {
  306. errorToast('已上报的资料,不允许上传');
  307. return
  308. }
  309. uni.navigateTo({
  310. url: '/pages/data-fill/fileUp?node=' + encodeURIComponent(JSON.stringify(pageNode.value))
  311. });
  312. }
  313. </script>
  314. <style lang="scss" scoped>
  315. page {
  316. height: 100%;
  317. background: #FAFBFE;
  318. }
  319. .hc-uni-app-table-form {
  320. .title-bar {
  321. position: absolute;
  322. top: 0;
  323. display: flex;
  324. width: 100%;
  325. padding: 15rpx;
  326. background: #E8EEF2;
  327. overflow-x: auto;
  328. white-space: nowrap;
  329. z-index: 9999;
  330. .title-bar-btn {
  331. flex: 1;
  332. color: #6FCC9F;
  333. background-color: #EBF9F4;
  334. height: 58rpx;
  335. font-size: 25rpx;
  336. padding: 0;
  337. margin: 0;
  338. line-height: initial;
  339. border-radius: 6rpx;
  340. display: flex;
  341. justify-content: center;
  342. align-items: center;
  343. &:after {
  344. display: none;
  345. }
  346. }
  347. .title-bar-btn + .title-bar-btn {
  348. margin-left: 16rpx;
  349. }
  350. }
  351. .action-bar {
  352. position: absolute;
  353. bottom: 0;
  354. width: 100%;
  355. display: flex;
  356. background: white;
  357. padding: 28rpx 28rpx calc(var(--window-bottom) + 34rpx);
  358. .action-bar-btn {
  359. flex: 1;
  360. }
  361. }
  362. }
  363. </style>