data-source-config.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="data-source-config admin-page">
  3. <el-card>
  4. <PageHeader slot="header" title="健康数据源配置">
  5. <el-input v-model="keyword" placeholder="搜索数据源..." prefix-icon="el-icon-search" style="width:200px" clearable @keyup.enter.native="handleSearch" @clear="handleSearch" />
  6. <div class="admin-page-actions">
  7. <el-button type="primary" size="small" @click="handleCreate">+ 添加数据源</el-button>
  8. </div>
  9. </PageHeader>
  10. <div class="adm-table-wrap">
  11. <el-table height="100%" :data="records" stripe v-loading="loading">
  12. <el-table-column prop="id" label="ID" width="60">
  13. <template slot="header">
  14. <span class="sort-header" @click.stop="onSortClick('id', $event)">ID<span v-if="sortIndex('id') !== null" class="sort-index" :class="sortClass('id') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('id') }}</span>{{ sortIcon('id') }}</span>
  15. </template>
  16. </el-table-column>
  17. <el-table-column prop="memberId" label="成员ID" width="80">
  18. <template slot="header">
  19. <span class="sort-header" @click.stop="onSortClick('memberId', $event)">成员ID<span v-if="sortIndex('memberId') !== null" class="sort-index" :class="sortClass('memberId') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('memberId') }}</span>{{ sortIcon('memberId') }}</span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column prop="sourceType" label="类型" width="100">
  23. <template slot="header">
  24. <span class="sort-header" @click.stop="onSortClick('sourceType', $event)">类型<span v-if="sortIndex('sourceType') !== null" class="sort-index" :class="sortClass('sourceType') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('sourceType') }}</span>{{ sortIcon('sourceType') }}</span>
  25. </template>
  26. <template slot-scope="scope">
  27. <el-tag size="mini">{{ scope.row.sourceType }}</el-tag>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="dimensionCodes" label="维度" width="150" show-overflow-tooltip>
  31. <template slot="header">
  32. <span class="sort-header" @click.stop="onSortClick('dimensionCodes', $event)">维度<span v-if="sortIndex('dimensionCodes') !== null" class="sort-index" :class="sortClass('dimensionCodes') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('dimensionCodes') }}</span>{{ sortIcon('dimensionCodes') }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="confidence" label="置信度" width="80">
  36. <template slot="header">
  37. <span class="sort-header" @click.stop="onSortClick('confidence', $event)">置信度<span v-if="sortIndex('confidence') !== null" class="sort-index" :class="sortClass('confidence') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('confidence') }}</span>{{ sortIcon('confidence') }}</span>
  38. </template>
  39. <template slot-scope="scope">{{ scope.row.confidence }}</template>
  40. </el-table-column>
  41. <el-table-column prop="fileUrl" label="文件URL" min-width="200" show-overflow-tooltip>
  42. <template slot="header">
  43. <span class="sort-header" @click.stop="onSortClick('fileUrl', $event)">文件URL<span v-if="sortIndex('fileUrl') !== null" class="sort-index" :class="sortClass('fileUrl') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('fileUrl') }}</span>{{ sortIcon('fileUrl') }}</span>
  44. </template>
  45. <template slot-scope="scope">
  46. <a v-if="scope.row.fileUrl" :href="scope.row.fileUrl" target="_blank" style="color:#409EFF;font-size:12px;">查看文件</a>
  47. <span v-else style="color:#999">-</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="createdAt" label="创建时间" width="160">
  51. <template slot-scope="scope">{{ formatDate(scope.row.createdAt) }}</template>
  52. <template slot="header">
  53. <span class="sort-header" @click.stop="onSortClick('createdAt', $event)">创建时间<span v-if="sortIndex('createdAt') !== null" class="sort-index" :class="sortClass('createdAt') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('createdAt') }}</span>{{ sortIcon('createdAt') }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="操作" width="200" fixed="right">
  57. <template slot-scope="{ row }">
  58. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  59. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  60. <el-button size="mini">
  61. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  62. </el-button>
  63. <el-dropdown-menu slot="dropdown">
  64. <el-dropdown-item command="delete" icon="el-icon-delete">删除</el-dropdown-item>
  65. </el-dropdown-menu>
  66. </el-dropdown>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. </div>
  71. <el-pagination
  72. v-if="total > 0"
  73. class="pagination-wrap"
  74. style="margin-top:16px;text-align:right"
  75. :page.sync="page"
  76. :limit.sync="size"
  77. @current-change="fetchRecords"
  78. layout="total, prev, pager, next"
  79. />
  80. </el-card>
  81. <el-dialog :visible.sync="dialogVisible" :title="isEdit ? '编辑数据源' : '添加数据源'" width="550px">
  82. <el-form :model="form" label-width="100px">
  83. <el-form-item label="成员ID" required>
  84. <el-input-number v-model="form.memberId" :min="1" style="width:100%"/>
  85. </el-form-item>
  86. <el-form-item label="来源类型" required>
  87. <el-select v-model="form.sourceType" placeholder="选择类型" style="width:100%">
  88. <el-option label="REPORT" value="REPORT"></el-option>
  89. <el-option label="PHOTO" value="PHOTO"></el-option>
  90. <el-option label="VOICE" value="VOICE"></el-option>
  91. <el-option label="MANUAL" value="MANUAL"></el-option>
  92. </el-select>
  93. </el-form-item>
  94. <el-form-item label="维度编码">
  95. <el-input v-model="form.dimensionCodes" placeholder="如: growth,sleep,vision"/>
  96. </el-form-item>
  97. <el-form-item label="置信度">
  98. <el-input-number v-model="form.confidence" :min="0" :max="1" :precision="2" style="width:100%"/>
  99. </el-form-item>
  100. <el-form-item label="解析结果">
  101. <el-input type="textarea" v-model="form.parsedResult" :rows="3" placeholder="JSON格式"/>
  102. </el-form-item>
  103. <el-form-item label="文件URL">
  104. <el-input v-model="form.fileUrl" placeholder="https://..."/>
  105. </el-form-item>
  106. </el-form>
  107. <div slot="footer">
  108. <el-button @click="dialogVisible = false">取消</el-button>
  109. <el-button type="primary" @click="handleSubmit" :loading="submitting">保存</el-button>
  110. </div>
  111. </el-dialog>
  112. <el-dialog title="操作成功" :visible.sync="successDialogVisible" width="400px" :close-on-click-modal="false">
  113. <div style="text-align:center;padding:10px 0">
  114. <i class="el-icon-success" style="color:#67C23A;font-size:32px"></i>
  115. <p style="margin:12px 0 0;font-size:16px;color:#303133">保存成功</p>
  116. </div>
  117. <div slot="footer">
  118. <el-button type="primary" @click="handleContinue">继续添加</el-button>
  119. <el-button @click="handleClose">关闭</el-button>
  120. </div>
  121. </el-dialog>
  122. </div>
  123. </template>
  124. <script>
  125. import SortMixin from '@/mixins/SortMixin'
  126. import ListStateMixin from '@/mixins/ListStateMixin'
  127. export default {
  128. name: 'DataSourceConfig',
  129. mixins: [SortMixin, ListStateMixin],
  130. computed: {
  131. tableHeight() {
  132. return window.innerHeight - 300
  133. }
  134. },
  135. data() {
  136. return {
  137. loading: false,
  138. submitting: false,
  139. records: [],
  140. total: 0,
  141. page: 1,
  142. size: 20,
  143. dialogVisible: false,
  144. successDialogVisible: false,
  145. isEdit: false,
  146. form: this.emptyForm(),
  147. keyword: '',
  148. sortableColumns: { id: 'ID', memberId: '成员ID', sourceType: '类型', dimensionCodes: '维度', confidence: '置信度', fileUrl: '文件URL', createdAt: '创建时间' }
  149. }
  150. },
  151. mounted() {
  152. this.fetchRecords()
  153. },
  154. methods: {
  155. loadList() {
  156. this.fetchRecords()
  157. },
  158. handleSearch() {
  159. this.page = 1
  160. this.fetchRecords()
  161. },
  162. emptyForm() {
  163. return {
  164. id: null,
  165. memberId: null,
  166. sourceType: 'MANUAL',
  167. dimensionCodes: '',
  168. parsedResult: '',
  169. fileUrl: '',
  170. confidence: null
  171. }
  172. },
  173. fetchRecords() {
  174. this.loading = true
  175. var params = { page: this.page, size: this.size, keyword: this.keyword || undefined }
  176. if (this.sortState.length > 0) params.sort = this.sortState
  177. this.$axios.post('/api/admin/dimension/data-source/list', null, { params: params })
  178. .then(res => {
  179. if (res.data.code === 200) {
  180. this.records = res.data.data.records || []
  181. this.total = res.data.data.total || 0
  182. }
  183. }).catch(() => {}).finally(() => { this.loading = false })
  184. },
  185. handleCreate() {
  186. this.form = this.emptyForm()
  187. this.isEdit = false
  188. this.dialogVisible = true
  189. },
  190. handleEdit(row) {
  191. this.form = { ...row }
  192. this.isEdit = true
  193. this.dialogVisible = true
  194. },
  195. handleSubmit() {
  196. this.submitting = true
  197. this.$axios.post('/api/admin/dimension/data-source/save', this.form).then(res => {
  198. if (res.data.code === 200) {
  199. this.$message.success('保存成功')
  200. this.successDialogVisible = true
  201. } else {
  202. this.$message.error(res.data.message || '保存失败')
  203. }
  204. }).catch(() => { this.$message.error('保存失败') }).finally(() => { this.submitting = false })
  205. },
  206. handleDelete(row) {
  207. this.$confirm('确认删除此数据源?', '提示', { type: 'warning' }).then(() => {
  208. this.$axios.post('/api/admin/dimension/data-source/delete', row.id).then(res => {
  209. if (res.data.code === 200) {
  210. this.fetchRecords()
  211. this.$message.success('删除成功')
  212. } else {
  213. this.$message.error(res.data.message || '删除失败')
  214. }
  215. })
  216. }).catch(() => {})
  217. },
  218. handleActionCmd(row, cmd) {
  219. switch (cmd) {
  220. case 'delete':
  221. this.handleDelete(row)
  222. break
  223. }
  224. },
  225. handleContinue() {
  226. this.successDialogVisible = false
  227. this.isEdit = false
  228. this.form = this.emptyForm()
  229. this.dialogVisible = true
  230. },
  231. handleClose() {
  232. this.successDialogVisible = false
  233. this.dialogVisible = false
  234. this.fetchRecords()
  235. }
  236. }
  237. }
  238. </script>
  239. <style scoped>
  240. .sort-header {
  241. cursor: pointer;
  242. user-select: none;
  243. font-weight: 500;
  244. font-size: 12px;
  245. }
  246. .sort-header:hover {
  247. color: #409eff;
  248. }
  249. .sort-tag {
  250. margin-left: 8px;
  251. cursor: pointer;
  252. white-space: nowrap;
  253. }
  254. </style>