hooksDemo.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div>{{ form }}</div>
  3. <div>{{ search }}</div>
  4. <el-button @click="test">测试公共弹窗</el-button>
  5. <el-button
  6. v-debounce:click="
  7. () => {
  8. testDebunce('这是传递的参数');
  9. }
  10. "
  11. >测试防抖截流</el-button
  12. >
  13. <div class="mainContentBox">
  14. <avue-crud
  15. ref="crudRef"
  16. v-model:search="search"
  17. v-model="form"
  18. :data="data"
  19. :option="option"
  20. v-model:page="page"
  21. @row-save="createRow"
  22. @row-update="updateRow"
  23. @row-del="deleteRow"
  24. @search-change="searchChange"
  25. @search-reset="resetChange"
  26. @size-change="dataList"
  27. @current-change="dataList"
  28. @selection-change="selectionChange"
  29. >
  30. <template #menu-left="{ size }">
  31. <el-button
  32. :disabled="toDeleteIds.length < 1"
  33. type="danger"
  34. icon="el-icon-delete"
  35. :size="size"
  36. @click="multipleDelete"
  37. >删除</el-button
  38. >
  39. </template>
  40. <template #menu-right="{}">
  41. <el-dropdown split-button
  42. >导入
  43. <template #dropdown>
  44. <el-dropdown-menu>
  45. <el-dropdown-item
  46. @click="downloadTemplate('/api/v1/plan/order/template')"
  47. >
  48. <i-ep-download />下载模板
  49. </el-dropdown-item>
  50. <el-dropdown-item @click="importExcelData">
  51. <i-ep-top />导入数据
  52. </el-dropdown-item>
  53. </el-dropdown-menu>
  54. </template>
  55. </el-dropdown>
  56. <el-button
  57. class="ml-3"
  58. @click="exportData('/api/v1/plan/order/export')"
  59. >
  60. <template #icon> <i-ep-download /> </template>导出
  61. </el-button>
  62. </template>
  63. </avue-crud>
  64. <CommonTable
  65. ref="ctableRef"
  66. tableTitle="测试title"
  67. tableType="MARTERIAL"
  68. @selected-sure="onSelectedFinish"
  69. />
  70. <ExcelUpload ref="uploadRef" @finished="uploadFinished" />
  71. </div>
  72. </template>
  73. <script setup>
  74. import { ref, getCurrentInstance } from "vue";
  75. import { useCrud } from "@/hooks/userCrud";
  76. import dictDataUtil from "@/common/configs/dictDataUtil";
  77. import ButtonPermKeys from "@/common/configs/buttonPermission";
  78. import { useCommonStoreHook, useDictionaryStoreHook } from "@/store";
  79. // 数据字典相关
  80. const { dicts } = useDictionaryStoreHook();
  81. // 公共弹窗相关
  82. const ctableRef = ref(null);
  83. const test = () => {
  84. if (ctableRef.value) {
  85. ctableRef.value.startSelect();
  86. }
  87. };
  88. const onSelectedFinish = (selectedValue) => {
  89. console.log("onSelectedFinish", selectedValue);
  90. };
  91. const testDebunce = (args) => {
  92. console.log("执行了事件", args);
  93. };
  94. // 传入一个url,后面不带/
  95. const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  96. useCrud({
  97. src: "/api/v1/plan/order",
  98. });
  99. const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  100. Methords; //增删改查
  101. const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
  102. const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
  103. // checkBtnPerm(ButtonPermKeys.PLAN.BTNS.order_add) :permission="permission"
  104. // const permission = reactive({
  105. // delBtn: checkPerm(buttonPermission.PLAN.BTNS.order_del),
  106. // addBtn: checkPerm(buttonPermission.PLAN.BTNS.order_add),
  107. // editBtn: checkPerm(buttonPermission.PLAN.BTNS.order_edit),
  108. // menu: true,
  109. // });
  110. const crudRef = ref(null); //crudRef.value 获取avue-crud对象
  111. onMounted(() => {
  112. // console.log("crudRef", crudRef)
  113. dataList();
  114. });
  115. /**
  116. * 上传excel相关
  117. */
  118. const uploadRef = ref(null);
  119. const uploadFinished = () => {
  120. // 上传完成后的刷新操作
  121. page.currentPage = 1;
  122. dataList();
  123. };
  124. const importExcelData = () => {
  125. if (uploadRef.value) {
  126. uploadRef.value.show("/api/v1/plan/order/import");
  127. }
  128. };
  129. // 设置表格列或者其他自定义的option
  130. option.value = Object.assign(option.value, {
  131. selection: true,
  132. column: [
  133. {
  134. label: "产品",
  135. prop: "materialCode",
  136. search: true,
  137. },
  138. {
  139. label: "年龄",
  140. prop: "materialModel",
  141. search: true,
  142. },
  143. {
  144. label: "性别",
  145. prop: "orderCode",
  146. search: true,
  147. },
  148. {
  149. label: "网络字典",
  150. prop: "province",
  151. type: "select",
  152. dicUrl: dictDataUtil.request_url + dictDataUtil.TYPE_CODE.routing_type,
  153. props: {
  154. label: "dictLabel",
  155. value: "dictValue",
  156. },
  157. },
  158. {
  159. label: "全局字典",
  160. prop: "province",
  161. type: "select",
  162. dicData: dicts.station_operate_type,
  163. props: {
  164. label: "dictLabel",
  165. value: "dictValue",
  166. },
  167. },
  168. {
  169. label: "身高",
  170. prop: "projectCode",
  171. search: true,
  172. },
  173. {
  174. label: "是否xxxx",
  175. prop: "xxxxx",
  176. search: false,
  177. filterable: true,
  178. type: "radio", //类型为单选框
  179. dicData: [
  180. {
  181. label: "否",
  182. value: 0,
  183. },
  184. {
  185. label: "是",
  186. value: 1,
  187. },
  188. ],
  189. value: 0,
  190. },
  191. ],
  192. });
  193. </script>