index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <route lang="yaml">
  2. meta:
  3. enabled: false
  4. </route>
  5. <script lang="ts" setup name="BizObjectAttrList">
  6. import type { FormInstance, FormRules } from 'element-plus'
  7. import { ElMessage } from 'element-plus'
  8. import { dataType } from '@/utils/tool'
  9. import {
  10. createObjectAttr,
  11. deleteObjectAttrById,
  12. getObjectAttrListById,
  13. updateObjectAttr,
  14. } from '@/api/biz/bizObjectAttrApi'
  15. const props = withDefaults(defineProps<{
  16. bizId: number
  17. objectId: number
  18. }>(), {
  19. bizId: 0,
  20. objectId: 0,
  21. })
  22. const bizId = props.bizId
  23. const objectId = props.objectId
  24. interface ObjectAttr {
  25. bizId: number
  26. objectId: number
  27. attrId: number
  28. attrTitle: string
  29. attrCode: string
  30. mappingCode: string
  31. attrType: number
  32. attrLength: number
  33. attrDecimals: number
  34. isNotNull: number
  35. comment: string
  36. sortNo: number
  37. isEdit: boolean
  38. }
  39. // 数据
  40. const state = reactive({
  41. title: '',
  42. dialogVisible: false,
  43. loading: false,
  44. search: {
  45. keywords: '',
  46. },
  47. conditions: {
  48. bizId,
  49. objectId,
  50. },
  51. attrs: [] as ObjectAttr[],
  52. actionType: 1,
  53. })
  54. const formRef = ref<FormInstance>()
  55. const formRules = reactive<FormRules>({
  56. objectTitle: [
  57. { required: true, message: '请输入对象标题', trigger: 'blur' },
  58. ],
  59. objectType: [
  60. { required: true, message: '请输入对象类型', trigger: 'blur' },
  61. ],
  62. objectCode: [
  63. { required: true, message: '请输入对像代码', trigger: 'blur' },
  64. ],
  65. comment: [
  66. { required: false, message: '请输入简要描述', trigger: 'blur' },
  67. ],
  68. })
  69. // 查询数据
  70. const getData = async () => {
  71. state.loading = true
  72. const { data } = await getObjectAttrListById(bizId, objectId)
  73. state.loading = false
  74. state.attrs = data
  75. data.forEach((attr: ObjectAttr) => {
  76. attr.isEdit = false
  77. })
  78. }
  79. const attrsTableRef = ref()
  80. const attrsTableKey = ref(0)
  81. function onAttrAdd() {
  82. state.attrs.push({
  83. bizId,
  84. objectId,
  85. attrId: 0,
  86. attrTitle: '', // 名称
  87. attrCode: '', // 代码
  88. mappingCode: '',
  89. attrType: 0, // 类型
  90. attrLength: 0, // 长度
  91. attrDecimals: 0, // 小数位数
  92. isNotNull: 0, // 是否为空
  93. comment: '', // 注释
  94. sortNo: 0,
  95. isEdit: true,
  96. })
  97. state.actionType = 1
  98. }
  99. function onAttrEdit(row: any) {
  100. row.isEdit = true
  101. state.actionType = 2
  102. }
  103. async function onAttrDelete(row: any) {
  104. const { bizId, objectId } = state.conditions
  105. const attrId = row.attrId
  106. const { msg } = await deleteObjectAttrById(bizId, objectId, attrId)
  107. ElMessage.success(msg)
  108. await getData()
  109. }
  110. function onAttrCancel(row: any, index: number) {
  111. row.isEdit = false
  112. if (state.actionType === 1) {
  113. state.attrs.splice(index, 1)
  114. }
  115. state.actionType = 0
  116. }
  117. async function onAttrSave(row: any) {
  118. row.isEdit = false
  119. if (state.actionType === 1) {
  120. const { msg } = await createObjectAttr(row)
  121. ElMessage.success(msg)
  122. state.dialogVisible = false
  123. }
  124. else {
  125. const { msg } = await updateObjectAttr(row)
  126. ElMessage.success(msg)
  127. state.dialogVisible = false
  128. }
  129. await getData()
  130. }
  131. onMounted(() => {
  132. getData()
  133. nextTick(() => {
  134. })
  135. })
  136. </script>
  137. <template>
  138. <div class="absolute-container">
  139. <div class="container">
  140. <tool-bar>
  141. <template #left>
  142. <h4>对象属性</h4>
  143. </template>
  144. <template #right>
  145. <el-input v-model="state.search.keywords" placeholder="请输入关键词筛选" clearable style="width: 200px;" />
  146. <el-button style="margin-left:10px" @click="getData">
  147. <template #icon>
  148. <el-icon>
  149. <svg-icon name="i-ep:search" />
  150. </el-icon>
  151. </template>
  152. </el-button>
  153. <el-button type="default" @click="onAttrAdd">
  154. <template #icon>
  155. <el-icon>
  156. <svg-icon name="i-ep:plus" />
  157. </el-icon>
  158. </template>
  159. </el-button>
  160. </template>
  161. </tool-bar>
  162. <el-table ref="attrsTableRef" :key="attrsTableKey" :data="state.attrs" class="list-table" size="small" border stripe highlight-current-row>
  163. <el-table-column type="index" label="序号" header-align="center" align="center" width="60" />
  164. <el-table-column label="名称" header-align="center" align="center" width="150">
  165. <template #default="scope">
  166. <el-input v-if="scope.row.isEdit" v-model="scope.row.attrTitle" size="small" />
  167. <span v-else>{{ scope.row.attrTitle }}</span>
  168. </template>
  169. </el-table-column>
  170. <el-table-column label="代码" header-align="center" align="center" width="120">
  171. <template #default="scope">
  172. <el-input v-if="scope.row.isEdit" v-model="scope.row.attrCode" size="small" />
  173. <span v-else>{{ scope.row.attrCode }}</span>
  174. </template>
  175. </el-table-column>
  176. <el-table-column label="映射代码" header-align="center" align="center" width="120">
  177. <template #default="scope">
  178. <el-input v-if="scope.row.isEdit" v-model="scope.row.mappingCode" size="small" />
  179. <span v-else>{{ scope.row.mappingCode }}</span>
  180. </template>
  181. </el-table-column>
  182. <el-table-column label="类型" header-align="center" align="center" width="120">
  183. <template #default="scope">
  184. <data-type-selector v-if="scope.row.isEdit" v-model="scope.row.attrType" />
  185. <span v-else>{{ dataType(scope.row.attrType) }}</span>
  186. </template>
  187. </el-table-column>
  188. <el-table-column label="长度" header-align="center" align="center" width="120">
  189. <template #default="scope">
  190. <el-input-number
  191. v-if="scope.row.isEdit"
  192. v-model="scope.row.attrLength" style="width:90px"
  193. :min="0"
  194. controls-position="right"
  195. size="small"
  196. />
  197. <span v-else>{{ scope.row.attrLength }}</span>
  198. </template>
  199. </el-table-column>
  200. <el-table-column label="小数位数" header-align="center" align="center" width="120">
  201. <template #default="scope">
  202. <el-input-number
  203. v-if="scope.row.isEdit"
  204. v-model="scope.row.attrDecimals" style="width:90px"
  205. :min="0"
  206. controls-position="right"
  207. size="small"
  208. />
  209. <span v-else>{{ scope.row.attrDecimals }}</span>
  210. </template>
  211. </el-table-column>
  212. <el-table-column label="是否为空" header-align="center" align="center" width="90">
  213. <template #default="scope">
  214. <el-checkbox
  215. v-if="scope.row.isEdit"
  216. v-model="scope.row.isNotNull"
  217. :true-label="1"
  218. :false-label="0"
  219. >
  220. {{ scope.row.isNotNull === 1 ? '是' : '否' }}
  221. </el-checkbox>
  222. <span v-else>{{ scope.row.isNotNull === 1 ? '是' : '否' }}</span>
  223. </template>
  224. </el-table-column>
  225. <el-table-column label="注释">
  226. <template #default="scope">
  227. <el-input v-if="scope.row.isEdit" v-model="scope.row.comment" size="small" />
  228. <span v-else>{{ scope.row.comment }}</span>
  229. </template>
  230. </el-table-column>
  231. <el-table-column header-align="center" align="center" width="70">
  232. <template #header>
  233. 排序
  234. </template>
  235. <template #default>
  236. <el-tag type="info" class="sortable">
  237. <el-icon>
  238. <svg-icon name="i-ep:d-caret" />
  239. </el-icon>
  240. </el-tag>
  241. </template>
  242. </el-table-column>
  243. <el-table-column label="操作" width="140" align="center">
  244. <template #default="scope">
  245. <template v-if="scope.row.isEdit">
  246. <div>
  247. <el-button type="primary" plain size="small" @click="onAttrSave(scope.row)">
  248. 保存
  249. </el-button>
  250. <el-button type="primary" plain size="small" @click="onAttrCancel(scope.row, scope.$index)">
  251. 取消
  252. </el-button>
  253. </div>
  254. </template>
  255. <template v-else>
  256. <div>
  257. <el-button type="primary" plain size="small" @click="onAttrEdit(scope.row)">
  258. 编辑
  259. </el-button>
  260. <el-popconfirm title="是否要删除此行?" style="margin-left: 10px;" @confirm="onAttrDelete(scope.row)">
  261. <template #reference>
  262. <el-button type="danger" plain size="small">
  263. 删除
  264. </el-button>
  265. </template>
  266. </el-popconfirm>
  267. </div>
  268. </template>
  269. </template>
  270. </el-table-column>
  271. </el-table>
  272. </div>
  273. </div>
  274. </template>
  275. <style lang="scss" scoped>
  276. .page-main {
  277. :deep(.el-table) {
  278. height: 100%;
  279. .el-table__row {
  280. .index {
  281. display: inline-block;
  282. }
  283. .delete {
  284. display: none;
  285. }
  286. &:hover {
  287. .index {
  288. display: none;
  289. }
  290. .delete {
  291. display: inline-block;
  292. }
  293. }
  294. }
  295. }
  296. h5{
  297. padding: 0;
  298. margin: 0;
  299. }
  300. }
  301. </style>