analysis-select.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="page-select" :class="themeClass">
  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. import { useTheme } from '@/composables/useThemeStyle'
  80. const { themeClass } = useTheme()
  81. const userStore = useUserStore()
  82. const relations = ref([])
  83. const loading = ref(false)
  84. const selectedIds = ref([])
  85. const question = ref('')
  86. const submitting = ref(false)
  87. const userProfile = computed(() => ({
  88. birthYear: userStore.birthYear || '----',
  89. birthMonth: userStore.birthMonth || '--',
  90. birthDay: userStore.birthDay || '--'
  91. }))
  92. const canSubmit = computed(() => selectedIds.value.length >= 1 && question.value.trim().length > 0)
  93. const relationTypeMap = {
  94. spouse: '夫妻',
  95. parent_child: '亲子',
  96. colleague: '同事',
  97. friend: '朋友',
  98. superior: '上下级'
  99. }
  100. function relationTypeLabel(type) {
  101. return relationTypeMap[type] || type || '未知'
  102. }
  103. onShow(() => {
  104. fetchRelations()
  105. })
  106. async function fetchRelations() {
  107. loading.value = true
  108. try {
  109. relations.value = await request.post('/relation/list', {})
  110. } catch (e) {
  111. relations.value = []
  112. } finally {
  113. loading.value = false
  114. }
  115. }
  116. function toggleRelation(id) {
  117. const idx = selectedIds.value.indexOf(id)
  118. if (idx > -1) {
  119. selectedIds.value.splice(idx, 1)
  120. } else {
  121. selectedIds.value.push(id)
  122. }
  123. }
  124. function goAddRelation() {
  125. uni.navigateTo({ url: '/pages/relations/add-relation' })
  126. }
  127. async function handleStart() {
  128. if (!canSubmit.value || submitting.value) return
  129. submitting.value = true
  130. try {
  131. const res = await request.post('/relation/analysis/start', {
  132. relationIds: selectedIds.value,
  133. question: question.value.trim()
  134. })
  135. if (res && res.id) {
  136. uni.redirectTo({
  137. url: '/pages/relations/analysis-chat?recordId=' + res.id
  138. })
  139. }
  140. } catch (e) {
  141. uni.showToast({ title: '启动分析失败', icon: 'none' })
  142. } finally {
  143. submitting.value = false
  144. }
  145. }
  146. </script>
  147. <style scoped lang="scss">
  148. $brand-color: #1E3A5F;
  149. .page-select {
  150. min-height: 100vh;
  151. background: var(--color-bg);
  152. padding: 16px;
  153. }
  154. .section {
  155. margin-bottom: 24px;
  156. }
  157. .section-title {
  158. display: block;
  159. font-size: 17px;
  160. font-weight: 700;
  161. color: var(--color-text-primary);
  162. margin-bottom: 6px;
  163. }
  164. .section-desc {
  165. display: block;
  166. font-size: 13px;
  167. color: var(--color-text-secondary);
  168. margin-bottom: 14px;
  169. }
  170. /* Member cards */
  171. .member-card {
  172. display: flex;
  173. align-items: center;
  174. background: var(--color-bg-card);
  175. border-radius: 14px;
  176. padding: 14px 16px;
  177. margin-bottom: 10px;
  178. border: 2px solid transparent;
  179. transition: border-color 0.2s;
  180. }
  181. .member-card:active {
  182. transform: scale(0.98);
  183. }
  184. .member-card.selected {
  185. border-color: var(--color-gold);
  186. background: linear-gradient(135deg, var(--color-bg-card), rgba(201, 168, 76, 0.06));
  187. }
  188. .self-card {
  189. border-color: var(--color-brand);
  190. opacity: 0.85;
  191. }
  192. .member-avatar {
  193. width: 44px;
  194. height: 44px;
  195. border-radius: 50%;
  196. background: var(--color-brand);
  197. display: flex;
  198. align-items: center;
  199. justify-content: center;
  200. margin-right: 14px;
  201. flex-shrink: 0;
  202. }
  203. .self-avatar {
  204. background: var(--color-gold);
  205. }
  206. .avatar-text {
  207. font-size: 16px;
  208. font-weight: 700;
  209. color: #FFFFFF;
  210. }
  211. .member-info {
  212. flex: 1;
  213. min-width: 0;
  214. }
  215. .member-name {
  216. display: block;
  217. font-size: 15px;
  218. font-weight: 600;
  219. color: var(--color-text-primary);
  220. margin-bottom: 3px;
  221. }
  222. .member-detail {
  223. display: block;
  224. font-size: 12px;
  225. color: var(--color-text-secondary);
  226. }
  227. .member-checkbox {
  228. margin-left: 10px;
  229. flex-shrink: 0;
  230. }
  231. .checkbox-box {
  232. width: 22px;
  233. height: 22px;
  234. border-radius: 50%;
  235. border: 2px solid var(--color-border);
  236. display: flex;
  237. align-items: center;
  238. justify-content: center;
  239. transition: all 0.2s;
  240. }
  241. .checkbox-box.checked {
  242. background: var(--color-gold);
  243. border-color: var(--color-gold);
  244. }
  245. .checkbox-icon {
  246. color: #FFFFFF;
  247. font-size: 12px;
  248. font-weight: 700;
  249. }
  250. .member-checked {
  251. margin-left: 10px;
  252. }
  253. .check-icon {
  254. font-size: 18px;
  255. color: var(--color-gold);
  256. font-weight: 700;
  257. }
  258. /* Loading / Empty */
  259. .loading-hint, .empty-hint {
  260. text-align: center;
  261. padding: 30px 0;
  262. font-size: 14px;
  263. color: var(--color-text-secondary);
  264. }
  265. .link-text {
  266. color: var(--color-brand);
  267. font-weight: 600;
  268. text-decoration: underline;
  269. }
  270. /* Question input */
  271. .input-wrap {
  272. background: var(--color-bg-card);
  273. border-radius: 12px;
  274. padding: 14px;
  275. border: 1px solid var(--color-border);
  276. }
  277. .question-input {
  278. width: 100%;
  279. min-height: 100px;
  280. font-size: 15px;
  281. color: var(--color-text-primary);
  282. line-height: 1.6;
  283. background: transparent;
  284. }
  285. .input-placeholder {
  286. color: var(--color-text-secondary);
  287. font-size: 14px;
  288. }
  289. .char-count {
  290. display: block;
  291. text-align: right;
  292. font-size: 12px;
  293. color: var(--color-text-secondary);
  294. margin-top: 4px;
  295. padding-right: 4px;
  296. }
  297. /* Submit */
  298. .submit-bar {
  299. position: sticky;
  300. bottom: 0;
  301. padding: 12px 0 24px;
  302. background: var(--color-bg);
  303. }
  304. .btn-submit {
  305. width: 100%;
  306. height: 50px;
  307. background: linear-gradient(135deg, $brand-color, darken($brand-color, 4%));
  308. border-radius: 14px;
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. }
  313. .btn-submit:active {
  314. transform: scale(0.97);
  315. opacity: 0.9;
  316. }
  317. .btn-submit.disabled {
  318. opacity: 0.5;
  319. pointer-events: none;
  320. }
  321. .btn-submit-text {
  322. color: #FFFFFF;
  323. font-size: 17px;
  324. font-weight: 700;
  325. }
  326. </style>