Components.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <div class="components-view">
  3. <el-affix :offset="100" style="width: 90px; float: right">
  4. <el-menu @select="onSelectBlock">
  5. <el-menu-item index="elFormRef">ElForm</el-menu-item>
  6. <el-menu-item index="epFormRef">EPForm</el-menu-item>
  7. <el-menu-item index="epFormRef1">InlineForm</el-menu-item>
  8. <el-menu-item index="epTableRef">EPTable</el-menu-item>
  9. <el-menu-item index="eChartsRef">E-Charts</el-menu-item>
  10. </el-menu>
  11. </el-affix>
  12. <div ref="elFormRef" class="example-block">
  13. <h3 class="example-title">ElForm</h3>
  14. <el-form ref="elFormRef" :model="formModel" :rules="forRules">
  15. <el-form-item prop="mainQuestion" label="Input">
  16. <el-input v-model="formModel.mainQuestion"></el-input>
  17. </el-form-item>
  18. <el-form-item prop="person" label="Input">
  19. <el-input v-model="formModel.person"></el-input>
  20. </el-form-item>
  21. <el-row>
  22. <el-col :span="12">
  23. <el-form-item prop="separate" label="Input">
  24. <el-input v-model="formModel.separate"></el-input>
  25. </el-form-item>
  26. <el-col :span="10">1231231</el-col>
  27. </el-col>
  28. <el-col :span="12">
  29. <el-form-item prop="day" label="Input">
  30. <el-input v-model="formModel.day"></el-input>
  31. </el-form-item>
  32. </el-col>
  33. </el-row>
  34. </el-form>
  35. </div>
  36. <div ref="epFormRef" class="example-block">
  37. <h3 class="example-title">Form</h3>
  38. <div class="flex items-center example-title">
  39. <el-button-group>
  40. <el-button v-for="(_, K) in formConfig" :key="K" type="primary" @click="changeFormConfig(K)">
  41. {{ K }}
  42. </el-button>
  43. </el-button-group>
  44. </div>
  45. <base-form
  46. ref="baseFormRef"
  47. v-bind="form"
  48. :items="items"
  49. :model="formModel"
  50. :rules="forRules"
  51. :label-width="'110px'"
  52. >
  53. </base-form>
  54. </div>
  55. <div ref="epFormRef1" class="example-block">
  56. <h3 class="example-title">InlineForm</h3>
  57. <base-form v-bind="form" :items="inlineItems" :model="formModel" size="small" :label-width="'88px'">
  58. <template #form-item-cao-zuo-col>
  59. <el-button type="primary">132</el-button>
  60. </template>
  61. </base-form>
  62. </div>
  63. <div ref="epTableRef" class="example-block">
  64. <h3 class="example-title">Table</h3>
  65. <base-table
  66. ref="baseTableRef"
  67. height="30vw"
  68. :data="data"
  69. :columns="columns"
  70. highlight-current-row
  71. @refresh="refresh"
  72. @current-change="onCurrentChange"
  73. @row-dblclick="onDbClick"
  74. >
  75. <template #column-header-a="s">
  76. <button>{{ parseFloat('0.0003') }}</button>
  77. <button>{{ s.row }}</button>
  78. </template>
  79. <template #column-7="{ row }">
  80. <button>{{ row }}</button>
  81. </template>
  82. <template #expand="scope">
  83. <div>{{ scope }}</div>
  84. </template>
  85. </base-table>
  86. </div>
  87. <div ref="eChartsRef" class="example-block">
  88. <h3 class="example-title">Echarts</h3>
  89. <vue-e-charts class="chart-box" :option="option"></vue-e-charts>
  90. </div>
  91. </div>
  92. </template>
  93. <script setup lang="tsx" name="ComponentsView">
  94. import {
  95. toRefs,
  96. reactive,
  97. ref,
  98. shallowReactive,
  99. shallowRef,
  100. watch,
  101. watchEffect,
  102. getCurrentInstance,
  103. computed,
  104. unref,
  105. } from 'vue'
  106. import VueECharts from 'vue-echarts'
  107. import useVueECharts from '@/hooks/useVueECharts'
  108. import {
  109. ElForm,
  110. ElFormItem,
  111. ElInput,
  112. ElRow,
  113. ElCol,
  114. ElAffix,
  115. ElMenu,
  116. ElMenuItem,
  117. ElButton,
  118. ElButtonGroup,
  119. } from 'element-plus'
  120. import BaseTable from '@/components/element/BaseTable.vue'
  121. import BaseForm from '@/components/element/BaseForm.vue'
  122. import useFetch from '@/hooks/useFetch'
  123. import useVW from '@/hooks/useVW'
  124. import type { EpTableProps, EpFormProps } from 'global-type'
  125. const onCurrentChange = (...args: any) => {
  126. console.log(...args)
  127. }
  128. const onDbClick = (...args: any) => {
  129. console.log(...args)
  130. }
  131. const instance = getCurrentInstance()
  132. function onSelectBlock(index: string) {
  133. const dom = instance?.refs[index]
  134. if (dom) {
  135. ;(dom as HTMLElement).scrollIntoView(true)
  136. }
  137. }
  138. /** Button start */
  139. /** Button end */
  140. const { fetch, loading, cancel, error } = useFetch('userLogin')
  141. /** form start */
  142. const formModel = reactive({
  143. subject: void 0,
  144. mainQuestion: void 0,
  145. separate: void 0,
  146. publish: true,
  147. person: 5,
  148. day: 8,
  149. type: [],
  150. checkBox: [],
  151. })
  152. const items: EpFormProps<typeof formModel>['items'] = [
  153. {
  154. rowKey: 'row-1',
  155. label: '科目',
  156. slotType: 'select',
  157. prop: 'subject',
  158. slot: {
  159. placeholder: '科目代码-科目名称',
  160. optionGroup: {
  161. 'group-1': {
  162. label: 'group-1',
  163. },
  164. 'group-2': {
  165. label: 'group-2',
  166. },
  167. },
  168. options: [
  169. {
  170. groupKey: 'group-1',
  171. value: 1,
  172. label: 'label-1',
  173. },
  174. {
  175. groupKey: 'group-2',
  176. value: 2,
  177. label: 'label-2',
  178. },
  179. {
  180. value: 3,
  181. label: 'label-3',
  182. },
  183. {
  184. value: 4,
  185. label: 'label-4',
  186. },
  187. ],
  188. },
  189. colProp: {
  190. span: 6,
  191. },
  192. },
  193. {
  194. rowKey: 'row-1',
  195. label: '大题',
  196. slotType: 'select',
  197. prop: 'mainQuestion',
  198. slot: {
  199. placeholder: '大题号-大题名称',
  200. options: [
  201. { label: '大题一-小题一', value: '1-1' },
  202. { label: '大题一-小题二', value: '1-2' },
  203. ],
  204. },
  205. colProp: {
  206. offset: 2,
  207. span: 6,
  208. },
  209. },
  210. {
  211. rowKey: 'row-2',
  212. label: '分隔符',
  213. slotType: 'input',
  214. prop: 'separate',
  215. slot: {},
  216. colProp: {
  217. span: 6,
  218. },
  219. },
  220. {
  221. rowKey: 'row-2',
  222. label: '导入同时发布任务',
  223. slotType: 'select',
  224. prop: 'publish',
  225. slot: {
  226. placeholder: ' 这是一个inputNumber框',
  227. options: [
  228. { label: '是', value: true },
  229. { label: '否', value: false },
  230. ],
  231. },
  232. colProp: {
  233. offset: 2,
  234. span: 6,
  235. },
  236. },
  237. {
  238. rowKey: 'row-3',
  239. label: '每包打包人数',
  240. slotType: 'input',
  241. prop: 'person',
  242. slot: {},
  243. colProp: {
  244. span: 6,
  245. },
  246. },
  247. {
  248. rowKey: 'row-3',
  249. label: '计划评卷天数',
  250. prop: 'day',
  251. slotType: 'inputNumber',
  252. slot: {
  253. step: 1,
  254. stepStrictly: true,
  255. },
  256. itemDescription: {
  257. requiredAsterisk: true,
  258. description: '系统将按各省考生平均分配到计划评卷天数中,确保各天的评卷进度一致',
  259. },
  260. colProp: {
  261. offset: 2,
  262. span: 6,
  263. },
  264. },
  265. {
  266. rowKey: 'row-4',
  267. label: '导入文件',
  268. // upload
  269. slotType: 'input',
  270. slot: {},
  271. },
  272. {
  273. slotType: 'input',
  274. label: '',
  275. slot: {
  276. placeholder: '这是一个进度条',
  277. },
  278. },
  279. {
  280. slotType: 'checkbox',
  281. label: 'CheckBox',
  282. prop: 'type',
  283. rowKey: 'row-5',
  284. slot: {
  285. type: 'checkbox',
  286. options: [
  287. { label: 'JavaScript', trueLabel: 'js' },
  288. { label: 'TypeScript', trueLabel: 'ts' },
  289. { label: 'NodeJs', trueLabel: 'nodeJs' },
  290. ],
  291. },
  292. },
  293. {
  294. slotType: 'checkbox',
  295. label: 'SingleCheckBox',
  296. prop: 'check',
  297. rowKey: 'row-5',
  298. slot: {
  299. type: 'checkbox',
  300. options: [{ label: 'JavaScript' }],
  301. },
  302. },
  303. ]
  304. const inlineItems: EpFormProps<typeof formModel>['items'] = [
  305. {
  306. slotType: 'input',
  307. label: '科目',
  308. rowKey: 'row-1',
  309. colProp: {
  310. span: 4,
  311. },
  312. },
  313. {
  314. slotType: 'input',
  315. label: '培训卷组',
  316. rowKey: 'row-1',
  317. colProp: {
  318. span: 4,
  319. },
  320. },
  321. {
  322. slotType: 'input',
  323. label: '培训卷组',
  324. rowKey: 'row-1',
  325. colProp: {
  326. span: 4,
  327. },
  328. },
  329. {
  330. slotType: 'input',
  331. label: '科目',
  332. rowKey: 'row-2',
  333. colProp: {
  334. span: 4,
  335. },
  336. },
  337. {
  338. slotType: 'input',
  339. label: '培训卷组',
  340. rowKey: 'row-2',
  341. colProp: {
  342. span: 4,
  343. },
  344. },
  345. {
  346. slotType: 'switch',
  347. label: '开关',
  348. rowKey: 'row-2',
  349. prop: 'publish',
  350. colProp: {
  351. span: 4,
  352. },
  353. },
  354. {
  355. slotType: 'checkbox',
  356. rowKey: 'row-2',
  357. labelWidth: '25px',
  358. prop: 'checkBox',
  359. slot: {
  360. type: 'button',
  361. options: [{ label: '差值显示', border: true }],
  362. },
  363. colProp: {
  364. span: 4,
  365. },
  366. },
  367. {
  368. slotType: 'inputNumber',
  369. rowKey: 'row-3',
  370. slot: {},
  371. colProp: {
  372. span: 4,
  373. },
  374. },
  375. {
  376. rowKey: 'row-1',
  377. slotName: 'cao-zuo-col',
  378. labelWidth: '10px',
  379. colProp: {
  380. span: 4,
  381. },
  382. },
  383. ]
  384. const forRules: EpFormProps<typeof formModel>['rules'] = {
  385. day: [{ required: true, message: '必填' }],
  386. }
  387. type formConfigType = 'normal' | 'with-group' | 'with-multiple-group'
  388. const usedFormConfigType = ref<formConfigType>('normal')
  389. const formConfig = reactive<Record<formConfigType, Omit<EpFormProps<typeof formModel>, 'model'>>>({
  390. normal: {
  391. size: 'large',
  392. },
  393. 'with-group': {
  394. rows: {},
  395. groups: [{ groupTitle: '选择大题', rowKeys: ['row-1'] }],
  396. },
  397. 'with-multiple-group': {
  398. groups: [
  399. { groupTitle: '选择大题', rowKeys: ['row-1'] },
  400. { groupTitle: '任务设置', rowKeys: ['row-2', 'row-3'] },
  401. { groupTitle: '选择文件', rowKeys: ['row-4'] },
  402. { groupTitle: 'CheckBox', rowKeys: ['row-5'] },
  403. ],
  404. },
  405. })
  406. const form = computed(() => {
  407. return formConfig[unref(usedFormConfigType)]
  408. })
  409. function changeFormConfig(type: formConfigType) {
  410. usedFormConfigType.value = type
  411. }
  412. /** form end */
  413. /** Table start */
  414. interface DataType {
  415. a: number
  416. b: number
  417. }
  418. const columns: EpTableProps<DataType>['columns'] = [
  419. {
  420. type: 'index',
  421. label: 'index',
  422. },
  423. {
  424. type: 'selection',
  425. label: 'selection',
  426. },
  427. {
  428. type: 'expand',
  429. label: 'expand',
  430. },
  431. {
  432. label: 'column-1',
  433. prop: 'a',
  434. },
  435. {
  436. label: 'column-2',
  437. prop: 'b',
  438. },
  439. {
  440. label: 'column-3',
  441. prop: 'a',
  442. },
  443. {
  444. label: 'column-4',
  445. prop: 'b',
  446. },
  447. {
  448. label: 'column-5',
  449. formatter(row) {
  450. return ''
  451. },
  452. },
  453. ]
  454. const data = ref<DataType[]>(getTableData())
  455. function getTableData() {
  456. return Array.from({ length: 30 }).map((_) => ({
  457. a: (Math.random() * 1000) | 0,
  458. b: (Math.random() * 1000) | 0,
  459. }))
  460. }
  461. const baseTableRef = shallowRef<InstanceType<typeof BaseTable>>()
  462. function refresh() {
  463. console.log('refresh')
  464. }
  465. /** Table end */
  466. /** echarts start */
  467. const { provideInitOption } = useVueECharts()
  468. provideInitOption({ renderer: 'svg' })
  469. const option = ref({
  470. title: {
  471. text: 'Traffic Sources',
  472. left: 'center',
  473. },
  474. tooltip: {
  475. trigger: 'item',
  476. formatter: '{a} <br/>{b} : {c} ({d}%)',
  477. },
  478. legend: {
  479. orient: 'vertical',
  480. left: 'left',
  481. data: ['Direct', 'Email', 'Ad Networks', 'Video Ads', 'Search Engines'],
  482. },
  483. series: [
  484. {
  485. name: 'Traffic Sources',
  486. type: 'pie',
  487. radius: '55%',
  488. center: ['50%', '60%'],
  489. data: [
  490. { value: 335, name: 'Direct' },
  491. { value: 310, name: 'Email' },
  492. { value: 234, name: 'Ad Networks' },
  493. { value: 135, name: 'Video Ads' },
  494. { value: 1548, name: 'Search Engines' },
  495. ],
  496. emphasis: {
  497. itemStyle: {
  498. shadowBlur: 10,
  499. shadowOffsetX: 0,
  500. shadowColor: 'rgba(0, 0, 0, 0.5)',
  501. },
  502. },
  503. },
  504. ],
  505. })
  506. /** echarts end */
  507. </script>
  508. <style scoped lang="scss">
  509. .components-view {
  510. .example-block {
  511. padding: $BaseGapSpace;
  512. .example-title {
  513. margin-bottom: $BaseGapSpace;
  514. }
  515. }
  516. .chart-box {
  517. height: 600px;
  518. }
  519. .float-nav {
  520. right: 20px;
  521. top: 80px;
  522. }
  523. }
  524. </style>