symptom.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="category-container">
  3. <!-- 顶部搜索栏 -->
  4. <view class="search-bar">
  5. <view class="search-input">
  6. <text class="iconfont icon-search"></text>
  7. <input
  8. v-model="searchKeyword"
  9. placeholder="搜索症状"
  10. placeholder-class="search-placeholder"
  11. @confirm="handleSearch"
  12. />
  13. </view>
  14. </view>
  15. <!-- 症状分类标签 -->
  16. <view class="category-tabs">
  17. <view
  18. class="tab-item"
  19. :class="{ 'active': activeTab === tab.value }"
  20. @click="changeTab(tab)"
  21. v-for="tab in tabs"
  22. :key="tab.key"
  23. >
  24. {{ tab.label }}
  25. </view>
  26. </view>
  27. <!-- 症状列表 -->
  28. <view class="symptom-list" v-if="symptomList.length > 0">
  29. <view
  30. class="symptom-item"
  31. v-for="(symptom, index) in filteredSymptoms"
  32. :key="symptom.id"
  33. @click="viewSymptomDetail(symptom.id)"
  34. >
  35. <view class="symptom-content">
  36. <text class="symptom-name">{{ symptom.name }}</text>
  37. <text class="symptom-desc">{{ symptom.description }}</text>
  38. </view>
  39. <text class="iconfont icon-arrow-right"></text>
  40. </view>
  41. </view>
  42. <view v-else class="no-data">
  43. <image src="/static/images/no-data.png" mode="aspectFit"></image>
  44. <text>暂无相关症状数据</text>
  45. </view>
  46. <!-- 加载状态 -->
  47. <view class="loading-state" v-if="isLoading">
  48. <text class="iconfont icon-loading"></text>
  49. <text>加载中...</text>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. searchKeyword: '',
  58. activeTab: 'common', // 默认分类
  59. symptomList: [], // 症状列表
  60. tabs: [ // 分类标签配置
  61. { key: 'common', label: '常见症状', value: 'common' },
  62. { key: 'body', label: '部位分类', value: 'body' },
  63. { key: 'disease', label: '疾病相关', value: 'disease' }
  64. ],
  65. isLoading: false, // 加载状态
  66. errorMsg: '' // 错误信息
  67. };
  68. },
  69. computed: {
  70. filteredSymptoms() {
  71. // 根据搜索词和分类过滤数据
  72. return this.symptomList.filter(symptom => {
  73. const matchSearch = symptom.name.includes(this.searchKeyword) ||
  74. symptom.description.includes(this.searchKeyword);
  75. const matchCategory = this.activeTab === 'all' ||
  76. symptom.category === this.activeTab;
  77. return matchSearch && matchCategory;
  78. });
  79. }
  80. },
  81. methods: {
  82. // 切换分类标签
  83. changeTab(tab) {
  84. if (this.activeTab === tab.value) return;
  85. this.activeTab = tab.value;
  86. this.fetchSymptoms(); // 切换分类时重新获取数据
  87. },
  88. // 搜索症状
  89. handleSearch() {
  90. this.fetchSymptoms();
  91. },
  92. // 使用 uni.request 获取症状数据
  93. fetchSymptoms() {
  94. this.isLoading = true;
  95. this.errorMsg = '';
  96. uni.request({
  97. url: 'http://localhost:8080/symptoms/findAll',
  98. method: 'POST',
  99. data: {
  100. category: this.activeTab,
  101. keyword: this.searchKeyword
  102. },
  103. success: (res) => {
  104. if (res.statusCode === 200) {
  105. this.symptomList = res.data.data || [];
  106. } else {
  107. this.errorMsg = '数据获取失败';
  108. uni.showToast({
  109. title: '数据获取失败',
  110. icon: 'none',
  111. duration: 2000
  112. });
  113. }
  114. },
  115. fail: (err) => {
  116. console.error('请求失败:', err);
  117. this.errorMsg = '网络请求失败,请检查网络';
  118. uni.showToast({
  119. title: '网络请求失败',
  120. icon: 'none',
  121. duration: 2000
  122. });
  123. },
  124. complete: () => {
  125. this.isLoading = false;
  126. }
  127. });
  128. },
  129. // 跳转详情页
  130. viewSymptomDetail(id) {
  131. uni.request({
  132. url: 'http://localhost:8080/symptoms/selectById/${id}',
  133. method: 'GET',
  134. data: {
  135. id: id
  136. }
  137. });
  138. }
  139. },
  140. // 页面加载时初始化数据
  141. onLoad() {
  142. this.fetchSymptoms();
  143. },
  144. // 页面显示时重新获取数据
  145. onShow() {
  146. // 如果需要每次显示都刷新数据,可以取消下面的注释
  147. // this.fetchSymptoms();
  148. }
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. /* 基础样式 */
  153. page {
  154. background-color: #f5f7fa;
  155. font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
  156. }
  157. .category-container {
  158. padding-bottom: 100rpx;
  159. }
  160. /* 搜索栏 */
  161. .search-bar {
  162. padding: 30rpx 40rpx;
  163. background-color: #fff;
  164. .search-input {
  165. display: flex;
  166. align-items: center;
  167. height: 80rpx;
  168. background-color: #f5f5f5;
  169. border-radius: 40rpx;
  170. padding: 0 30rpx;
  171. .icon-search {
  172. color: #999;
  173. font-size: 32rpx;
  174. }
  175. input {
  176. flex: 1;
  177. margin-left: 20rpx;
  178. font-size: 28rpx;
  179. color: #333;
  180. }
  181. .search-placeholder {
  182. color: #999;
  183. }
  184. }
  185. }
  186. /* 分类标签 */
  187. .category-tabs {
  188. display: flex;
  189. background-color: #fff;
  190. padding: 0 40rpx;
  191. border-bottom: 2rpx solid #f5f5f5;
  192. .tab-item {
  193. flex: 1;
  194. text-align: center;
  195. padding: 30rpx 0;
  196. font-size: 30rpx;
  197. color: #666;
  198. position: relative;
  199. &.active {
  200. color: #4a90e2;
  201. font-weight: bold;
  202. }
  203. &.active::after {
  204. content: '';
  205. position: absolute;
  206. bottom: 0;
  207. left: 50%;
  208. transform: translateX(-50%);
  209. width: 40rpx;
  210. height: 6rpx;
  211. background-color: #4a90e2;
  212. border-radius: 3rpx;
  213. }
  214. }
  215. }
  216. /* 症状列表 */
  217. .symptom-list {
  218. background-color: #fff;
  219. .symptom-item {
  220. display: flex;
  221. align-items: center;
  222. padding: 30rpx 40rpx;
  223. border-bottom: 2rpx solid #f5f5f5;
  224. .symptom-content {
  225. flex: 1;
  226. .symptom-name {
  227. font-size: 32rpx;
  228. font-weight: bold;
  229. color: #333;
  230. }
  231. .symptom-desc {
  232. font-size: 26rpx;
  233. color: #666;
  234. margin-top: 10rpx;
  235. line-height: 1.5;
  236. max-height: 78rpx;
  237. overflow: hidden;
  238. text-overflow: ellipsis;
  239. display: -webkit-box;
  240. -webkit-line-clamp: 2;
  241. -webkit-box-orient: vertical;
  242. }
  243. }
  244. .icon-arrow-right {
  245. color: #999;
  246. font-size: 32rpx;
  247. }
  248. }
  249. }
  250. /* 无数据状态 */
  251. .no-data {
  252. display: flex;
  253. flex-direction: column;
  254. align-items: center;
  255. justify-content: center;
  256. padding: 100rpx 0;
  257. image {
  258. width: 200rpx;
  259. height: 200rpx;
  260. opacity: 0.5;
  261. }
  262. text {
  263. margin-top: 40rpx;
  264. font-size: 28rpx;
  265. color: #999;
  266. }
  267. }
  268. /* 加载状态 */
  269. .loading-state {
  270. position: fixed;
  271. top: 50%;
  272. left: 50%;
  273. transform: translate(-50%, -50%);
  274. display: flex;
  275. flex-direction: column;
  276. align-items: center;
  277. justify-content: center;
  278. background-color: rgba(0, 0, 0, 0.6);
  279. padding: 40rpx 60rpx;
  280. border-radius: 20rpx;
  281. z-index: 1000;
  282. .icon-loading {
  283. color: #fff;
  284. font-size: 60rpx;
  285. animation: rotate 1.5s linear infinite;
  286. }
  287. text {
  288. margin-top: 20rpx;
  289. font-size: 28rpx;
  290. color: #fff;
  291. }
  292. }
  293. @keyframes rotate {
  294. from {
  295. transform: rotate(0deg);
  296. }
  297. to {
  298. transform: rotate(360deg);
  299. }
  300. }
  301. /* 图标样式 */
  302. @font-face {
  303. font-family: 'iconfont';
  304. src: url('https://at.alicdn.com/t/font_1797472_r754c57n48d.ttf') format('truetype');
  305. }
  306. .iconfont {
  307. font-family: "iconfont" !important;
  308. font-size: 16px;
  309. font-style: normal;
  310. -webkit-font-smoothing: antialiased;
  311. -moz-osx-font-smoothing: grayscale;
  312. }
  313. .icon-search:before {
  314. content: "\e60d";
  315. }
  316. .icon-arrow-right:before {
  317. content: "\e60c";
  318. }
  319. .icon-loading:before {
  320. content: "\e60e";
  321. }
  322. </style>