// my-component.js // 引入全局 Vue 对象(因在 HTML 中通过 script 引入,Vue 已挂载到 window) const { defineComponent, ref, inject } = Vue; // 定义组件(直接使用模板) export const report = defineComponent({ name: "report", props: { itemdata: { type: Object, default: () => {}, }, }, setup(props) { let item = ref({ ...props.itemdata }); const reasonList = ["广告", "辱骂", "重复发送", "不良信息", "其他"]; let reportAlertShow = inject("reportState"); let checkList = ref([]); let alertShow = ref(false); let alertText = ref(""); const selectRadio = (value) => { const index = checkList.value.indexOf(value); if (index === -1) checkList.value.push(value); else checkList.value.splice(index, 1); }; // 举报提交 const alertSubmit = () => { if (checkList.value.length == 0) { creationAlertBox("error", "请选择举报类型"); return; } checkList.value.push(alertText.value); reportAlertShow.value = false; ajax(`/v2/api/forum/postTopicReport`, { message: checkList.value, token: item.value.token, }).then((res) => { checkList.value = []; reportAlertShow.value = false; creationAlertBox("success", res.message || "举报成功"); }); }; // 取消 const cancel = () => (reportAlertShow.value = false); return { alertText, checkList, reasonList, selectRadio, cancel, alertSubmit, alertShow }; }, template: `
举报投诉
{{ s }}
{{ 200 - alertText.length }}
`, });