index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="app-container post-page">
  3. <div class="post-page-min" v-if="pageType == 1">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" >
  5. <el-form-item label="关键字" prop="searchValue">
  6. <el-input
  7. v-model="queryParams.searchValue"
  8. placeholder="请输入身份编码"
  9. clearable
  10. size="small"
  11. />
  12. </el-form-item>
  13. <!--<el-form-item label="状态" prop="status">-->
  14. <!--<el-select v-model="queryParams.status" placeholder="身份状态" clearable size="small">-->
  15. <!--<el-option-->
  16. <!--v-for="dict in statusOptions"-->
  17. <!--:key="dict.dictValue"-->
  18. <!--:label="dict.dictLabel"-->
  19. <!--:value="dict.dictValue"-->
  20. <!--/>-->
  21. <!--</el-select>-->
  22. <!--</el-form-item>-->
  23. <el-form-item style="float: right;">
  24. <el-col :span="1.5" style="margin-right:20px">
  25. <p class="add-button-one-120"
  26. @click="handleAdd"
  27. v-hasPermi="['system:post:add']"
  28. ><i class="el-icon-plus"></i>新增</p>
  29. </el-col>
  30. </el-form-item>
  31. <el-form-item>
  32. <p class="inquire-button-one" @click="handleQuery">查询</p>
  33. <p class="reset-button-one" @click="resetQuery">重置</p>
  34. </el-form-item>
  35. </el-form>
  36. <el-table v-loading="loading" border :data="postList" @selection-change="handleSelectionChange">
  37. <!--<el-table-column type="selection" width="55" align="center" />-->
  38. <el-table-column label="序号" width="55" align="center" type="index"/>
  39. <el-table-column label="身份名称" align="left" prop="postName" :show-overflow-tooltip="true" width="200"/>
  40. <el-table-column label="身份编码" align="left" prop="postCode" :show-overflow-tooltip="true" width="200"/>
  41. <el-table-column label="权限组" align="left" prop="roleNameStr" :show-overflow-tooltip="true"/>
  42. <!--<el-table-column label="状态" align="left" prop="status" :formatter="statusFormat" :show-overflow-tooltip="true" width="80"/>-->
  43. <el-table-column label="创建时间" align="left" prop="createTime" width="180">
  44. <template slot-scope="scope">
  45. <span>{{ parseTime(scope.row.createTime) }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="180">
  49. <template slot-scope="scope">
  50. <div class="table-button-box">
  51. <p class="table-button-null"></p>
  52. <p class="table-button-p"
  53. @click="handleAuthUser(scope.row)"
  54. >成员维护</p>
  55. <el-dropdown @command="moreClick" v-hasPermi="['system:post:query','system:post:edit','system:post:remove']">
  56. <p class="table-button-p">更多>></p>
  57. <el-dropdown-menu slot="dropdown">
  58. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;" :command="{row:scope.row,command:1}"
  59. v-hasPermiAnd="['system:post:query','system:post:edit']">编辑</el-dropdown-item>
  60. <el-dropdown-item style="margin:0 10px;" :command="{row:scope.row,command:2}"
  61. v-hasPermi="['system:post:remove']">删除</el-dropdown-item>
  62. </el-dropdown-menu>
  63. </el-dropdown>
  64. <p class="table-button-null"></p>
  65. </div>
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. <pagination :page-sizes="[20, 30, 40, 50]"
  70. v-show="total>0"
  71. :total="total"
  72. layout="total, prev, pager, next, sizes, jumper"
  73. :page.sync="queryParams.pageNum"
  74. :limit.sync="queryParams.pageSize"
  75. @pagination="getList"
  76. />
  77. </div>
  78. <!-- 添加或修改身份对话框 -->
  79. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body
  80. :close-on-click-modal="false">
  81. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  82. <el-form-item label="身份名称" prop="postName">
  83. <el-input v-model="form.postName" placeholder="请输入身份名称" maxlength="10" />
  84. </el-form-item>
  85. <el-form-item label="身份编码" prop="postCode">
  86. <el-input v-model="form.postCode" placeholder="请输入编码名称" maxlength="20" />
  87. </el-form-item>
  88. <!--<el-form-item label="身份顺序" prop="postSort">-->
  89. <!--<el-input-number v-model="form.postSort" controls-position="right" :min="0" style="width: 380px"/>-->
  90. <!--</el-form-item>-->
  91. <el-form-item label="权限组" prop="roleIds">
  92. <el-select
  93. style="width:380px;"
  94. v-model="form.roleIds"
  95. multiple
  96. collapse-tags
  97. placeholder="请选择">
  98. <el-option
  99. v-for="item in optionselectList"
  100. :key="item.roleId"
  101. :label="item.roleName"
  102. :value="item.roleId">
  103. </el-option>
  104. </el-select>
  105. </el-form-item>
  106. <!--<el-form-item label="身份状态" prop="status">-->
  107. <!--<el-radio-group v-model="form.status">-->
  108. <!--<el-radio-->
  109. <!--v-for="dict in statusOptions"-->
  110. <!--:key="dict.dictValue"-->
  111. <!--:label="dict.dictValue"-->
  112. <!--&gt;{{dict.dictLabel}}</el-radio>-->
  113. <!--</el-radio-group>-->
  114. <!--</el-form-item>-->
  115. <!--<el-form-item label="备注" prop="remark">-->
  116. <!--<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />-->
  117. <!--</el-form-item>-->
  118. </el-form>
  119. <div slot="footer" class="dialog-footer">
  120. <el-button @click="cancel">取 消</el-button>
  121. <el-button type="primary" @click="submitForm">确 定</el-button>
  122. </div>
  123. </el-dialog>
  124. <!--分配用户-->
  125. <auth-user :postId="postId" v-if="pageType == 2"></auth-user>
  126. </div>
  127. </template>
  128. <script>
  129. import { positionByList } from "@/api/system/user";
  130. import { listPost, getPost, delPost, addPost, updatePost, optionselect } from "@/api/system/post";
  131. import authUser from "./authUser.vue";
  132. export default {
  133. components: {
  134. authUser,
  135. },
  136. name: "Post",
  137. data() {
  138. return {
  139. isShow:true,
  140. // 遮罩层
  141. loading: true,
  142. // 选中数组
  143. ids: [],
  144. // 非单个禁用
  145. single: true,
  146. // 非多个禁用
  147. multiple: true,
  148. // 显示搜索条件
  149. showSearch: true,
  150. // 总条数
  151. total: 0,
  152. // 身份表格数据
  153. postList: [],
  154. // 弹出层标题
  155. title: "",
  156. // 是否显示弹出层
  157. open: false,
  158. // 状态数据字典
  159. statusOptions: [],
  160. // 查询参数
  161. queryParams: {
  162. pageNum: 1,
  163. pageSize:20,
  164. searchValue: null,
  165. postCode: undefined,
  166. postName: undefined,
  167. status: undefined
  168. },
  169. // 表单参数
  170. form: {},
  171. pageType:1,
  172. postId:"",
  173. // 表单校验
  174. rules: {
  175. postName: [
  176. { required: true, message: "请输入身份名称", trigger: "blur" },
  177. { required: true, message: "请输入身份名称", validator: this.spaceJudgment, trigger: "blur" }
  178. ],
  179. postCode: [
  180. { required: true, message: "请输入身份编码", trigger: "blur" },
  181. { required: true, message: "请输入身份编码", validator: this.spaceJudgment, trigger: "blur" }
  182. ],
  183. postSort: [
  184. { required: true, message: "请输入身份顺序", trigger: "blur" },
  185. { required: true, message: "请输入身份顺序", validator: this.spaceJudgment, trigger: "blur" }
  186. ],
  187. roleIds: [
  188. { required: true, message: "请选择权限组", trigger: "blur" },
  189. { required: true, message: "请选择权限组", validator: this.spaceJudgment, trigger: "blur" }
  190. ]
  191. },
  192. //权限组列表
  193. optionselectList:[],
  194. };
  195. },
  196. created() {
  197. this.getList();
  198. // this.getDicts("sys_normal_disable").then(response => {
  199. // this.statusOptions = response.data;
  200. // });
  201. this.optionselect();
  202. },
  203. methods: {
  204. //更多选项
  205. moreClick(item){
  206. if(item.command == 1){
  207. this.handleUpdate(item.row)
  208. }else if(item.command == 2){
  209. this.handleDelete(item.row)
  210. }
  211. },
  212. clickPage(type){
  213. if(this.pageType != type){
  214. this.pageType = type;
  215. }
  216. },
  217. /** 查询身份列表 */
  218. getList() {
  219. this.loading = true;
  220. listPost(this.queryParams).then(response => {
  221. this.postList = response.rows;
  222. this.total = response.total;
  223. this.loading = false;
  224. });
  225. },
  226. //获取权限组列表
  227. optionselect(){
  228. optionselect().then(response => {
  229. this.optionselectList = response.data;
  230. });
  231. },
  232. // 身份状态字典翻译
  233. statusFormat(row, column) {
  234. return this.selectDictLabel(this.statusOptions, row.status);
  235. },
  236. // 取消按钮
  237. cancel() {
  238. this.open = false;
  239. this.reset();
  240. },
  241. // 表单重置
  242. reset() {
  243. this.form = {
  244. postId: undefined,
  245. postCode: undefined,
  246. postName: undefined,
  247. postSort: 0,
  248. remark: undefined
  249. };
  250. this.resetForm("form");
  251. },
  252. /** 搜索按钮操作 */
  253. handleQuery() {
  254. this.queryParams.pageNum = 1;
  255. this.getList();
  256. },
  257. /** 重置按钮操作 */
  258. resetQuery() {
  259. this.queryParams.searchValue='';
  260. // this.resetForm("queryForm");
  261. this.$set(this,'queryParams',{
  262. pageNum: 1,
  263. pageSize:20,
  264. searchValue:"",
  265. });
  266. this.handleQuery();
  267. },
  268. /** 分配用户操作 */
  269. handleAuthUser: function(row) {
  270. if(row.roleIds){
  271. this.postId=row.postId;
  272. this.pageType=2;
  273. }else{
  274. this.msgError('未配置权限组的身份无法分配用户')
  275. }
  276. },
  277. // 多选框选中数据
  278. handleSelectionChange(selection) {
  279. this.ids = selection.map(item => item.postId)
  280. this.single = selection.length!=1
  281. this.multiple = !selection.length
  282. },
  283. /** 新增按钮操作 */
  284. handleAdd() {
  285. this.reset();
  286. this.open = true;
  287. this.title = "新增身份";
  288. },
  289. /** 修改按钮操作 */
  290. handleUpdate(row) {
  291. this.reset();
  292. const postId = row.postId || this.ids
  293. getPost(postId).then(response => {
  294. if(response.data.roleIds){
  295. response.data.roleIds = response.data.roleIds.split(',')
  296. for(let i=0;i<response.data.roleIds.length;i++){
  297. response.data.roleIds[i] = parseInt(response.data.roleIds[i]);//字符串转数字
  298. }
  299. }
  300. this.form = response.data;
  301. this.open = true;
  302. this.title = "修改身份";
  303. });
  304. },
  305. /** 提交按钮 */
  306. submitForm: function() {
  307. this.$refs["form"].validate(valid => {
  308. if (valid) {
  309. let obj = JSON.parse(JSON.stringify(this.form))
  310. obj.roleIds = obj.roleIds+'';
  311. if (this.form.postId != undefined) {
  312. updatePost(obj).then(response => {
  313. this.msgSuccess("修改成功");
  314. this.open = false;
  315. this.getList();
  316. });
  317. } else {
  318. addPost(obj).then(response => {
  319. this.msgSuccess("新增成功");
  320. this.open = false;
  321. this.getList();
  322. });
  323. }
  324. }
  325. });
  326. },
  327. /** 删除按钮操作 */
  328. handleDelete(row) {
  329. positionByList({position:row.postId}).then(response => {
  330. if(response.total<1){
  331. const postIds = row.postId || this.ids;
  332. this.$confirm('是否确认删除身份?', "警告", {
  333. confirmButtonText: "确定",
  334. cancelButtonText: "取消",
  335. type: "warning"
  336. }).then(function() {
  337. return delPost(postIds);
  338. }).then(() => {
  339. this.getList();
  340. this.msgSuccess("删除成功");
  341. }).catch(() => {});
  342. }else{
  343. this.msgError('该身份下还有用户无法删除')
  344. }
  345. });
  346. },
  347. /** 导出按钮操作 */
  348. handleExport() {
  349. this.download('system/post/export', {
  350. ...this.queryParams
  351. }, `post_${new Date().getTime()}.xlsx`)
  352. }
  353. }
  354. };
  355. </script>
  356. <style scoped lang="scss">
  357. .post-page{
  358. display: flex!important;
  359. flex-direction: column;
  360. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  361. padding:11px 20px 20px!important;
  362. .post-page-min{
  363. flex:1;
  364. display: flex!important;
  365. flex-direction: column;
  366. .button-box{
  367. width:340px;
  368. display: flex;
  369. }
  370. }
  371. }
  372. </style>