Browse Source

feat: 添加订阅消息功能并优化群组分享信息

添加微信小程序订阅消息工具模块
在发布内容前统一调用订阅消息功能
为群组添加分享信息字段并优化分享逻辑
master
主管理员 3 days ago
parent
commit
f0a62dd1f3
8 changed files with 122 additions and 41 deletions
  1. +13
    -0
      api/model/group.js
  2. +2
    -34
      pages_order/components/list/comment/commentPublish.vue
  3. +15
    -2
      pages_order/group/createGroup.vue
  4. +2
    -1
      pages_order/group/groupDetail.vue
  5. +5
    -1
      pages_order/post/addPost.vue
  6. +11
    -2
      pages_order/renting/addRenting.vue
  7. +7
    -1
      pages_order/work/addWork.vue
  8. +67
    -0
      utils/subscribeMessage.js

+ 13
- 0
api/model/group.js View File

@ -30,6 +30,19 @@ const api = {
loadingTitle: '加载中...'
},
/**
* 加入同城群
* 对应后端: POST /city/group/join
* 需要登录token
* @param {Object} group - 群组信息对象
*/
groupJoin: {
url: '/city/group/join',
method: 'GET',
auth: true,
limit: 1000,
},
/**
* 编辑同城群新增或更新
* 对应后端: POST /group/saveOrUpdate


+ 2
- 34
pages_order/components/list/comment/commentPublish.vue View File

@ -26,6 +26,7 @@
<script>
import { mapState } from 'vuex'
import EmailPopup from './emailPopup.vue'
import { subscribeBeforePublish } from '@/utils/subscribeMessage.js'
export default {
name: 'CommentPublish',
@ -90,7 +91,7 @@ export default {
//
async doSubmit() {
await this.onSubscribeMessageTap()
await subscribeBeforePublish()
let data = {
...this.form,
@ -140,39 +141,6 @@ export default {
})
})
},
//
onSubscribeMessageTap() {
return new Promise((resolve, reject) => {
let templateIds = [
'uXZnHWrjtcX9JHlnMpdlWmzgJp71sKxCRiMn3TrE-EE',
'gTzGpOfJcYxtbvPG9OHnhbureKz5XLG8NPyECUGb2lw',
];
wx.requestSubscribeMessage({
tmplIds: templateIds, // ID
success(res) {
resolve(res)
console.log('订阅消息调用成功', res);
// res[tmplId] ID
// res['your_template_id_1'] === 'accept'
templateIds.forEach(tmplId => {
if (res[tmplId] === 'accept') {
console.log(`用户同意订阅模板ID:${tmplId}`);
//
} else if (res[tmplId] === 'reject') {
console.log(`用户拒绝订阅模板ID:${tmplId}`);
} else {
console.log(`用户对该模板ID的订阅请求:${res[tmplId]}`); // 'ban'
}
});
},
fail(err) {
resolve(res)
console.error('订阅消息调用失败', err);
}
});
})
},
}
}
</script>


+ 15
- 2
pages_order/group/createGroup.vue View File

@ -75,6 +75,17 @@
></uv-input>
</view>
<view class="form-item">
<view class="form-label">分享信息</view>
<uv-textarea
v-model="groupForm.shareMsg"
placeholder="请输入分享时显示的信息(可选)"
:border="false"
:maxlength="100"
height="80"
></uv-textarea>
</view>
<!-- 群二维码上传 -->
<view class="form-item">
<view class="form-label">群二维码必填</view>
@ -125,7 +136,8 @@
classId: '',
notice: '',
num: '',
qrCode: ''
qrCode: '',
shareMsg: ''
},
qrCodeFileList: [] //
}
@ -155,7 +167,8 @@
classId: res.result.classId || '',
notice: res.result.notice || '',
num: res.result.num || '',
qrCode: res.result.qrCode || ''
qrCode: res.result.qrCode || '',
shareMsg: res.result.shareMsg || ''
}
//


+ 2
- 1
pages_order/group/groupDetail.vue View File

@ -122,6 +122,7 @@
// 广
showQrCodeAfterAd() {
this.showQrCode = true
this.$api('groupJoin', {id : this.groupId})
uni.showToast({
title: '恭喜获得群聊二维码!',
icon: 'success'
@ -135,7 +136,7 @@
this.groupInfo = res.result
//
this.share.title = res.result.title || '群组详情'
this.share.title = res.result.shareMsg || res.result.title || '群组详情'
this.share.imageUrl = this.$utils.getImageOne(res.result.image)
} else {
uni.showToast({


+ 5
- 1
pages_order/post/addPost.vue View File

@ -157,6 +157,7 @@
import { mapState } from 'vuex'
import Position from '@/utils/position.js'
import pickerHospital from '@/components/base/pickerHospital.vue'
import { subscribeBeforePublish } from '@/utils/subscribeMessage.js'
export default {
components : {
pickerHospital,
@ -279,7 +280,7 @@
},
//
submit(){
async submit(){
// if(this.fileList.length == 0){
// return uni.showToast({
@ -301,6 +302,9 @@
})
}
//
await subscribeBeforePublish()
delete this.form.shop
// image


+ 11
- 2
pages_order/renting/addRenting.vue View File

@ -230,8 +230,9 @@
</template>
<script>
import Position from '@/utils/position.js'
import { Position } from '@/utils/position.js'
import { mapState } from 'vuex'
import { subscribeBeforePublish } from '@/utils/subscribeMessage.js'
export default {
data() {
return {
@ -403,7 +404,7 @@
})
},
//
submit(){
async submit(){
if (this.$utils.verificationAll(this.form, {
title: '请输入标题',
@ -430,6 +431,14 @@
})
}
//
if (!this.isEdit) {
const subscribed = await subscribeBeforePublish()
if (!subscribed) {
return //
}
}
//
this.form.image = this.fileList.map(n => n.url).join(',')


+ 7
- 1
pages_order/work/addWork.vue View File

@ -212,6 +212,7 @@
<script>
import { mapState } from 'vuex'
import { subscribeBeforePublish } from '@/utils/subscribeMessage.js'
export default {
data() {
return {
@ -344,7 +345,7 @@
this.form[this.pickerKey] = e.value[0]
},
//
submit(){
async submit(){
if (this.$utils.verificationAll(this.form, {
title: '请输入招工标题',
@ -362,6 +363,11 @@
return
}
//
if (!this.isEdit) {
await subscribeBeforePublish()
}
// API
const apiName = this.isEdit ? 'editMyJob' : 'publishJob'
const params = this.isEdit ? { ...this.form, id: this.jobId } : this.form


+ 67
- 0
utils/subscribeMessage.js View File

@ -0,0 +1,67 @@
/**
* 微信小程序订阅消息工具
* 用于统一管理订阅消息通知功能
*/
/**
* 订阅模板消息
* @param {Array} templateIds - 模板ID数组如果不传则使用默认模板
* @returns {Promise} 返回订阅结果
*/
export function subscribeMessage(templateIds = null) {
return new Promise((resolve, reject) => {
// 默认的模板ID列表
const defaultTemplateIds = [
'uXZnHWrjtcX9JHlnMpdlWmzgJp71sKxCRiMn3TrE-EE',
'gTzGpOfJcYxtbvPG9OHnhbureKz5XLG8NPyECUGb2lw',
];
// 使用传入的模板ID或默认模板ID
const tmplIds = templateIds || defaultTemplateIds;
wx.requestSubscribeMessage({
tmplIds: tmplIds, // 需要订阅的模板ID列表
success(res) {
resolve(res);
console.log('订阅消息调用成功', res);
// 遍历处理每个模板ID的订阅结果
tmplIds.forEach(tmplId => {
if (res[tmplId] === 'accept') {
console.log(`用户同意订阅模板ID:${tmplId}`);
// 这里可以添加用户同意后的逻辑,比如发送消息等(注意:发送消息需要在后端进行)
} else if (res[tmplId] === 'reject') {
console.log(`用户拒绝订阅模板ID:${tmplId}`);
} else {
console.log(`用户对该模板ID的订阅请求:${res[tmplId]}`); // 'ban' 表示用户被禁止订阅该模板
}
});
},
fail(err) {
resolve(err); // 即使失败也resolve,避免阻塞业务流程
console.error('订阅消息调用失败', err);
}
});
});
}
/**
* 在发布内容前调用订阅消息
* 这是一个便捷方法用于在发布内容前统一处理订阅逻辑
* @param {Array} templateIds - 可选的模板ID数组
* @returns {Promise} 返回订阅结果
*/
export async function subscribeBeforePublish(templateIds = null) {
try {
const result = await subscribeMessage(templateIds);
return result;
} catch (error) {
console.error('订阅消息失败:', error);
return null;
}
}
export default {
subscribeMessage,
subscribeBeforePublish
};

Loading…
Cancel
Save