Products-dev.3852cc44.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { u as useAuthStore } from "./index-dev.bb5c7162.js";
  2. import { a as axios } from "./utils-dev.be08a1a2.js";
  3. import { a as ElMessage } from "./element-dev.26a170ea.js";
  4. import { v as defineComponent, r as ref, l as onMounted, B as createElementBlock, E as createBaseVNode, C as createVNode, D as withCtx, ak as resolveComponent, aq as resolveDirective, y as openBlock, M as createTextVNode, J as withDirectives, O as toDisplayString, L as createCommentVNode, u as unref } from "./vue-dev.7a51ac2d.js";
  5. import { _ as _export_sfc } from "./_plugin-vue_export-helper-dev.cc2b3d55.js";
  6. const _hoisted_1 = { class: "products-page" };
  7. const _hoisted_2 = { class: "card-header" };
  8. const _hoisted_3 = {
  9. key: 0,
  10. class: "empty-state"
  11. };
  12. const _hoisted_4 = { class: "user-info" };
  13. const _sfc_main = /* @__PURE__ */ defineComponent({
  14. __name: "Products",
  15. setup(__props) {
  16. const authStore = useAuthStore();
  17. const loading = ref(false);
  18. const products = ref([]);
  19. const loadProducts = async () => {
  20. loading.value = true;
  21. try {
  22. const response = await axios.get("/api/products");
  23. if (response.data.code === 0) {
  24. products.value = response.data.data.products;
  25. ElMessage.success("产品列表加载成功");
  26. } else {
  27. ElMessage.error(response.data.message || "加载失败");
  28. }
  29. } catch (error) {
  30. console.error("加载产品列表失败:", error);
  31. ElMessage.error("加载产品列表失败");
  32. } finally {
  33. loading.value = false;
  34. }
  35. };
  36. const viewProduct = (product) => {
  37. ElMessage.info(`查看产品: ${product.name}`);
  38. };
  39. const editProduct = (product) => {
  40. ElMessage.info(`编辑产品: ${product.name}`);
  41. };
  42. onMounted(() => {
  43. loadProducts();
  44. });
  45. return (_ctx, _cache) => {
  46. const _component_Refresh = resolveComponent("Refresh");
  47. const _component_el_icon = resolveComponent("el-icon");
  48. const _component_el_button = resolveComponent("el-button");
  49. const _component_el_table_column = resolveComponent("el-table-column");
  50. const _component_el_table = resolveComponent("el-table");
  51. const _component_el_empty = resolveComponent("el-empty");
  52. const _component_el_card = resolveComponent("el-card");
  53. const _component_el_tag = resolveComponent("el-tag");
  54. const _directive_loading = resolveDirective("loading");
  55. return openBlock(), createElementBlock("div", _hoisted_1, [
  56. _cache[8] || (_cache[8] = createBaseVNode("div", { class: "page-header" }, [
  57. createBaseVNode("h2", null, "产品管理"),
  58. createBaseVNode("p", null, "这里展示了通过SSO认证保护的业务接口数据")
  59. ], -1)),
  60. createVNode(_component_el_card, null, {
  61. header: withCtx(() => [
  62. createBaseVNode("div", _hoisted_2, [
  63. _cache[1] || (_cache[1] = createBaseVNode("span", null, "产品列表", -1)),
  64. createVNode(_component_el_button, {
  65. type: "primary",
  66. onClick: loadProducts
  67. }, {
  68. default: withCtx(() => [
  69. createVNode(_component_el_icon, null, {
  70. default: withCtx(() => [
  71. createVNode(_component_Refresh)
  72. ]),
  73. _: 1
  74. }),
  75. _cache[0] || (_cache[0] = createTextVNode(" 刷新 ", -1))
  76. ]),
  77. _: 1
  78. })
  79. ])
  80. ]),
  81. default: withCtx(() => [
  82. withDirectives((openBlock(), createElementBlock("div", null, [
  83. createVNode(_component_el_table, {
  84. data: products.value,
  85. style: { "width": "100%" }
  86. }, {
  87. default: withCtx(() => [
  88. createVNode(_component_el_table_column, {
  89. prop: "id",
  90. label: "ID",
  91. width: "80"
  92. }),
  93. createVNode(_component_el_table_column, {
  94. prop: "name",
  95. label: "产品名称"
  96. }),
  97. createVNode(_component_el_table_column, {
  98. prop: "price",
  99. label: "价格"
  100. }, {
  101. default: withCtx(({ row }) => [
  102. createTextVNode(" ¥" + toDisplayString(row.price.toFixed(2)), 1)
  103. ]),
  104. _: 1
  105. }),
  106. createVNode(_component_el_table_column, {
  107. prop: "description",
  108. label: "描述"
  109. }),
  110. createVNode(_component_el_table_column, {
  111. label: "操作",
  112. width: "200"
  113. }, {
  114. default: withCtx(({ row }) => [
  115. createVNode(_component_el_button, {
  116. size: "small",
  117. onClick: ($event) => viewProduct(row)
  118. }, {
  119. default: withCtx(() => [..._cache[2] || (_cache[2] = [
  120. createTextVNode(" 查看 ", -1)
  121. ])]),
  122. _: 1
  123. }, 8, ["onClick"]),
  124. createVNode(_component_el_button, {
  125. size: "small",
  126. type: "primary",
  127. onClick: ($event) => editProduct(row)
  128. }, {
  129. default: withCtx(() => [..._cache[3] || (_cache[3] = [
  130. createTextVNode(" 编辑 ", -1)
  131. ])]),
  132. _: 1
  133. }, 8, ["onClick"])
  134. ]),
  135. _: 1
  136. })
  137. ]),
  138. _: 1
  139. }, 8, ["data"]),
  140. !loading.value && products.value.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_3, [
  141. createVNode(_component_el_empty, { description: "暂无产品数据" })
  142. ])) : createCommentVNode("", true)
  143. ])), [
  144. [_directive_loading, loading.value]
  145. ])
  146. ]),
  147. _: 1
  148. }),
  149. createVNode(_component_el_card, { class: "user-info-card" }, {
  150. header: withCtx(() => [..._cache[4] || (_cache[4] = [
  151. createBaseVNode("span", null, "当前用户信息", -1)
  152. ])]),
  153. default: withCtx(() => {
  154. var _a, _b, _c;
  155. return [
  156. createBaseVNode("div", _hoisted_4, [
  157. createBaseVNode("p", null, [
  158. _cache[5] || (_cache[5] = createBaseVNode("strong", null, "用户名:", -1)),
  159. createTextVNode(" " + toDisplayString((_a = unref(authStore).user) == null ? void 0 : _a.username), 1)
  160. ]),
  161. createBaseVNode("p", null, [
  162. _cache[6] || (_cache[6] = createBaseVNode("strong", null, "邮箱:", -1)),
  163. createTextVNode(" " + toDisplayString((_b = unref(authStore).user) == null ? void 0 : _b.email), 1)
  164. ]),
  165. createBaseVNode("p", null, [
  166. _cache[7] || (_cache[7] = createBaseVNode("strong", null, "状态:", -1)),
  167. createVNode(_component_el_tag, {
  168. type: ((_c = unref(authStore).user) == null ? void 0 : _c.is_active) ? "success" : "danger"
  169. }, {
  170. default: withCtx(() => {
  171. var _a2;
  172. return [
  173. createTextVNode(toDisplayString(((_a2 = unref(authStore).user) == null ? void 0 : _a2.is_active) ? "活跃" : "非活跃"), 1)
  174. ];
  175. }),
  176. _: 1
  177. }, 8, ["type"])
  178. ])
  179. ])
  180. ];
  181. }),
  182. _: 1
  183. })
  184. ]);
  185. };
  186. }
  187. });
  188. const Products_vue_vue_type_style_index_0_scoped_d133a70f_lang = "";
  189. const Products = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d133a70f"]]);
  190. export {
  191. Products as default
  192. };
  193. //# sourceMappingURL=Products-dev.3852cc44.js.map