data-source-config.vue 7.9 KB

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