Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <script setup>
  2. import { getCurrentInstance, ref } from 'vue';
  3. const { proxy } = getCurrentInstance();
  4. /* 通用方法: 重置list数据 */
  5. const basicReset = () => {
  6. finished.value = false;
  7. loading.value = true;
  8. pageNum.value = 1;
  9. list.value = [];
  10. };
  11. /* 查询数据 */
  12. const pageNum = ref(1);
  13. const pageSize = ref(10);
  14. const total = ref(0);
  15. const resultData = ref([]);
  16. const fetchData = ref({
  17. lawName: '',
  18. lawType: 'safe'
  19. });
  20. const onSearch = () => {
  21. basicReset();
  22. onLoad();
  23. };
  24. const resetCondition = () => {
  25. basicReset();
  26. fetchData.value.lawName = '';
  27. onLoad();
  28. };
  29. const currentTab = ref('safe');
  30. const handleClick = (tab) => {
  31. currentTab.value = tab;
  32. fetchData.value.lawType = tab;
  33. onRefresh();
  34. };
  35. /* 查询请求 */
  36. const queryFetch = async () => {
  37. if (sessionStorage.getItem('lawName')) {
  38. fetchData.value.lawName = sessionStorage.getItem('lawName');
  39. sessionStorage.removeItem('lawName');
  40. }
  41. const url = '/sgsafe/InstitutionLaw/query';
  42. const param = {
  43. page: pageNum.value,
  44. rows: pageSize.value,
  45. params: JSON.stringify(fetchData.value)
  46. };
  47. try {
  48. const res = await proxy.$axios.post(url, param);
  49. if (res.data.code === 0) {
  50. total.value = res.data.data.total;
  51. resultData.value = res.data.data.records;
  52. } else {
  53. console.log('操作失败!' + res.data.msg);
  54. }
  55. } catch (error) {
  56. console.error('请求出错:', error);
  57. }
  58. };
  59. /* 列表加载与下拉刷新 */
  60. const list = ref([]);
  61. const refreshing = ref(false);
  62. const loading = ref(false);
  63. const finished = ref(false);
  64. const onRefresh = () => {
  65. basicReset();
  66. onLoad();
  67. };
  68. const onLoad = async () => {
  69. if (refreshing.value) {
  70. list.value = [];
  71. pageNum.value = 1;
  72. refreshing.value = false;
  73. }
  74. try {
  75. await queryFetch();
  76. if (pageSize.value * pageNum.value < total.value) {
  77. list.value = [...list.value, ...resultData.value];
  78. pageNum.value++;
  79. } else {
  80. list.value = [...list.value, ...resultData.value];
  81. finished.value = true;
  82. }
  83. } catch (error) {
  84. console.log(error);
  85. finished.value = true;
  86. } finally {
  87. loading.value = false;
  88. }
  89. };
  90. /* 在线预览实现 */
  91. import { Base64 } from 'js-base64';
  92. import { showFailToast } from 'vant';
  93. const linShiFid = ref({ fileId: '' });
  94. const handlePreview = (fileId) => {
  95. if (fetchData.value.lawName) {
  96. sessionStorage.setItem('lawName', fetchData.value.lawName);
  97. }
  98. linShiFid.value.fileId = fileId;
  99. getTableDataQueryFile();
  100. };
  101. const bucket = ref(import.meta.env.VITE_BUCKET);
  102. const getTableDataQueryFile = () => {
  103. const url = 'framework/Common/queryFileWithValues';
  104. let param = {
  105. fId: linShiFid.value.fileId
  106. };
  107. proxy.$axios.get(url, param).then(response => {
  108. if (response.data.code === 0) {
  109. const downloadPath = import.meta.env.VITE_BASE_API + '/framework/Common/downloadFileS3?bucket=' + bucket.value + '&id=';
  110. const fileListWithUrls = response.data.data.map(file => ({
  111. ...file,
  112. url: `${downloadPath}${file.id}`, // 添加完整的下载路径
  113. thumbUrl: `${downloadPath}${file.id}`, // 如果需要缩略图,可以使用相同的路径
  114. name: file.fileName, // 确保有文件名属性
  115. status: file.status, // 确保有状态属性
  116. id: file.id
  117. }));
  118. let originUrl = import.meta.env.VITE_PREVIEW_BASE_API + 'framework/Common/downloadFileS3?bucket=' + bucket.value + '&id=' + fileListWithUrls[0].id;
  119. let previewUrl = originUrl + '&fullfilename=' + Date.now() + fileListWithUrls[0].name;
  120. let url = import.meta.env.VITE_PREVIEW_API + 'onlinePreview?url=' + encodeURIComponent(Base64.encode(
  121. previewUrl)) + '&officePreviewType=pdf';
  122. window.open(url);
  123. } else {
  124. showFailToast('失败!' + response.data.msg);
  125. }
  126. });
  127. };
  128. </script>
  129. <template>
  130. <div class="page-container">
  131. <van-sticky>
  132. <van-nav-bar
  133. title="法律法规"
  134. @click-left="handleClick('safe')"
  135. @click-right="handleClick('env')"
  136. >
  137. <template #left>
  138. <div class="custom-tab" :class="{ 'custom-tab--active': currentTab === 'safe' }">安全</div>
  139. </template>
  140. <template #right>
  141. <div class="custom-tab" :class="{ 'custom-tab--active': currentTab === 'env' }">环保</div>
  142. </template>
  143. </van-nav-bar>
  144. <van-search
  145. v-model="fetchData.lawName"
  146. @search="onSearch"
  147. @clear="resetCondition"
  148. placeholder="请输入法律法规名称"
  149. />
  150. </van-sticky>
  151. <div class="scroll-container">
  152. <van-pull-refresh
  153. v-model="refreshing"
  154. success-text="刷新成功"
  155. @refresh="onRefresh"
  156. >
  157. <van-list
  158. class="listDiv"
  159. v-model:loading="loading"
  160. :finished="finished"
  161. finished-text="没有更多了"
  162. @load="onLoad"
  163. >
  164. <div v-for="item in list" :key="item.id" class="card">
  165. <van-cell @click="handlePreview(item.lawFile)" :border="false" is-link>
  166. <template #title>
  167. <van-icon name="idcard" />
  168. <span class="bold-title" style="margin-left: 4px;">{{ item.lawName }}</span>
  169. </template>
  170. </van-cell>
  171. </div>
  172. </van-list>
  173. </van-pull-refresh>
  174. </div>
  175. </div>
  176. </template>
  177. <style scoped>
  178. .page-container {
  179. height: 100vh;
  180. display: flex;
  181. flex-direction: column;
  182. }
  183. .scroll-container {
  184. flex: 1;
  185. overflow: auto;
  186. -webkit-overflow-scrolling: touch;
  187. }
  188. .scroll-container::-webkit-scrollbar {
  189. display: none;
  190. }
  191. .card {
  192. margin: 10px;
  193. border-radius: 8px;
  194. overflow: hidden;
  195. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  196. background-color: #fff;
  197. }
  198. .bold-title {
  199. font-weight: bold;
  200. color: #333;
  201. }
  202. .custom-tab {
  203. padding: 8px 0;
  204. font-size: 14px;
  205. color: var(--van-gray-7, #646566);
  206. position: relative;
  207. cursor: pointer;
  208. }
  209. .custom-tab--active {
  210. color: var(--van-primary-color, #1989fa);
  211. }
  212. .custom-tab--active::after {
  213. content: '';
  214. position: absolute;
  215. bottom: 0;
  216. left: 0;
  217. width: 100%;
  218. height: 3px;
  219. background-color: var(--van-primary-color, #1989fa);
  220. border-radius: 2px;
  221. }
  222. </style>