12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- const net = require("../../utils/net.js");
- const {
- api_user_attention,
- api_topic_attention,
- } = require("../../utils/api.js");
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- isAttention: {
- type: Boolean,
- value: false,
- observer: function (newVal, oldVal) {
- // 属性值变化时执行
- this.setData({
- isLike: newVal,
- });
- },
- },
- type: {
- type: Number,
- value: 1, // 1 是用户,2 是话题
- },
- attentionId: {
- type: Number,
- value: 0,
- },
- index: {
- type: Number,
- value: 0,
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- isLike: false,
- },
- /**
- * 组件的方法列表
- */
- methods: {
- tapAttentionAction(e) {
- const { type, attentionId, index } = this.properties;
- const userInfo = wx.getStorageSync("USERINFO");
- if (userInfo) {
- let params = {};
- if (parseInt(type) == 1) {
- params.url = api_user_attention;
- params.data = {
- targetUserId: attentionId,
- };
- } else {
- params.url = api_topic_attention;
- params.data = {
- id: attentionId,
- };
- }
- net.req(params, true).then(
- (data) => {
- const { isAttention, attentionNum } = data;
- this.setData({
- isLike: !!isAttention,
- });
- this.triggerEvent("attention", {
- index: index,
- isAttention: isAttention,
- attentionNum: attentionNum,
- });
- },
- (e) => {
- wx.showToast({
- title: e.msg,
- });
- }
- );
- } else {
- wx.navigateTo({ url: `/pages/login/login` });
- }
- },
- },
- });
|