import { u as useAuthStore } from "./index-dev.bb5c7162.js";
import { a as axios } from "./utils-dev.be08a1a2.js";
import { a as ElMessage } from "./element-dev.26a170ea.js";
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";
import { _ as _export_sfc } from "./_plugin-vue_export-helper-dev.cc2b3d55.js";
const _hoisted_1 = { class: "products-page" };
const _hoisted_2 = { class: "card-header" };
const _hoisted_3 = {
  key: 0,
  class: "empty-state"
};
const _hoisted_4 = { class: "user-info" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "Products",
  setup(__props) {
    const authStore = useAuthStore();
    const loading = ref(false);
    const products = ref([]);
    const loadProducts = async () => {
      loading.value = true;
      try {
        const response = await axios.get("/api/products");
        if (response.data.code === 0) {
          products.value = response.data.data.products;
          ElMessage.success("产品列表加载成功");
        } else {
          ElMessage.error(response.data.message || "加载失败");
        }
      } catch (error) {
        console.error("加载产品列表失败:", error);
        ElMessage.error("加载产品列表失败");
      } finally {
        loading.value = false;
      }
    };
    const viewProduct = (product) => {
      ElMessage.info(`查看产品: ${product.name}`);
    };
    const editProduct = (product) => {
      ElMessage.info(`编辑产品: ${product.name}`);
    };
    onMounted(() => {
      loadProducts();
    });
    return (_ctx, _cache) => {
      const _component_Refresh = resolveComponent("Refresh");
      const _component_el_icon = resolveComponent("el-icon");
      const _component_el_button = resolveComponent("el-button");
      const _component_el_table_column = resolveComponent("el-table-column");
      const _component_el_table = resolveComponent("el-table");
      const _component_el_empty = resolveComponent("el-empty");
      const _component_el_card = resolveComponent("el-card");
      const _component_el_tag = resolveComponent("el-tag");
      const _directive_loading = resolveDirective("loading");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        _cache[8] || (_cache[8] = createBaseVNode("div", { class: "page-header" }, [
          createBaseVNode("h2", null, "产品管理"),
          createBaseVNode("p", null, "这里展示了通过SSO认证保护的业务接口数据")
        ], -1)),
        createVNode(_component_el_card, null, {
          header: withCtx(() => [
            createBaseVNode("div", _hoisted_2, [
              _cache[1] || (_cache[1] = createBaseVNode("span", null, "产品列表", -1)),
              createVNode(_component_el_button, {
                type: "primary",
                onClick: loadProducts
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_icon, null, {
                    default: withCtx(() => [
                      createVNode(_component_Refresh)
                    ]),
                    _: 1
                  }),
                  _cache[0] || (_cache[0] = createTextVNode(" 刷新 ", -1))
                ]),
                _: 1
              })
            ])
          ]),
          default: withCtx(() => [
            withDirectives((openBlock(), createElementBlock("div", null, [
              createVNode(_component_el_table, {
                data: products.value,
                style: { "width": "100%" }
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_table_column, {
                    prop: "id",
                    label: "ID",
                    width: "80"
                  }),
                  createVNode(_component_el_table_column, {
                    prop: "name",
                    label: "产品名称"
                  }),
                  createVNode(_component_el_table_column, {
                    prop: "price",
                    label: "价格"
                  }, {
                    default: withCtx(({ row }) => [
                      createTextVNode(" ¥" + toDisplayString(row.price.toFixed(2)), 1)
                    ]),
                    _: 1
                  }),
                  createVNode(_component_el_table_column, {
                    prop: "description",
                    label: "描述"
                  }),
                  createVNode(_component_el_table_column, {
                    label: "操作",
                    width: "200"
                  }, {
                    default: withCtx(({ row }) => [
                      createVNode(_component_el_button, {
                        size: "small",
                        onClick: ($event) => viewProduct(row)
                      }, {
                        default: withCtx(() => [..._cache[2] || (_cache[2] = [
                          createTextVNode(" 查看 ", -1)
                        ])]),
                        _: 1
                      }, 8, ["onClick"]),
                      createVNode(_component_el_button, {
                        size: "small",
                        type: "primary",
                        onClick: ($event) => editProduct(row)
                      }, {
                        default: withCtx(() => [..._cache[3] || (_cache[3] = [
                          createTextVNode(" 编辑 ", -1)
                        ])]),
                        _: 1
                      }, 8, ["onClick"])
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }, 8, ["data"]),
              !loading.value && products.value.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_3, [
                createVNode(_component_el_empty, { description: "暂无产品数据" })
              ])) : createCommentVNode("", true)
            ])), [
              [_directive_loading, loading.value]
            ])
          ]),
          _: 1
        }),
        createVNode(_component_el_card, { class: "user-info-card" }, {
          header: withCtx(() => [..._cache[4] || (_cache[4] = [
            createBaseVNode("span", null, "当前用户信息", -1)
          ])]),
          default: withCtx(() => {
            var _a, _b, _c;
            return [
              createBaseVNode("div", _hoisted_4, [
                createBaseVNode("p", null, [
                  _cache[5] || (_cache[5] = createBaseVNode("strong", null, "用户名:", -1)),
                  createTextVNode(" " + toDisplayString((_a = unref(authStore).user) == null ? void 0 : _a.username), 1)
                ]),
                createBaseVNode("p", null, [
                  _cache[6] || (_cache[6] = createBaseVNode("strong", null, "邮箱:", -1)),
                  createTextVNode(" " + toDisplayString((_b = unref(authStore).user) == null ? void 0 : _b.email), 1)
                ]),
                createBaseVNode("p", null, [
                  _cache[7] || (_cache[7] = createBaseVNode("strong", null, "状态:", -1)),
                  createVNode(_component_el_tag, {
                    type: ((_c = unref(authStore).user) == null ? void 0 : _c.is_active) ? "success" : "danger"
                  }, {
                    default: withCtx(() => {
                      var _a2;
                      return [
                        createTextVNode(toDisplayString(((_a2 = unref(authStore).user) == null ? void 0 : _a2.is_active) ? "活跃" : "非活跃"), 1)
                      ];
                    }),
                    _: 1
                  }, 8, ["type"])
                ])
              ])
            ];
          }),
          _: 1
        })
      ]);
    };
  }
});
const Products_vue_vue_type_style_index_0_scoped_d133a70f_lang = "";
const Products = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d133a70f"]]);
export {
  Products as default
};
//# sourceMappingURL=Products-dev.3852cc44.js.map
