tav-ui
Version:
83 lines (80 loc) • 3.03 kB
JavaScript
import { defineComponent, reactive, watch, toRefs, resolveComponent, openBlock, createBlock, withCtx, createElementVNode, normalizeClass, createElementBlock, toDisplayString } from 'vue';
import { useMessage } from '../../../hooks/web/useMessage2.mjs';
import { useGlobalConfig } from '../../../hooks/global/useGlobalConfig2.mjs';
import '../../../locales/index2.mjs';
import { TaButton } from '../../button/index2.mjs';
import { followProps } from './types2.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
import { tavI18n } from '../../../locales/transfer2.mjs';
const _sfc_main = defineComponent({
name: "TaFollow",
components: {
TaButton
},
props: followProps,
emits: ["update:show"],
setup(props) {
const { createMessage } = useMessage();
const globalConfig = useGlobalConfig("components");
const state = reactive({
loading: false,
isFollow: false
});
const getFollwStatus = () => {
if (globalConfig.value && globalConfig.value.TaFollow) {
globalConfig.value.TaFollow.getFollwStatus(props.id).then((res) => {
state.isFollow = res.data ? !!res.data.status : false;
});
}
};
const changFollwStatus = () => {
state.loading = true;
if (globalConfig.value && globalConfig.value.TaFollow) {
globalConfig.value.TaFollow.updateFollowStatus({ followId: props.id, type: props.type }).then(() => {
const msg = state.isFollow ? tavI18n("Tav.follow.3") : tavI18n("Tav.follow.4");
state.isFollow = !state.isFollow;
createMessage.success(msg);
}).finally(() => {
state.loading = false;
});
}
};
getFollwStatus();
watch(() => props.id, (newValue) => {
if (newValue) {
getFollwStatus();
}
});
return {
...toRefs(state),
tavI18n,
getFollwStatus,
changFollwStatus
};
}
});
const _hoisted_1 = {
key: 0,
class: "active"
};
const _hoisted_2 = { key: 1 };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_TaButton = resolveComponent("TaButton");
return openBlock(), createBlock(_component_TaButton, {
class: "basic-follow",
type: "link",
loading: _ctx.loading,
onClick: _ctx.changFollwStatus
}, {
default: withCtx(() => [
createElementVNode("i", {
class: normalizeClass(`basic-follow-icon basic-follow-icon${_ctx.isFollow ? "-active" : ""}`)
}, null, 2),
_ctx.isFollow ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(_ctx.tavI18n("Tav.follow.1")), 1)) : (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(_ctx.tavI18n("Tav.follow.2")), 1))
]),
_: 1
}, 8, ["loading", "onClick"]);
}
var Follow = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/follow/src/follow.vue"]]);
export { Follow as default };
//# sourceMappingURL=follow2.mjs.map