diff --git a/src/main/java/xuan/controller/ShareController.java b/src/main/java/xuan/controller/ShareController.java new file mode 100644 index 0000000..3c34582 --- /dev/null +++ b/src/main/java/xuan/controller/ShareController.java @@ -0,0 +1,76 @@ +package xuan.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import xuan.entity.ShareRecord; +import xuan.repository.ShareRecordRepository; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@RestController +@RequestMapping("/api/share") +public class ShareController { + + @Autowired + private ShareRecordRepository shareRecordRepository; + + @PostMapping("/create") + public Map createShare(@RequestBody Map params) { + Map result = new HashMap<>(); + + try { + String type = (String) params.get("type"); + String resultData = (String) params.get("resultData"); + String name = (String) params.get("name"); + + ShareRecord shareRecord = new ShareRecord(); + shareRecord.setShareId(UUID.randomUUID().toString().replace("-", "").substring(0, 16)); + shareRecord.setType(type); + shareRecord.setResultData(resultData); + shareRecord.setName(name); + + shareRecordRepository.save(shareRecord); + + result.put("success", true); + result.put("shareId", shareRecord.getShareId()); + result.put("message", "分享链接创建成功"); + } catch (Exception e) { + result.put("success", false); + result.put("error", "创建分享链接失败:" + e.getMessage()); + } + + return result; + } + + @GetMapping("/view/{shareId}") + public Map viewShare(@PathVariable String shareId) { + Map result = new HashMap<>(); + + try { + ShareRecord shareRecord = shareRecordRepository.findByShareId(shareId) + .orElse(null); + + if (shareRecord == null) { + result.put("success", false); + result.put("error", "分享链接不存在或已过期"); + return result; + } + + if (shareRecord.getExpireTime() != null && shareRecord.getExpireTime().before(new java.util.Date())) { + result.put("success", false); + result.put("error", "分享链接已过期"); + return result; + } + + result.put("success", true); + result.put("data", shareRecord); + } catch (Exception e) { + result.put("success", false); + result.put("error", "获取分享数据失败:" + e.getMessage()); + } + + return result; + } +} diff --git a/src/main/java/xuan/entity/ShareRecord.java b/src/main/java/xuan/entity/ShareRecord.java new file mode 100644 index 0000000..8f91293 --- /dev/null +++ b/src/main/java/xuan/entity/ShareRecord.java @@ -0,0 +1,94 @@ +package xuan.entity; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Table(name = "share_record") +public class ShareRecord { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(unique = true, nullable = false, length = 32) + private String shareId; + + @Column(nullable = false, length = 20) + private String type; + + @Column(columnDefinition = "TEXT") + private String resultData; + + @Column(length = 50) + private String name; + + @Column(updatable = false) + private Date createTime; + + private Date expireTime; + + @PrePersist + protected void onCreate() { + createTime = new Date(); + if (expireTime == null) { + expireTime = new Date(System.currentTimeMillis() + 30L * 24 * 60 * 60 * 1000); + } + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getShareId() { + return shareId; + } + + public void setShareId(String shareId) { + this.shareId = shareId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getResultData() { + return resultData; + } + + public void setResultData(String resultData) { + this.resultData = resultData; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getExpireTime() { + return expireTime; + } + + public void setExpireTime(Date expireTime) { + this.expireTime = expireTime; + } +} diff --git a/src/main/java/xuan/repository/ShareRecordRepository.java b/src/main/java/xuan/repository/ShareRecordRepository.java new file mode 100644 index 0000000..0e1f807 --- /dev/null +++ b/src/main/java/xuan/repository/ShareRecordRepository.java @@ -0,0 +1,12 @@ +package xuan.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import xuan.entity.ShareRecord; + +import java.util.Optional; + +@Repository +public interface ShareRecordRepository extends JpaRepository { + Optional findByShareId(String shareId); +} diff --git a/xuan-deduct-uniapp/src/components/share-button/share-button.vue b/xuan-deduct-uniapp/src/components/share-button/share-button.vue new file mode 100644 index 0000000..fdbacd9 --- /dev/null +++ b/xuan-deduct-uniapp/src/components/share-button/share-button.vue @@ -0,0 +1,110 @@ + + + + + diff --git a/xuan-deduct-uniapp/src/mixins/shareMixin.js b/xuan-deduct-uniapp/src/mixins/shareMixin.js new file mode 100644 index 0000000..762bb60 --- /dev/null +++ b/xuan-deduct-uniapp/src/mixins/shareMixin.js @@ -0,0 +1,50 @@ +import api from '@/utils/api.js' + +export default { + methods: { + async shareResult(type, name) { + try { + uni.showLoading({ title: '创建分享链接...' }) + + const shareData = { + type: type, + resultData: JSON.stringify(this.result), + name: name || '测算结果' + } + + const res = await api.shareApi.create(shareData) + + uni.hideLoading() + + if (res.success) { + const shareUrl = `/pages/share/view?shareId=${res.shareId}` + + uni.showModal({ + title: '分享成功', + content: '点击确定转发给微信好友', + success: (modalRes) => { + if (modalRes.confirm) { + uni.shareAppMessage({ + title: `${name}的测算结果`, + path: shareUrl, + imageUrl: '/static/share.png' + }) + } + } + }) + } else { + uni.showToast({ + title: res.error || '创建分享失败', + icon: 'none' + }) + } + } catch (e) { + uni.hideLoading() + uni.showToast({ + title: '分享失败:' + (e.message || '未知错误'), + icon: 'none' + }) + } + } + } +} diff --git a/xuan-deduct-uniapp/src/pages.json b/xuan-deduct-uniapp/src/pages.json index 5a03b7e..7b4f0b0 100644 --- a/xuan-deduct-uniapp/src/pages.json +++ b/xuan-deduct-uniapp/src/pages.json @@ -264,6 +264,14 @@ "navigationBarBackgroundColor": "#EC4899", "navigationBarTextStyle": "white" } + }, + { + "path": "pages/share/view", + "style": { + "navigationBarTitleText": "测算结果分享", + "navigationBarBackgroundColor": "#667eea", + "navigationBarTextStyle": "white" + } } ], "globalStyle": { diff --git a/xuan-deduct-uniapp/src/pages/bazi/result.vue b/xuan-deduct-uniapp/src/pages/bazi/result.vue index 596e42c..5b69b0e 100644 --- a/xuan-deduct-uniapp/src/pages/bazi/result.vue +++ b/xuan-deduct-uniapp/src/pages/bazi/result.vue @@ -160,6 +160,12 @@ + + @@ -265,6 +271,50 @@ export default { return this.result.baZiKongWang[index] } return '-' + }, + async shareResult() { + try { + uni.showLoading({ title: '创建分享链接...' }) + + const shareData = { + type: 'bazi', + resultData: JSON.stringify(this.result), + name: this.result.name || '八字命盘' + } + + const res = await api.shareApi.create(shareData) + + uni.hideLoading() + + if (res.success) { + const shareUrl = `/pages/share/view?shareId=${res.shareId}` + + uni.showModal({ + title: '分享成功', + content: '点击确定转发给微信好友', + success: (modalRes) => { + if (modalRes.confirm) { + uni.shareAppMessage({ + title: `${this.result.name || '八字命盘'}的测算结果`, + path: shareUrl, + imageUrl: '/static/share.png' + }) + } + } + }) + } else { + uni.showToast({ + title: res.error || '创建分享失败', + icon: 'none' + }) + } + } catch (e) { + uni.hideLoading() + uni.showToast({ + title: '分享失败:' + (e.message || '未知错误'), + icon: 'none' + }) + } } } } @@ -279,6 +329,7 @@ page { .container { min-height: 100vh; padding: 32rpx; + padding-bottom: 160rpx; } .header-card { @@ -750,4 +801,29 @@ page { color: #374151; line-height: 1.8; } + +.share-card { + position: fixed; + bottom: 0; + left: 0; + right: 0; + padding: 20rpx 32rpx; + background: linear-gradient(180deg, transparent 0%, #FDF2F8 20%); + z-index: 100; +} + +.share-btn { + background: linear-gradient(135deg, #DC2626 0%, #B91C1C 100%); + color: #fff; + border: none; + padding: 24rpx 0; + border-radius: 50rpx; + font-size: 32rpx; + font-weight: bold; + box-shadow: 0 8rpx 24rpx rgba(220, 38, 38, 0.3); +} + +.share-btn-text { + color: #fff; +} diff --git a/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue b/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue index b957c5a..d0b0a64 100644 --- a/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue +++ b/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue @@ -72,12 +72,12 @@ 日期类型 - - 公历 - 农历 + + 公历 + @@ -125,7 +125,7 @@ export default { solarDate: '2024-01-01', birthTime: '12:00', gender: '男', - dateType: 0, + dateType: 1, guiRenType: 0, loading: false } diff --git a/xuan-deduct-uniapp/src/pages/daliuren/result.vue b/xuan-deduct-uniapp/src/pages/daliuren/result.vue index 30480ff..fc39f47 100644 --- a/xuan-deduct-uniapp/src/pages/daliuren/result.vue +++ b/xuan-deduct-uniapp/src/pages/daliuren/result.vue @@ -213,11 +213,18 @@ + + @@ -268,6 +321,7 @@ page { .container { min-height: 100vh; padding: 24rpx; + padding-bottom: 160rpx; } .header-card { @@ -656,4 +710,32 @@ page { font-weight: 600; color: #DC2626; } + +.share-card { + position: fixed; + bottom: 0; + left: 0; + right: 0; + padding: 20rpx 32rpx; + background: linear-gradient(180deg, transparent 0%, #F5F3FF 20%); + z-index: 100; +} + +.share-btn { + background: linear-gradient(135deg, #7C3AED 0%, #6D28D9 100%); + color: #fff; + border: none; + padding: 24rpx 0; + border-radius: 50rpx; + font-size: 32rpx; + font-weight: bold; + box-shadow: 0 8rpx 24rpx rgba(124, 58, 237, 0.3); + display: flex; + align-items: center; + justify-content: center; +} + +.share-btn-text { + color: #fff; +} diff --git a/xuan-deduct-uniapp/src/pages/mine/mine.vue b/xuan-deduct-uniapp/src/pages/mine/mine.vue index f71ae4e..e55e796 100644 --- a/xuan-deduct-uniapp/src/pages/mine/mine.vue +++ b/xuan-deduct-uniapp/src/pages/mine/mine.vue @@ -1,12 +1,16 @@ + + diff --git a/xuan-deduct-uniapp/src/pages/ziwei/result.vue b/xuan-deduct-uniapp/src/pages/ziwei/result.vue index 3cfdc50..df00839 100644 --- a/xuan-deduct-uniapp/src/pages/ziwei/result.vue +++ b/xuan-deduct-uniapp/src/pages/ziwei/result.vue @@ -127,11 +127,18 @@ + +