number-analysis.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="page-number-analysis">
  3. <!-- ========== Phone Input Section ========== -->
  4. <view class="input-card">
  5. <text class="input-label">手机号码</text>
  6. <view class="input-row">
  7. <input
  8. v-model="phoneNumber"
  9. class="phone-input"
  10. type="number"
  11. maxlength="11"
  12. placeholder="请输入11位手机号码"
  13. placeholder-class="input-placeholder"
  14. @confirm="handleAnalyze"
  15. />
  16. <view class="btn-analyze" :class="{ analyzing: analyzing }" @click="handleAnalyze">
  17. <text class="btn-analyze-text">{{ analyzing ? '分析中' : '分析' }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- ========== Star Combinations Result ========== -->
  22. <view v-if="starCombinations.length > 0" class="result-section">
  23. <view class="section-header">
  24. <text class="section-title">🔢 八星数组</text>
  25. </view>
  26. <view class="star-grid">
  27. <view
  28. v-for="(star, index) in starCombinations"
  29. :key="index"
  30. class="star-card"
  31. :class="'star-type-' + star.type"
  32. >
  33. <view class="star-card-header">
  34. <text class="star-pair">{{ star.pair }}</text>
  35. <text class="star-name">{{ star.name }}</text>
  36. </view>
  37. <view class="star-card-body">
  38. <text class="star-energy">{{ star.energy }}</text>
  39. <text class="star-desc">{{ star.description || '' }}</text>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- ========== AI Summary ========== -->
  45. <view v-if="summary" class="summary-card">
  46. <view class="summary-header">
  47. <text class="summary-title">🤖 AI 综合解读</text>
  48. <text v-if="summaryDate" class="summary-date">{{ summaryDate }}</text>
  49. </view>
  50. <view class="summary-body">
  51. <text class="summary-content">{{ summary }}</text>
  52. </view>
  53. </view>
  54. <!-- ========== Analysis History ========== -->
  55. <view v-if="history.length > 0" class="history-section">
  56. <view class="section-header">
  57. <text class="section-title">📋 历史分析</text>
  58. </view>
  59. <view
  60. v-for="item in history"
  61. :key="item.id"
  62. class="history-card"
  63. @click="loadHistory(item)"
  64. >
  65. <text class="history-phone">{{ maskPhone(item.phoneNumber) }}</text>
  66. <view class="history-meta">
  67. <text class="history-date">{{ formatDate(item.createdAt) }}</text>
  68. <text v-if="item.summary" class="history-status">已解读</text>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script setup>
  75. import { ref } from 'vue'
  76. import { onShow } from '@dcloudio/uni-app'
  77. import requestInstance from '@/utils/api'
  78. const phoneNumber = ref('')
  79. const analyzing = ref(false)
  80. const starCombinations = ref([])
  81. const summary = ref('')
  82. const summaryDate = ref('')
  83. const history = ref([])
  84. const analysisApi = {
  85. analyze: (data) => requestInstance.post('/number-analysis/analyze', data),
  86. list: (data) => requestInstance.post('/number-analysis/list', data),
  87. get: (id) => requestInstance.post('/number-analysis/detail', { id })
  88. }
  89. onShow(() => {
  90. fetchHistory()
  91. })
  92. async function fetchHistory() {
  93. try {
  94. history.value = await analysisApi.list({})
  95. } catch (e) {
  96. history.value = []
  97. }
  98. }
  99. async function handleAnalyze() {
  100. const num = phoneNumber.value.trim()
  101. if (num.length < 7) {
  102. uni.showToast({ title: '请输入至少7位数字', icon: 'none' })
  103. return
  104. }
  105. if (analyzing.value) return
  106. analyzing.value = true
  107. try {
  108. const result = await analysisApi.analyze({ phoneNumber: num })
  109. if (result) {
  110. starCombinations.value = result.starCombinations || []
  111. summary.value = result.summary || ''
  112. summaryDate.value = result.createdAt || ''
  113. }
  114. // Refresh history
  115. fetchHistory()
  116. } catch (e) {
  117. uni.showToast({ title: '分析失败,请重试', icon: 'none' })
  118. } finally {
  119. analyzing.value = false
  120. }
  121. }
  122. function loadHistory(item) {
  123. phoneNumber.value = item.phoneNumber || ''
  124. if (item.starCombinations) {
  125. try {
  126. starCombinations.value = typeof item.starCombinations === 'string'
  127. ? JSON.parse(item.starCombinations)
  128. : item.starCombinations
  129. } catch (e) {
  130. starCombinations.value = []
  131. }
  132. } else {
  133. starCombinations.value = []
  134. }
  135. summary.value = item.summary || ''
  136. summaryDate.value = item.createdAt || ''
  137. }
  138. function maskPhone(phone) {
  139. if (!phone) return ''
  140. if (phone.length >= 7) {
  141. return phone.slice(0, 3) + '****' + phone.slice(-4)
  142. }
  143. return phone
  144. }
  145. function formatDate(dateStr) {
  146. if (!dateStr) return ''
  147. return dateStr.slice(0, 10)
  148. }
  149. </script>
  150. <style scoped lang="scss">
  151. .page-number-analysis {
  152. min-height: 100vh;
  153. background: var(--color-bg);
  154. padding: 16px;
  155. }
  156. /* ========== Input Card ========== */
  157. .input-card {
  158. background: var(--color-bg-card);
  159. border-radius: 16px;
  160. padding: 20px;
  161. box-shadow: var(--shadow-card);
  162. margin-bottom: 16px;
  163. }
  164. .input-label {
  165. display: block;
  166. font-size: 14px;
  167. font-weight: 600;
  168. color: var(--color-text-secondary);
  169. margin-bottom: 12px;
  170. }
  171. .input-row {
  172. display: flex;
  173. gap: 12px;
  174. }
  175. .phone-input {
  176. flex: 1;
  177. height: 48px;
  178. border: 1px solid var(--color-border);
  179. border-radius: 12px;
  180. padding: 0 14px;
  181. font-size: 18px;
  182. color: var(--color-text-primary);
  183. background: var(--color-bg-card);
  184. box-sizing: border-box;
  185. }
  186. .phone-input:focus {
  187. border-color: var(--color-brand);
  188. box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.1);
  189. }
  190. .input-placeholder {
  191. color: var(--color-text-secondary);
  192. font-size: 16px;
  193. }
  194. .btn-analyze {
  195. flex-shrink: 0;
  196. height: 48px;
  197. padding: 0 24px;
  198. background: var(--color-brand);
  199. border-radius: 12px;
  200. display: flex;
  201. align-items: center;
  202. justify-content: center;
  203. }
  204. .btn-analyze:active {
  205. transform: scale(0.97);
  206. opacity: 0.9;
  207. }
  208. .btn-analyze.analyzing {
  209. opacity: 0.7;
  210. pointer-events: none;
  211. }
  212. .btn-analyze-text {
  213. color: var(--color-bg-card);
  214. font-size: 16px;
  215. font-weight: 600;
  216. }
  217. /* ========== Sections ========== */
  218. .result-section,
  219. .history-section {
  220. margin-bottom: 16px;
  221. }
  222. .section-header {
  223. margin-bottom: 12px;
  224. }
  225. .section-title {
  226. font-size: 17px;
  227. font-weight: 600;
  228. color: var(--color-text-primary);
  229. }
  230. /* ========== Star Grid ========== */
  231. .star-grid {
  232. display: flex;
  233. flex-direction: column;
  234. gap: 10px;
  235. }
  236. .star-card {
  237. background: var(--color-bg-card);
  238. border-radius: 14px;
  239. padding: 14px 16px;
  240. box-shadow: var(--shadow-card);
  241. border-left: 4px solid var(--color-text-secondary);
  242. }
  243. .star-card.star-type-ji { border-left-color: #D94A4A; }
  244. .star-card.star-type-huo { border-left-color: #E8A238; }
  245. .star-card.star-type-yan { border-left-color: #4A90D9; }
  246. .star-card.star-type-tian { border-left-color: #2D8B67; }
  247. .star-card.star-type-sheng { border-left-color: #7B6FA0; }
  248. .star-card.star-type-ju { border-left-color: #C9A84C; }
  249. .star-card.star-type-fu { border-left-color: #4A6FA5; }
  250. .star-card.star-type-jue { border-left-color: #B85C3A; }
  251. .star-card-header {
  252. display: flex;
  253. align-items: center;
  254. gap: 10px;
  255. margin-bottom: 6px;
  256. }
  257. .star-pair {
  258. font-size: 20px;
  259. font-weight: 700;
  260. color: var(--color-text-primary);
  261. }
  262. .star-name {
  263. font-size: 14px;
  264. font-weight: 500;
  265. color: var(--color-text-secondary);
  266. }
  267. .star-card-body {
  268. padding-left: 2px;
  269. }
  270. .star-energy {
  271. font-size: 13px;
  272. font-weight: 600;
  273. color: var(--color-brand);
  274. display: block;
  275. margin-bottom: 2px;
  276. text-transform: capitalize;
  277. }
  278. .star-desc {
  279. font-size: 12px;
  280. color: var(--color-text-secondary);
  281. line-height: 1.5;
  282. display: block;
  283. }
  284. /* ========== Summary Card ========== */
  285. .summary-card {
  286. background: var(--color-bg-card);
  287. border-radius: 16px;
  288. padding: 20px 16px;
  289. box-shadow: var(--shadow-card);
  290. margin-bottom: 16px;
  291. }
  292. .summary-header {
  293. display: flex;
  294. justify-content: space-between;
  295. align-items: center;
  296. margin-bottom: 12px;
  297. }
  298. .summary-title {
  299. font-size: 16px;
  300. font-weight: 600;
  301. color: var(--color-text-primary);
  302. }
  303. .summary-date {
  304. font-size: 12px;
  305. color: var(--color-text-secondary);
  306. }
  307. .summary-body {
  308. background: var(--color-bg-secondary);
  309. border-radius: 12px;
  310. padding: 16px;
  311. }
  312. .summary-content {
  313. font-size: 14px;
  314. color: var(--color-text-secondary);
  315. line-height: 1.8;
  316. white-space: pre-wrap;
  317. }
  318. /* ========== History ========== */
  319. .history-card {
  320. background: var(--color-bg-card);
  321. border-radius: 14px;
  322. padding: 14px 16px;
  323. margin-bottom: 10px;
  324. box-shadow: var(--shadow-card);
  325. display: flex;
  326. justify-content: space-between;
  327. align-items: center;
  328. }
  329. .history-card:active {
  330. transform: scale(0.98);
  331. opacity: 0.9;
  332. }
  333. .history-phone {
  334. font-size: 16px;
  335. font-weight: 600;
  336. color: var(--color-text-primary);
  337. }
  338. .history-meta {
  339. display: flex;
  340. align-items: center;
  341. gap: 10px;
  342. }
  343. .history-date {
  344. font-size: 12px;
  345. color: var(--color-text-secondary);
  346. }
  347. .history-status {
  348. font-size: 11px;
  349. color: var(--color-success);
  350. background: var(--color-success-bg);
  351. padding: 2px 8px;
  352. border-radius: 10px;
  353. font-weight: 500;
  354. }
  355. </style>