adv-search.mdc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. ---
  2. description: cl-adv-search 组件示例
  3. globs: *.tsx, *.ts, *.vue
  4. ---
  5. ## 起步 示例
  6. ```vue
  7. <template>
  8. <div class="scope">
  9. <div class="h">
  10. <el-tag size="small" effect="dark" disable-transitions>base</el-tag>
  11. <span>起步</span>
  12. </div>
  13. <div class="c">
  14. <el-button @click="open">预览</el-button>
  15. <demo-code :files="['adv-search/base.vue']" />
  16. <!-- 自定义表格组件 -->
  17. <cl-dialog v-model="visible" title="起步" width="80%">
  18. <cl-crud ref="Crud">
  19. <cl-row>
  20. <!--【很重要】高级搜索组件按钮 -->
  21. <cl-adv-btn />
  22. </cl-row>
  23. <cl-row>
  24. <cl-table ref="Table" />
  25. </cl-row>
  26. <cl-row>
  27. <cl-flex1 />
  28. <cl-pagination />
  29. </cl-row>
  30. <!--【很重要】高级搜索组件 -->
  31. <cl-adv-search ref="AdvSearch" />
  32. </cl-crud>
  33. </cl-dialog>
  34. </div>
  35. <div class="f">
  36. <span class="date">2024-01-01</span>
  37. </div>
  38. </div>
  39. </template>
  40. <script setup lang="ts">
  41. import { useCrud, useAdvSearch, useTable } from '@cool-vue/crud';
  42. import { ref } from 'vue';
  43. import { useDict } from '/$/dict';
  44. const { dict } = useDict();
  45. // cl-crud 配置
  46. const Crud = useCrud(
  47. {
  48. service: 'test'
  49. },
  50. app => {
  51. app.refresh();
  52. }
  53. );
  54. // cl-table 配置
  55. const Table = useTable({
  56. autoHeight: false,
  57. contextMenu: ['refresh'],
  58. columns: [
  59. {
  60. label: '姓名',
  61. prop: 'name',
  62. minWidth: 140
  63. },
  64. {
  65. label: '手机号',
  66. prop: 'phone',
  67. minWidth: 140
  68. },
  69. {
  70. label: '工作',
  71. prop: 'occupation',
  72. dict: dict.get('occupation'),
  73. minWidth: 140
  74. },
  75. {
  76. label: '创建时间',
  77. prop: 'createTime',
  78. minWidth: 170,
  79. sortable: 'desc'
  80. }
  81. ]
  82. });
  83. // cl-adv-search 配置
  84. //【很重要】该组件基于 cl-form 故很多示例都可复用
  85. const AdvSearch = useAdvSearch({
  86. // 配置如 cl-form 一样
  87. items: [
  88. {
  89. label: '姓名',
  90. prop: 'name',
  91. component: {
  92. name: 'el-input',
  93. props: {
  94. clearable: true
  95. }
  96. }
  97. },
  98. {
  99. label: '手机号',
  100. prop: 'phone',
  101. component: {
  102. name: 'el-input',
  103. props: {
  104. clearable: true
  105. }
  106. }
  107. },
  108. {
  109. label: '工作',
  110. prop: 'occupation',
  111. component: {
  112. name: 'cl-select',
  113. props: {
  114. tree: true,
  115. checkStrictly: true,
  116. options: dict.get('occupation')
  117. }
  118. }
  119. }
  120. ]
  121. });
  122. function refresh(params?: any) {
  123. Crud.value?.refresh(params);
  124. }
  125. const visible = ref(false);
  126. function open() {
  127. visible.value = true;
  128. }
  129. </script>
  130. ```
  131. ## 自定义 示例
  132. ```vue
  133. <template>
  134. <div class="scope">
  135. <div class="h">
  136. <el-tag size="small" effect="dark" disable-transitions>custom</el-tag>
  137. <span>自定义</span>
  138. </div>
  139. <div class="c">
  140. <el-button @click="open">预览</el-button>
  141. <demo-code :files="['adv-search/custom.vue']" />
  142. <!-- 自定义表格组件 -->
  143. <cl-dialog v-model="visible" title="自定义" width="80%">
  144. <cl-crud ref="Crud">
  145. <cl-row>
  146. <!--【很重要】高级搜索组件按钮 -->
  147. <cl-adv-btn>更多搜索</cl-adv-btn>
  148. </cl-row>
  149. <cl-row>
  150. <cl-table ref="Table" />
  151. </cl-row>
  152. <cl-row>
  153. <cl-flex1 />
  154. <cl-pagination />
  155. </cl-row>
  156. <!--【很重要】高级搜索组件 -->
  157. <cl-adv-search ref="AdvSearch">
  158. <!-- 自定义按钮 -->
  159. <template #slot-btn>
  160. <el-button @click="toSearch">自定义</el-button>
  161. </template>
  162. </cl-adv-search>
  163. </cl-crud>
  164. </cl-dialog>
  165. </div>
  166. <div class="f">
  167. <span class="date">2024-01-01</span>
  168. </div>
  169. </div>
  170. </template>
  171. <script setup lang="ts">
  172. import { useCrud, useAdvSearch, useTable } from '@cool-vue/crud';
  173. import { ref } from 'vue';
  174. import { useDict } from '/$/dict';
  175. const { dict } = useDict();
  176. // cl-crud 配置
  177. const Crud = useCrud(
  178. {
  179. service: 'test'
  180. },
  181. app => {
  182. app.refresh();
  183. }
  184. );
  185. // cl-table 配置
  186. const Table = useTable({
  187. autoHeight: false,
  188. contextMenu: ['refresh'],
  189. columns: [
  190. {
  191. label: '姓名',
  192. prop: 'name',
  193. minWidth: 140
  194. },
  195. {
  196. label: '手机号',
  197. prop: 'phone',
  198. minWidth: 140
  199. },
  200. {
  201. label: '工作',
  202. prop: 'occupation',
  203. dict: dict.get('occupation'),
  204. minWidth: 140
  205. },
  206. {
  207. label: '创建时间',
  208. prop: 'createTime',
  209. minWidth: 170,
  210. sortable: 'desc'
  211. }
  212. ]
  213. });
  214. // cl-adv-search 配置
  215. //【很重要】该组件基于 cl-form 故很多示例都可复用
  216. const AdvSearch = useAdvSearch({
  217. // 配置如 cl-form 一样
  218. items: [
  219. {
  220. label: '姓名',
  221. prop: 'name',
  222. component: {
  223. name: 'el-input',
  224. props: {
  225. clearable: true
  226. }
  227. }
  228. },
  229. {
  230. label: '手机号',
  231. prop: 'phone',
  232. component: {
  233. name: 'el-input',
  234. props: {
  235. clearable: true
  236. }
  237. }
  238. },
  239. {
  240. label: '工作',
  241. prop: 'occupation',
  242. component: {
  243. name: 'cl-select',
  244. props: {
  245. tree: true,
  246. checkStrictly: true,
  247. options: dict.get('occupation')
  248. }
  249. }
  250. }
  251. ],
  252. title: '更多搜索',
  253. size: '50%',
  254. op: ['close', 'search', 'slot-btn']
  255. });
  256. function refresh(params?: any) {
  257. Crud.value?.refresh(params);
  258. }
  259. // 自定义搜索
  260. function toSearch() {
  261. refresh({ page: 1 });
  262. }
  263. const visible = ref(false);
  264. function open() {
  265. visible.value = true;
  266. }
  267. </script>
  268. ```