index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  4. <el-form-item label="企业名称" prop="companyName">
  5. <el-input
  6. v-model="queryParams.companyName"
  7. placeholder="请输入企业名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. plain
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['system:repo:add']"
  26. >新增
  27. </el-button>
  28. </el-col>
  29. </el-row>
  30. <el-table
  31. v-if="refreshTable"
  32. v-loading="loading"
  33. :data="companyList"
  34. row-key="companyId"
  35. >
  36. <el-table-column type="index" label="ID" align="center" :show-overflow-tooltip="true" width="80"
  37. ></el-table-column>
  38. <el-table-column prop="companyName" label="名称" align="center" :show-overflow-tooltip="true" width="160"
  39. ></el-table-column>
  40. <el-table-column prop="updateBy" label="更新人" align="center" :show-overflow-tooltip="true" width="160"
  41. ></el-table-column>
  42. <el-table-column prop="updateTime" label="更新时间" align="center" :show-overflow-tooltip="true" width="160">
  43. <template slot-scope="scope">
  44. <span>{{ parseTime(scope.row.updateTime) }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="remark" label="备注" align="center" :show-overflow-tooltip="true" width="500"
  48. ></el-table-column>
  49. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  50. <template slot-scope="scope">
  51. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleConfig(scope.row)">配置</el-button>
  52. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDel(scope.row)">删除</el-button>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <pagination
  57. v-show="total>0"
  58. :total="total"
  59. :page.sync="queryParams.pageNum"
  60. :limit.sync="queryParams.pageSize"
  61. @pagination="getList"
  62. />
  63. <!-- 添加或修改菜单对话框 -->
  64. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  65. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  66. <el-row>
  67. <el-col :span="24">
  68. <el-form-item label="企业名称" prop="companyName">
  69. <el-input v-model="form.companyName" placeholder="请输入企业名称"/>
  70. </el-form-item>
  71. </el-col>
  72. </el-row>
  73. <el-row>
  74. <el-col :span="24">
  75. <el-form-item label="备注" prop="remark">
  76. <el-input v-model="form.remark" placeholder="可输入备注"/>
  77. </el-form-item>
  78. </el-col>
  79. </el-row>
  80. <el-row>
  81. <el-col :span="24">
  82. <el-divider>配置模板</el-divider>
  83. </el-col>
  84. </el-row>
  85. <el-row v-for="(category, index) in Object.keys(mapData)" :key="category">
  86. <el-col :span="24">
  87. <el-form-item :label="category">
  88. <el-select v-model="form.templateIds[index]">
  89. <el-option
  90. v-for="item in mapData[category]"
  91. :key="item.repoId"
  92. :label="item.repoName"
  93. :value="item.repoId"
  94. />
  95. </el-select>
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. </el-form>
  100. <div slot="footer" class="dialog-footer">
  101. <el-button type="primary" @click="submit">确 定</el-button>
  102. <el-button @click="cancel">取 消</el-button>
  103. </div>
  104. </el-dialog>
  105. </div>
  106. </template>
  107. <script>
  108. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  109. import FileUpload from '@/components/FileUpload'
  110. import { addCompany, delCompany, getInfo, getTemplate, listCompany, updateCompany } from '@/api/system/company'
  111. export default {
  112. name: 'Repo',
  113. dicts: [],
  114. components: { FileUpload },
  115. data() {
  116. return {
  117. // 遮罩层
  118. loading: true,
  119. // 显示搜索条件
  120. showSearch: true,
  121. // 总条数
  122. total: 0,
  123. // 角色表格数据
  124. companyList: [],
  125. // 弹出层标题
  126. title: '',
  127. // 是否显示弹出层
  128. open: false,
  129. // 判断按钮
  130. type: 0,
  131. // 重新渲染表格状态
  132. refreshTable: true,
  133. // 查询参数
  134. queryParams: {
  135. pageNum: 1,
  136. pageSize: 10,
  137. companyName: undefined
  138. },
  139. // 表单参数
  140. form: {},
  141. // 企业配置
  142. mapData: {},
  143. // 表单校验
  144. rules: {
  145. companyName: [
  146. { required: true, message: '企业名称不能为空', trigger: 'blur' }
  147. ]
  148. }
  149. }
  150. },
  151. created() {
  152. this.getList()
  153. },
  154. methods: {
  155. /** 查询菜单列表 */
  156. getList() {
  157. this.loading = true
  158. listCompany(this.queryParams).then(response => {
  159. this.companyList = response.data.rows
  160. this.total = response.data.total
  161. this.loading = false
  162. })
  163. },
  164. // 取消按钮
  165. cancel() {
  166. this.open = false
  167. this.reset()
  168. },
  169. // 表单重置
  170. reset() {
  171. this.form = {
  172. id: undefined,
  173. companyId: undefined,
  174. companyName: undefined,
  175. remark: undefined,
  176. templateIds: []
  177. }
  178. this.resetForm('form')
  179. },
  180. /** 搜索按钮操作 */
  181. handleQuery() {
  182. this.getList()
  183. },
  184. /** 重置按钮操作 */
  185. resetQuery() {
  186. this.resetForm('queryForm')
  187. this.handleQuery()
  188. },
  189. /** 新增按钮操作 */
  190. handleAdd() {
  191. this.reset()
  192. this.open = true
  193. this.title = '添加菜单'
  194. this.type = 0
  195. },
  196. /** 删除按钮操作 */
  197. handleDel(row) {
  198. this.$modal.confirm('是否确认删除:' + row.repoName).then(function() {
  199. return delCompany(row.id)
  200. }).then(() => {
  201. this.getList()
  202. this.$modal.msgSuccess('删除成功')
  203. }).catch(() => {
  204. })
  205. },
  206. /** 提交按钮 */
  207. submit: function() {
  208. this.$refs['form'].validate(valid => {
  209. if (valid) {
  210. if (this.type === 0) {
  211. addCompany(this.form).then(response => {
  212. this.$message('新增成功')
  213. this.open = false
  214. this.getList()
  215. })
  216. } else if (this.type === 1) {
  217. updateCompany(this.form).then(response => {
  218. this.$message('修改成功')
  219. this.open = false
  220. this.getList()
  221. })
  222. }
  223. }
  224. })
  225. },
  226. /** 企业配置 */
  227. handleConfig(row) {
  228. this.reset()
  229. getTemplate().then(response => {
  230. this.mapData = response.data
  231. })
  232. getInfo(row.id).then(response => {
  233. this.form = response.data
  234. const categoriesLength = Object.keys(this.mapData).length;
  235. if (this.form.templateIds === null || this.form.templateIds.length === 0) {
  236. this.form.templateIds = Array(categoriesLength).fill(0);
  237. } else if (this.form.templateIds.length < categoriesLength) {
  238. const diff = categoriesLength - this.form.templateIds.length;
  239. this.form.templateIds = this.form.templateIds.concat(Array(diff).fill(0));
  240. }
  241. this.form.templateIds.forEach((item, index) => {
  242. if (item === 0) {
  243. this.form.templateIds[index] = undefined
  244. }
  245. })
  246. })
  247. this.open = true
  248. this.title = '企业配置'
  249. this.type = 1
  250. },
  251. }
  252. }
  253. </script>