el-button.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <script setup lang="ts">
  2. import { ref, watch } from "vue";
  3. import { useDark } from "@pureadmin/utils";
  4. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  5. defineOptions({
  6. name: "PureButton"
  7. });
  8. const { isDark } = useDark();
  9. const size = ref("default");
  10. const dynamicSize = ref();
  11. const baseRadio = ref("default");
  12. const buttonList = [
  13. {
  14. type: "",
  15. text: "Default",
  16. icon: "ep:search"
  17. },
  18. {
  19. type: "primary",
  20. text: "Primary",
  21. icon: "ep:edit"
  22. },
  23. {
  24. type: "success",
  25. text: "Success",
  26. icon: "ep:check"
  27. },
  28. {
  29. type: "info",
  30. text: "Info",
  31. icon: "ep:message"
  32. },
  33. {
  34. type: "warning",
  35. text: "Warning",
  36. icon: "ep:star"
  37. },
  38. {
  39. type: "danger",
  40. text: "Danger",
  41. icon: "ep:delete"
  42. }
  43. ];
  44. watch(size, val =>
  45. val === "disabled"
  46. ? (dynamicSize.value = "default")
  47. : (dynamicSize.value = size.value)
  48. );
  49. </script>
  50. <template>
  51. <el-card shadow="never">
  52. <template #header>
  53. <div class="card-header">
  54. <el-space wrap :size="40">
  55. <el-link
  56. v-tippy="{
  57. content: '点击查看详细文档'
  58. }"
  59. href="https://element-plus.org/zh-CN/component/button.html"
  60. target="_blank"
  61. style="font-size: 16px; font-weight: 800"
  62. >
  63. Button 按钮
  64. </el-link>
  65. <el-radio-group v-model="size">
  66. <el-radio value="large">大尺寸</el-radio>
  67. <el-radio value="default">默认尺寸</el-radio>
  68. <el-radio value="small">小尺寸</el-radio>
  69. <el-radio value="disabled">禁用</el-radio>
  70. </el-radio-group>
  71. </el-space>
  72. </div>
  73. <el-link
  74. class="mt-2"
  75. href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/components/el-button.vue"
  76. target="_blank"
  77. >
  78. 代码位置 src/views/components/el-button.vue
  79. </el-link>
  80. </template>
  81. <div class="mb-2">基础按钮</div>
  82. <el-radio-group v-model="baseRadio" class="mb-3">
  83. <el-radio label="default" value="default" />
  84. <el-radio label="plain" value="plain" />
  85. <el-radio label="round" value="round" />
  86. <el-radio label="circle" value="circle" />
  87. <el-radio label="link" value="link" />
  88. <el-radio label="text" value="text" />
  89. <el-radio label="text-bg" value="text-bg" />
  90. </el-radio-group>
  91. <br />
  92. <el-space wrap>
  93. <el-button
  94. v-for="(button, index) in buttonList"
  95. :key="index"
  96. :type="button.type as any"
  97. :size="dynamicSize"
  98. :disabled="size === 'disabled'"
  99. :plain="baseRadio === 'plain'"
  100. :round="baseRadio === 'round'"
  101. :circle="baseRadio === 'circle'"
  102. :link="baseRadio === 'link'"
  103. :text="baseRadio === 'text' || baseRadio === 'text-bg'"
  104. :bg="baseRadio === 'text-bg'"
  105. :icon="useRenderIcon(button.icon)"
  106. >
  107. <template v-if="baseRadio !== 'circle'" #default>
  108. <p>{{ button.text }}</p>
  109. </template>
  110. </el-button>
  111. </el-space>
  112. <el-divider />
  113. <div class="mb-4">加载状态按钮</div>
  114. <el-button
  115. text
  116. bg
  117. type="primary"
  118. :size="dynamicSize"
  119. :disabled="size === 'disabled'"
  120. :loading="size !== 'disabled'"
  121. >
  122. {{ size === "disabled" ? "停止加载" : "加载中" }}
  123. </el-button>
  124. <el-button
  125. type="primary"
  126. plain
  127. :size="dynamicSize"
  128. :disabled="size === 'disabled'"
  129. :loading-icon="useRenderIcon('ep:eleme')"
  130. :loading="size !== 'disabled'"
  131. >
  132. {{ size === "disabled" ? "停止加载" : "加载中" }}
  133. </el-button>
  134. <el-button
  135. type="primary"
  136. :size="dynamicSize"
  137. :disabled="size === 'disabled'"
  138. :loading="size !== 'disabled'"
  139. >
  140. <template #loading>
  141. <div class="custom-loading">
  142. <svg class="circular" viewBox="-10, -10, 50, 50">
  143. <path
  144. class="path"
  145. d="
  146. M 30 15
  147. L 28 17
  148. M 25.61 25.61
  149. A 15 15, 0, 0, 1, 15 30
  150. A 15 15, 0, 1, 1, 27.99 7.5
  151. L 15 15
  152. "
  153. style="fill: rgb(0 0 0 / 0%); stroke-width: 4px"
  154. />
  155. </svg>
  156. </div>
  157. </template>
  158. {{ size === "disabled" ? "停止加载" : "加载中" }}
  159. </el-button>
  160. <el-divider />
  161. <div class="mb-4">自定义元素标签。例如:按钮、div、链接</div>
  162. <el-button :size="dynamicSize" :disabled="size === 'disabled'">
  163. button 标签
  164. </el-button>
  165. <el-button
  166. tag="div"
  167. role="button"
  168. tabindex="0"
  169. :size="dynamicSize"
  170. :disabled="size === 'disabled'"
  171. >
  172. div 标签
  173. </el-button>
  174. <el-button
  175. type="primary"
  176. tag="a"
  177. :href="
  178. size === 'disabled'
  179. ? 'javascript:void(0);'
  180. : 'https://element-plus.org/zh-CN/component/button.html#tag'
  181. "
  182. :target="size === 'disabled' ? '_self' : '_blank'"
  183. rel="noopener noreferrer"
  184. :size="dynamicSize"
  185. :disabled="size === 'disabled'"
  186. >
  187. a 链接
  188. </el-button>
  189. <el-divider />
  190. <div class="mb-4">自定义颜色</div>
  191. <el-space wrap>
  192. <el-button
  193. color="#626aef"
  194. :size="dynamicSize"
  195. :disabled="size === 'disabled'"
  196. :dark="isDark"
  197. >
  198. Default
  199. </el-button>
  200. <el-button
  201. color="#626aef"
  202. :size="dynamicSize"
  203. :disabled="size === 'disabled'"
  204. :dark="isDark"
  205. plain
  206. >
  207. Plain
  208. </el-button>
  209. </el-space>
  210. </el-card>
  211. </template>
  212. <style lang="scss" scoped>
  213. :deep(.el-divider--horizontal) {
  214. margin: 17px 0;
  215. }
  216. .el-button .custom-loading .circular {
  217. width: 18px;
  218. height: 18px;
  219. margin-right: 6px;
  220. animation: loading-rotate 2s linear infinite;
  221. }
  222. .el-button .custom-loading .circular .path {
  223. stroke: var(--el-button-text-color);
  224. stroke-width: 2;
  225. stroke-linecap: round;
  226. stroke-dasharray: 90, 150;
  227. stroke-dashoffset: 0;
  228. animation: loading-dash 1.5s ease-in-out infinite;
  229. }
  230. </style>