BaziConfigs.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="bazi-configs admin-page">
  3. <el-card>
  4. <div slot="header" class="admin-page-header">
  5. <span class="admin-page-title">八字配置管理</span>
  6. <div class="flex items-center gap-sm">
  7. <el-input v-model="keyword" placeholder="搜索八字..." prefix-icon="el-icon-search" clearable @keyup.enter.native="handleSearch" @clear="handleSearch" />
  8. <el-button type="primary" size="small" @click="handleCreate">+ 添加配置</el-button>
  9. </div>
  10. </div>
  11. <div class="adm-table-wrap">
  12. <el-table :data="filteredData" stripe height="100%"
  13. <el-table-column prop="id" label="ID" width="80">
  14. <template slot="header">
  15. <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>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="stemOrBranch" label="天干/地支" width="100">
  19. <template slot="header">
  20. <span class="sort-header" @click.stop="onSortClick('stemOrBranch', $event)">天干/地支<span v-if="sortIndex('stemOrBranch') !== null" class="sort-index" :class="sortClass('stemOrBranch') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('stemOrBranch') }}</span>{{ sortIcon('stemOrBranch') }}</span>
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="type" label="类型" width="80">
  24. <template slot="header">
  25. <span class="sort-header" @click.stop="onSortClick('type', $event)">类型<span v-if="sortIndex('type') !== null" class="sort-index" :class="sortClass('type') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('type') }}</span>{{ sortIcon('type') }}</span>
  26. </template>
  27. <template slot-scope="scope">
  28. <el-tag :type="scope.row.type === 'stem' ? 'primary' : 'success'" size="mini">
  29. {{ scope.row.type === 'stem' ? '天干' : '地支' }}
  30. </el-tag>
  31. </template>
  32. </el-table-column>
  33. <el-table-column prop="element" label="五行">
  34. <template slot="header">
  35. <span class="sort-header" @click.stop="onSortClick('element', $event)">五行<span v-if="sortIndex('element') !== null" class="sort-index" :class="sortClass('element') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('element') }}</span>{{ sortIcon('element') }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="yinYang" label="阴阳">
  39. <template slot="header">
  40. <span class="sort-header" @click.stop="onSortClick('yinYang', $event)">阴阳<span v-if="sortIndex('yinYang') !== null" class="sort-index" :class="sortClass('yinYang') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('yinYang') }}</span>{{ sortIcon('yinYang') }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="mindBase" label="心基础分" width="100">
  44. <template slot="header">
  45. <span class="sort-header" @click.stop="onSortClick('mindBase', $event)">心基础分<span v-if="sortIndex('mindBase') !== null" class="sort-index" :class="sortClass('mindBase') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('mindBase') }}</span>{{ sortIcon('mindBase') }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="wisdomBase" label="智基础分" width="100">
  49. <template slot="header">
  50. <span class="sort-header" @click.stop="onSortClick('wisdomBase', $event)">智基础分<span v-if="sortIndex('wisdomBase') !== null" class="sort-index" :class="sortClass('wisdomBase') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('wisdomBase') }}</span>{{ sortIcon('wisdomBase') }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="操作" width="200" fixed="right">
  54. <template slot-scope="{ row }">
  55. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  56. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  57. <el-button size="mini">
  58. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  59. </el-button>
  60. <el-dropdown-menu slot="dropdown">
  61. <el-dropdown-item command="delete" icon="el-icon-delete">删除</el-dropdown-item>
  62. </el-dropdown-menu>
  63. </el-dropdown>
  64. </template>
  65. </el-table-column>
  66. </el-card>
  67. <el-dialog :visible.sync="dialogVisible" :title="isEdit ? '编辑八字配置' : '添加八字配置'" width="500px">
  68. <el-form :model="form" label-width="100px">
  69. <el-form-item label="天干/地支">
  70. <el-input v-model="form.stemOrBranch" placeholder="如: 甲"></el-input>
  71. </el-form-item>
  72. <el-form-item label="类型">
  73. <el-select v-model="form.type" placeholder="选择类型">
  74. <el-option label="天干" value="stem"></el-option>
  75. <el-option label="地支" value="branch"></el-option>
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item label="五行">
  79. <el-select v-model="form.element" placeholder="选择五行">
  80. <el-option label="金" value="金"></el-option>
  81. <el-option label="木" value="木"></el-option>
  82. <el-option label="水" value="水"></el-option>
  83. <el-option label="火" value="火"></el-option>
  84. <el-option label="土" value="土"></el-option>
  85. </el-select>
  86. </el-form-item>
  87. <el-form-item label="阴阳">
  88. <el-select v-model="form.yinYang" placeholder="选择阴阳">
  89. <el-option label="阳" value="yang"></el-option>
  90. <el-option label="阴" value="yin"></el-option>
  91. </el-select>
  92. </el-form-item>
  93. <el-form-item label="心基础分">
  94. <el-input-number v-model="form.mindBase" :min="0" :max="100" :precision="2" style="width:150px"></el-input-number>
  95. </el-form-item>
  96. <el-form-item label="智基础分">
  97. <el-input-number v-model="form.wisdomBase" :min="0" :max="100" :precision="2" style="width:150px"></el-input-number>
  98. </el-form-item>
  99. <el-form-item label="身修正系数">
  100. <el-input-number v-model="form.bodyModifier" :min="0" :max="2" :precision="2" :step="0.05" style="width:150px"></el-input-number>
  101. </el-form-item>
  102. <el-form-item label="行修正系数">
  103. <el-input-number v-model="form.actionModifier" :min="0" :max="2" :precision="2" :step="0.05" style="width:150px"></el-input-number>
  104. </el-form-item>
  105. <el-form-item label="富修正系数">
  106. <el-input-number v-model="form.wealthModifier" :min="0" :max="2" :precision="2" :step="0.05" style="width:150px"></el-input-number>
  107. </el-form-item>
  108. </el-form>
  109. <div slot="footer">
  110. <el-button @click="dialogVisible = false">取消</el-button>
  111. <el-button type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
  112. </div>
  113. </el-dialog>
  114. <el-dialog title="操作成功" :visible.sync="successDialogVisible" width="400px" :close-on-click-modal="false">
  115. <div style="text-align:center;padding:10px 0">
  116. <i class="el-icon-success" style="color:#67C23A;font-size:32px"></i>
  117. <p style="margin:12px 0 0;font-size:16px;color:#303133">保存成功</p>
  118. </div>
  119. <div slot="footer">
  120. <el-button type="primary" @click="handleContinue">继续添加</el-button>
  121. <el-button @click="handleClose">关闭</el-button>
  122. </div>
  123. </el-dialog>
  124. </div>
  125. </div></template>
  126. <script>
  127. import SortMixin from '@/mixins/SortMixin'
  128. import { listBaziConfigs, createBaziConfig, updateBaziConfig, deleteBaziConfig } from '@/api/admin'
  129. export default {
  130. mixins: [SortMixin],
  131. name: 'BaziConfigs',
  132. data() {
  133. return {
  134. submitting: false,
  135. configs: [],
  136. keyword: '',
  137. dialogVisible: false,
  138. successDialogVisible: false,
  139. isEdit: false,
  140. form: this.getEmptyForm(),
  141. sortableColumns: { id: 'ID', stemOrBranch: '天干/地支', element: '五行', yinYang: '阴阳', mindBase: '心基础分', wisdomBase: '智基础分' }
  142. }
  143. },
  144. created() {
  145. this.loadData()
  146. },
  147. computed: {
  148. tableHeight() {
  149. return window.innerHeight - 300
  150. },
  151. filteredData() {
  152. if (!this.keyword) return this.configs
  153. const kw = this.keyword.toLowerCase()
  154. return this.configs.filter(item =>
  155. [item.stemOrBranch, item.element, item.yinYang].some(v => (v||'').toLowerCase().includes(kw))
  156. )
  157. }
  158. },
  159. methods: {
  160. getEmptyForm() {
  161. return {
  162. id: null,
  163. stemOrBranch: '',
  164. type: 'stem',
  165. element: '',
  166. yinYang: 'yang',
  167. mindBase: 60,
  168. wisdomBase: 60,
  169. bodyModifier: 1.00,
  170. actionModifier: 1.00,
  171. wealthModifier: 1.00
  172. }
  173. },
  174. async loadData() {
  175. try {
  176. const params = {}
  177. if (this.sortState.length > 0) params.sort = this.sortState
  178. const res = await listBaziConfigs(params)
  179. if (res.data) this.configs = res.data
  180. } catch (e) {
  181. console.error(e)
  182. }
  183. },
  184. loadList() { this.loadData() },
  185. handleSearch() {
  186. },
  187. handleCreate() {
  188. this.isEdit = false
  189. this.form = this.getEmptyForm()
  190. this.dialogVisible = true
  191. },
  192. handleEdit(row) {
  193. this.isEdit = true
  194. this.form = { ...row }
  195. this.dialogVisible = true
  196. },
  197. async handleDelete(row) {
  198. try {
  199. await this.$confirm('确定删除该配置吗?', '提示', { type: 'warning' })
  200. await deleteBaziConfig(row.id)
  201. this.$message.success('删除成功')
  202. this.loadData()
  203. } catch (e) {
  204. if (e !== 'cancel') this.$message.error('删除失败')
  205. }
  206. },
  207. async handleSubmit() {
  208. try {
  209. if (this.isEdit) {
  210. await updateBaziConfig(this.form)
  211. } else {
  212. await createBaziConfig(this.form)
  213. }
  214. this.$message.success('保存成功')
  215. this.successDialogVisible = true
  216. } catch (e) {
  217. this.$message.error('保存失败')
  218. }
  219. },
  220. handleActionCmd(row, cmd) {
  221. switch (cmd) {
  222. case 'delete':
  223. this.handleDelete(row)
  224. break
  225. }
  226. },
  227. handleContinue() {
  228. this.successDialogVisible = false
  229. this.isEdit = false
  230. this.form = this.getEmptyForm()
  231. this.dialogVisible = true
  232. },
  233. handleClose() {
  234. this.successDialogVisible = false
  235. this.dialogVisible = false
  236. this.loadData()
  237. }
  238. }
  239. }
  240. </script>
  241. <style scoped>
  242. .sort-header {
  243. cursor: pointer;
  244. user-select: none;
  245. font-weight: 500;
  246. font-size: 12px;
  247. }
  248. .sort-header:hover {
  249. color: #409eff;
  250. }
  251. .sort-tag {
  252. margin-left: 8px;
  253. cursor: pointer;
  254. white-space: nowrap;
  255. }
  256. </style>