analysis-select.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view class="page-select">
  3. <!-- ========== Member Selection ========== -->
  4. <view class="section">
  5. <text class="section-title">选择分析成员</text>
  6. <text class="section-desc">选择您自己以及想分析的关系人(至少选2人)</text>
  7. <!-- Self (always included) -->
  8. <view class="member-card self-card">
  9. <view class="member-avatar self-avatar">
  10. <text class="avatar-text">我</text>
  11. </view>
  12. <view class="member-info">
  13. <text class="member-name">我(本人)</text>
  14. <text class="member-detail">{{ userProfile.birthYear }}-{{ userProfile.birthMonth }}-{{ userProfile.birthDay }}</text>
  15. </view>
  16. <view class="member-checked">
  17. <text class="check-icon">✓</text>
  18. </view>
  19. </view>
  20. <!-- Relations list -->
  21. <view v-if="loading" class="loading-hint">加载关系人...</view>
  22. <view v-else-if="relations.length === 0" class="empty-hint">
  23. <text>暂无关系人,请先</text>
  24. <text class="link-text" @click="goAddRelation">添加关系人</text>
  25. </view>
  26. <view
  27. v-for="item in relations"
  28. :key="item.id"
  29. class="member-card"
  30. :class="{ selected: selectedIds.includes(item.id) }"
  31. @click="toggleRelation(item.id)"
  32. >
  33. <view class="member-avatar">
  34. <text class="avatar-text">{{ item.name ? item.name[0] : '?' }}</text>
  35. </view>
  36. <view class="member-info">
  37. <text class="member-name">{{ item.name || '未知' }}</text>
  38. <text class="member-detail">{{ relationTypeLabel(item.relationType) }} · {{ item.birthDateText || '' }}</text>
  39. </view>
  40. <view class="member-checkbox">
  41. <view class="checkbox-box" :class="{ checked: selectedIds.includes(item.id) }">
  42. <text v-if="selectedIds.includes(item.id)" class="checkbox-icon">✓</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- ========== Question Input ========== -->
  48. <view class="section">
  49. <text class="section-title">您想咨询什么?</text>
  50. <view class="input-wrap">
  51. <textarea
  52. v-model="question"
  53. class="question-input"
  54. placeholder="例如:我们之间的能量是否匹配?或者想了解某方面的关系影响..."
  55. placeholder-class="input-placeholder"
  56. maxlength="500"
  57. :auto-height="true"
  58. />
  59. </view>
  60. <text class="char-count">{{ question.length }}/500</text>
  61. </view>
  62. <!-- ========== Submit ========== -->
  63. <view class="submit-bar">
  64. <view
  65. class="btn-submit"
  66. :class="{ disabled: !canSubmit || submitting }"
  67. @click="handleStart"
  68. >
  69. <text class="btn-submit-text">{{ submitting ? '分析中...' : '开始分析' }}</text>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script setup>
  75. import { ref, computed } from 'vue'
  76. import { onShow } from '@dcloudio/uni-app'
  77. import { useUserStore } from '@/stores/user'
  78. import request from '@/utils/api'
  79. const userStore = useUserStore()
  80. const relations = ref([])
  81. const loading = ref(false)
  82. const selectedIds = ref([])
  83. const question = ref('')
  84. const submitting = ref(false)
  85. const userProfile = computed(() => ({
  86. birthYear: userStore.birthYear || '----',
  87. birthMonth: userStore.birthMonth || '--',
  88. birthDay: userStore.birthDay || '--'
  89. }))
  90. const canSubmit = computed(() => selectedIds.value.length >= 1 && question.value.trim().length > 0)
  91. const relationTypeMap = {
  92. spouse: '夫妻',
  93. parent_child: '亲子',
  94. colleague: '同事',
  95. friend: '朋友',
  96. superior: '上下级'
  97. }
  98. function relationTypeLabel(type) {
  99. return relationTypeMap[type] || type || '未知'
  100. }
  101. onShow(() => {
  102. fetchRelations()
  103. })
  104. async function fetchRelations() {
  105. loading.value = true
  106. try {
  107. relations.value = await request.post('/relation/list', {})
  108. } catch (e) {
  109. relations.value = []
  110. } finally {
  111. loading.value = false
  112. }
  113. }
  114. function toggleRelation(id) {
  115. const idx = selectedIds.value.indexOf(id)
  116. if (idx > -1) {
  117. selectedIds.value.splice(idx, 1)
  118. } else {
  119. selectedIds.value.push(id)
  120. }
  121. }
  122. function goAddRelation() {
  123. uni.navigateTo({ url: '/pages/relations/add-relation' })
  124. }
  125. async function handleStart() {
  126. if (!canSubmit.value || submitting.value) return
  127. submitting.value = true
  128. try {
  129. const res = await request.post('/relation/analysis/start', {
  130. relationIds: selectedIds.value,
  131. question: question.value.trim()
  132. })
  133. if (res && res.id) {
  134. uni.redirectTo({
  135. url: '/pages/relations/analysis-chat?recordId=' + res.id
  136. })
  137. }
  138. } catch (e) {
  139. uni.showToast({ title: '启动分析失败', icon: 'none' })
  140. } finally {
  141. submitting.value = false
  142. }
  143. }
  144. </script>
  145. <style scoped lang="scss">
  146. @import "@/styles/theme.scss";
  147. .page-select {
  148. min-height: 100vh;
  149. background: var(--color-bg);
  150. padding: 16px;
  151. }
  152. .section {
  153. margin-bottom: 24px;
  154. }
  155. .section-title {
  156. display: block;
  157. font-size: 17px;
  158. font-weight: 700;
  159. color: var(--color-text-primary);
  160. margin-bottom: 6px;
  161. }
  162. .section-desc {
  163. display: block;
  164. font-size: 13px;
  165. color: var(--color-text-secondary);
  166. margin-bottom: 14px;
  167. }
  168. /* Member cards */
  169. .member-card {
  170. display: flex;
  171. align-items: center;
  172. background: var(--color-bg-card);
  173. border-radius: 14px;
  174. padding: 14px 16px;
  175. margin-bottom: 10px;
  176. border: 2px solid transparent;
  177. transition: border-color 0.2s;
  178. }
  179. .member-card:active {
  180. transform: scale(0.98);
  181. }
  182. .member-card.selected {
  183. border-color: var(--color-gold);
  184. background: linear-gradient(135deg, var(--color-bg-card), rgba(201, 168, 76, 0.06));
  185. }
  186. .self-card {
  187. border-color: var(--color-brand);
  188. opacity: 0.85;
  189. }
  190. .member-avatar {
  191. width: 44px;
  192. height: 44px;
  193. border-radius: 50%;
  194. background: var(--color-brand);
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. margin-right: 14px;
  199. flex-shrink: 0;
  200. }
  201. .self-avatar {
  202. background: var(--color-gold);
  203. }
  204. .avatar-text {
  205. font-size: 16px;
  206. font-weight: 700;
  207. color: var(--color-bg-card);
  208. }
  209. .member-info {
  210. flex: 1;
  211. min-width: 0;
  212. }
  213. .member-name {
  214. display: block;
  215. font-size: 15px;
  216. font-weight: 600;
  217. color: var(--color-text-primary);
  218. margin-bottom: 3px;
  219. }
  220. .member-detail {
  221. display: block;
  222. font-size: 12px;
  223. color: var(--color-text-secondary);
  224. }
  225. .member-checkbox {
  226. margin-left: 10px;
  227. flex-shrink: 0;
  228. }
  229. .checkbox-box {
  230. width: 22px;
  231. height: 22px;
  232. border-radius: 50%;
  233. border: 2px solid var(--color-border);
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. transition: all 0.2s;
  238. }
  239. .checkbox-box.checked {
  240. background: var(--color-gold);
  241. border-color: var(--color-gold);
  242. }
  243. .checkbox-icon {
  244. color: var(--color-bg-card);
  245. font-size: 12px;
  246. font-weight: 700;
  247. }
  248. .member-checked {
  249. margin-left: 10px;
  250. }
  251. .check-icon {
  252. font-size: 18px;
  253. color: var(--color-gold);
  254. font-weight: 700;
  255. }
  256. /* Loading / Empty */
  257. .loading-hint, .empty-hint {
  258. text-align: center;
  259. padding: 30px 0;
  260. font-size: 14px;
  261. color: var(--color-text-secondary);
  262. }
  263. .link-text {
  264. color: var(--color-brand);
  265. font-weight: 600;
  266. text-decoration: underline;
  267. }
  268. /* Question input */
  269. .input-wrap {
  270. background: var(--color-bg-card);
  271. border-radius: 12px;
  272. padding: 14px;
  273. border: 1px solid var(--color-border);
  274. }
  275. .question-input {
  276. width: 100%;
  277. min-height: 100px;
  278. font-size: 15px;
  279. color: var(--color-text-primary);
  280. line-height: 1.6;
  281. background: transparent;
  282. }
  283. .input-placeholder {
  284. color: var(--color-text-secondary);
  285. font-size: 14px;
  286. }
  287. .char-count {
  288. display: block;
  289. text-align: right;
  290. font-size: 12px;
  291. color: var(--color-text-secondary);
  292. margin-top: 4px;
  293. padding-right: 4px;
  294. }
  295. /* Submit */
  296. .submit-bar {
  297. position: sticky;
  298. bottom: 0;
  299. padding: 12px 0 24px;
  300. background: var(--color-bg);
  301. }
  302. .btn-submit {
  303. width: 100%;
  304. height: 50px;
  305. background: linear-gradient(135deg, var(--color-brand), darken(var(--color-brand), 4%));
  306. border-radius: 14px;
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. }
  311. .btn-submit:active {
  312. transform: scale(0.97);
  313. opacity: 0.9;
  314. }
  315. .btn-submit.disabled {
  316. opacity: 0.5;
  317. pointer-events: none;
  318. }
  319. .btn-submit-text {
  320. color: var(--color-bg-card);
  321. font-size: 17px;
  322. font-weight: 700;
  323. }
  324. </style>