editTable.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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">
  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 :webview-styles="webViewStyle" :style="webViewStyle" :src="webSrc" name="exceliframe" @message="handleMessage"/>
  12. </template>
  13. <view id="action-bar" class="action-bar">
  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. const store = useAppStore()
  27. const instance = getCurrentInstance().proxy
  28. let wv; //计划创建的webview
  29. //初始变量
  30. const contractInfo = ref(store.contractInfo);
  31. const projectId = ref(store.projectId);
  32. const contractId = ref(store.contractId);
  33. const pageNode = ref({});
  34. const webViewStyle = ref({})
  35. const webviewShow = ref(true)
  36. onLoad((option) => {
  37. // #ifdef H5
  38. window.addEventListener('message', handleMessage);
  39. // #endif
  40. const user = encodeURIComponent(JSON.stringify(getStorage('login_user_info')))
  41. if (option.node) {
  42. const res = JSON.parse(decodeURIComponent(option.node));
  43. uni.setNavigationBarTitle({
  44. title: res.title
  45. })
  46. pageNode.value = res
  47. webSrc.value = `${htmlsrc}&user=${user}&node=${option.node}`
  48. }
  49. })
  50. onShow(() => {
  51. webviewShow.value = true
  52. })
  53. //表格地址
  54. const webSrc = ref('');
  55. const envUrl = getFormApiUrl()
  56. const htmlsrc = `${envUrl}/#/app/table-form?source=app&type=data-fill`
  57. //渲染完成
  58. onReady(() => {
  59. setWebViewStyle()
  60. })
  61. const setWebViewStyle = async () => {
  62. // #ifdef APP-PLUS
  63. await initWebview()
  64. // #endif
  65. const appSys = await querySelect(instance, 'app-sys')
  66. const appSysHeight = appSys.height
  67. //顶部
  68. const titleBar = await querySelect(instance, 'title-bar')
  69. const titleBarHeight = titleBar?.height ?? 48
  70. // #ifdef H5
  71. webViewStyle.value.top = titleBarHeight + 'px'
  72. // #endif
  73. // #ifdef APP-PLUS
  74. const {statusBarHeight} = uni.getSystemInfoSync()
  75. webViewStyle.value.top = statusBarHeight + 45 + titleBarHeight
  76. // #endif
  77. //底部
  78. const actionBar = await querySelect(instance,'action-bar')
  79. const actionBarHeight = actionBar?.height ?? 80
  80. webViewStyle.value.height = (appSysHeight - titleBarHeight - actionBarHeight - 3) + 'px'
  81. }
  82. //初始化webview
  83. const initWebview = async () => {
  84. return new Promise((resolve) => {
  85. let currentWebview = instance.$scope.$getAppWebview()
  86. //如果是页面初始化调用时,需要延时一下
  87. setTimeout(() => {
  88. wv = currentWebview.children()[0]
  89. wv.setStyle({scalable:true})
  90. resolve(true)
  91. }, 1000);
  92. })
  93. }
  94. const handleMessage = (event) => {
  95. let msg = {};
  96. // #ifdef H5
  97. if (event.data && event.data.data && event.data.data.arg) {
  98. msg = event.data.data.arg
  99. }
  100. // #endif
  101. // #ifdef APP-PLUS
  102. msg = event.detail.data[0]
  103. // #endif
  104. if (msg.source === 'web') {
  105. if (msg.type === 'back') {
  106. toBack() //收到通知,刷新列表去
  107. }
  108. //保存成功
  109. if (msg.type === 'saveSuccess') {
  110. uni.hideLoading();
  111. previewClick()
  112. }
  113. }
  114. }
  115. const toBack = () => {
  116. webviewShow.value = false
  117. uni.navigateBack()
  118. }
  119. onUnload(()=>{
  120. // #ifdef H5
  121. window.removeEventListener('message', handleMessage);
  122. // #endif
  123. })
  124. //切换显示模式
  125. const editType = ref('form')
  126. const editTypeClick = () => {
  127. const type = editType.value === 'form' ? 'table' : 'form'
  128. // #ifdef H5
  129. window.frames["exceliframe"].postMessage({
  130. type: 'editTypeClick',
  131. source: 'app',
  132. data: type
  133. }, envUrl);
  134. // #endif
  135. // #ifdef APP-PLUS
  136. wv.evalJS(`editTypeClick('${type}')`)
  137. // #endif
  138. editType.value = type
  139. }
  140. //复制本表
  141. const toCopyClick = async () => {
  142. const { pkeyId, status } = pageNode.value
  143. if (!pkeyId) {
  144. errorToast('pkeyId为空');
  145. return
  146. } else if (status === '3') {
  147. errorToast('已上报的资料,不允许复制');
  148. return
  149. }
  150. uni.showLoading({title: '复制中...', mask: true});
  151. const { error, code, msg } = await wbsApi.copeBussTab({
  152. pkeyId: pkeyId,
  153. })
  154. uni.hideLoading();
  155. if (!error && code === 200) {
  156. successToast('复制成功');
  157. setTimeout(() => {
  158. toBack()
  159. }, 1500)
  160. } else {
  161. errorToast('复制失败:' + msg);
  162. }
  163. }
  164. //隐藏表单
  165. const toHideClick = async () => {
  166. const { pkeyId, status } = pageNode.value
  167. if (!pkeyId) {
  168. errorToast('pkeyId为空');
  169. return
  170. } else if (status === '3') {
  171. errorToast('已上报的资料,不允许隐藏示');
  172. return
  173. }
  174. uni.showLoading({title: '隐藏中...', mask: true});
  175. const { error, code, msg } = await wbsApi.showBussTab({
  176. pkeyId: pkeyId,
  177. status: 2,
  178. })
  179. uni.hideLoading();
  180. if (!error && code === 200) {
  181. successToast('隐藏成功');
  182. setTimeout(() => {
  183. toBack()
  184. }, 1500)
  185. } else {
  186. errorToast('隐藏失败:' + msg);
  187. }
  188. }
  189. //预览表单
  190. const previewClick = async () => {
  191. const { pkeyId, isBussShow, isTabPdf, pdfUrl } = pageNode.value
  192. if (!pkeyId) {
  193. errorToast('pkeyId为空');
  194. return
  195. } else if (isBussShow === 2 || isTabPdf === 1 || pdfUrl === '') {
  196. errorToast('当前状态无法预览');
  197. return
  198. }
  199. uni.showLoading({title: '获取PDF中...', mask: true});
  200. const { error, code, data, msg } = await wbsApi.getBussPdfInfo({
  201. pkeyId: pkeyId,
  202. })
  203. uni.hideLoading();
  204. if (!error && code === 200 && data) {
  205. toPdfPreview(data)
  206. } else {
  207. errorToast('获取失败:' + msg);
  208. }
  209. }
  210. //保存
  211. const formSaveClick = () => {
  212. uni.showLoading({title: '保存中...', mask: true})
  213. // #ifdef H5
  214. window.frames["exceliframe"].postMessage({
  215. type: 'formSave',
  216. source: 'app',
  217. data: {}
  218. }, envUrl);
  219. // #endif
  220. // #ifdef APP-PLUS
  221. wv.evalJS(`formSave()`)
  222. // #endif
  223. }
  224. //上传
  225. const toFileUp = () => {
  226. const { pkeyId, status } = pageNode.value
  227. if (!pkeyId) {
  228. errorToast('pkeyId为空');
  229. return
  230. } else if (status === '3') {
  231. errorToast('已上报的资料,不允许上传');
  232. return
  233. }
  234. uni.navigateTo({
  235. url: '/pages/data-fill/fileUp?node=' + encodeURIComponent(JSON.stringify(pageNode.value))
  236. });
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. page {
  241. height: 100%;
  242. background: #FAFBFE;
  243. }
  244. .hc-uni-app-table-form {
  245. .title-bar {
  246. position: absolute;
  247. top: 0;
  248. display: flex;
  249. width: 100%;
  250. padding: 15rpx;
  251. background: #E8EEF2;
  252. overflow-x: auto;
  253. white-space: nowrap;
  254. z-index: 9999;
  255. .title-bar-btn {
  256. flex: 1;
  257. color: #6FCC9F;
  258. background-color: #EBF9F4;
  259. height: 58rpx;
  260. font-size: 25rpx;
  261. padding: 0;
  262. margin: 0;
  263. line-height: initial;
  264. border-radius: 6rpx;
  265. display: flex;
  266. justify-content: center;
  267. align-items: center;
  268. &:after {
  269. display: none;
  270. }
  271. }
  272. .title-bar-btn + .title-bar-btn {
  273. margin-left: 16rpx;
  274. }
  275. }
  276. .action-bar {
  277. position: absolute;
  278. bottom: 0;
  279. width: 100%;
  280. display: flex;
  281. background: white;
  282. padding: 28rpx 28rpx calc(var(--window-bottom) + 34rpx);
  283. .action-bar-btn {
  284. flex: 1;
  285. }
  286. }
  287. }
  288. </style>