editTable.vue 8.5 KB

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