index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div id="index">
  3. <van-row>
  4. <van-col span="24" class="main animate__animated animate__backInRight">
  5. <van-col span="24" class="one">
  6. <van-col span="20" class="one_1">
  7. <van-field v-model="searchForm.name" placeholder="请输入文件标题" @blur="toInput" />
  8. </van-col>
  9. <van-col span="4" class="one_2">
  10. <van-button size="small" @click="toAdd" :disabled="!is_show">新增</van-button>
  11. </van-col>
  12. </van-col>
  13. <van-col span="24" class="two">
  14. <van-col span="24" class="list" v-for="i in list" :key="i._id">
  15. <van-col span="24" class="name">{{ i.title }}</van-col>
  16. <van-col span="24" class="other">
  17. <van-col span="24" class="other_1">
  18. <span>文件:</span>
  19. <span v-for="r in i.file" :key="r.url" @click="toDownload(r)">{{ r.name }};</span>
  20. </van-col>
  21. </van-col>
  22. <van-col span="24" class="btn">
  23. <van-button type="primary" size="small" @click="toEdit(i)">信息编辑</van-button>
  24. <van-button type="danger" size="small" @click="toDel(i)">信息删除</van-button>
  25. </van-col>
  26. </van-col>
  27. </van-col>
  28. <van-col span="24" class="thr">
  29. <cPage :total="total" :limit="limit" @search="search"> </cPage>
  30. </van-col>
  31. </van-col>
  32. </van-row>
  33. </div>
  34. </template>
  35. <script setup lang="ts">
  36. // 基础
  37. import _ from 'lodash';
  38. import type { Ref } from 'vue';
  39. import { onMounted, ref, getCurrentInstance } from 'vue';
  40. import { useRouter } from 'vue-router';
  41. import { showConfirmDialog, showToast } from 'vant';
  42. // 接口
  43. import { PolicyfileStore } from '@common/src/stores/basic/policyfile';
  44. import type { IQueryResult } from '@/util/types.util';
  45. import store from '@/stores/counter';
  46. const polAxios = PolicyfileStore();
  47. // 基本设置
  48. const { proxy } = getCurrentInstance() as any;
  49. // 路由
  50. const router = useRouter();
  51. // 是否显示
  52. const is_show: Ref<any> = ref(false);
  53. const list: Ref<any> = ref([]);
  54. const total: Ref<any> = ref(0);
  55. const skip = 0;
  56. const limit: number = proxy.$limit;
  57. // 查询
  58. const searchForm: Ref<any> = ref({});
  59. // 请求
  60. onMounted(async () => {
  61. await searchUser();
  62. await search({ skip, limit });
  63. });
  64. const searchUser = () => {
  65. let user = store.state.user as any;
  66. if (user.role_type == '0' || user.role_type == '1') {
  67. is_show.value = true;
  68. }
  69. };
  70. const search = async (e: { skip: number; limit: number }) => {
  71. const { skip, limit } = e;
  72. const condition = _.cloneDeep(searchForm.value);
  73. let info = { limit: limit, skip: skip, ...condition };
  74. let res: IQueryResult = await polAxios.query(info);
  75. if (res.errcode == 0) {
  76. list.value = res.data as [];
  77. total.value = res.total;
  78. }
  79. };
  80. // 名称查询
  81. const toInput = () => {
  82. search({ skip, limit });
  83. };
  84. // 新增
  85. const toAdd = () => {
  86. router.push({ path: '/policyfile/detail' });
  87. };
  88. // 信息修改
  89. const toEdit = (e) => {
  90. router.push({ path: '/policyfile/detail', query: { id: e._id } });
  91. };
  92. // 信息删除
  93. const toDel = async (e) => {
  94. showConfirmDialog({
  95. title: '提示',
  96. message: '您确认删除该数据?',
  97. width: '100%'
  98. })
  99. .then(async () => {
  100. let res: IQueryResult = await polAxios.del(e._id);
  101. if (res.errcode == '0') {
  102. showToast({ message: '信息删除成功', type: 'success', duration: 500 });
  103. search({ skip, limit });
  104. } else {
  105. showToast({ message: `${res.errmsg}`, type: 'fail', duration: 500 });
  106. }
  107. })
  108. .catch(() => {});
  109. };
  110. // 查看文件
  111. const toDownload = (e) => {
  112. window.location.href = `${e.url}`;
  113. };
  114. </script>
  115. <style scoped lang="scss">
  116. .main {
  117. height: 100vh;
  118. overflow: hidden;
  119. .one {
  120. display: flex;
  121. padding: 10px;
  122. height: 9vh;
  123. .one_1 {
  124. .van-cell {
  125. padding: 5px;
  126. border: 1px solid #f1f1f1;
  127. }
  128. }
  129. .one_2 {
  130. .van-button {
  131. width: 100%;
  132. height: 5.4vh;
  133. }
  134. }
  135. }
  136. .two {
  137. height: 85vh;
  138. overflow-y: auto;
  139. padding: 0 10px;
  140. .list {
  141. border: 1px solid #f1f1f1;
  142. margin: 0 0 10px 0;
  143. padding: 10px;
  144. border-radius: 5px;
  145. .name {
  146. font-size: 16px;
  147. font-weight: bold;
  148. margin: 0 0 5px 0;
  149. }
  150. .other {
  151. margin: 0 0 5px 0;
  152. .other_1 {
  153. font-size: 14px;
  154. }
  155. }
  156. .btn {
  157. text-align: center;
  158. .van-button {
  159. margin: 0 10px;
  160. }
  161. }
  162. }
  163. }
  164. .thr {
  165. height: 6vh;
  166. overflow: hidden;
  167. }
  168. }
  169. </style>