index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <div class="bf-rolelist">
  3. <!-- 角色列表 -->
  4. <div class="cont">
  5. <div v-if="title" class="paren_header">
  6. <p>{{ title }}</p>
  7. </div>
  8. <template v-if="dataList.length">
  9. <div :class="active ? 'bgActive' : 'bgActivecheckbox'" class="paren_content">
  10. <template v-if="!type">
  11. <el-scrollbar class="scrollBar" style="height: 100%">
  12. <el-row v-infinite-scroll="load" :infinite-scroll-distance="20" infinite-scroll-disabled="disabled" class="scCont scrollbar" :gutter="16">
  13. <el-checkbox-group @change="checkChange" v-model="checkList">
  14. <el-col :span="number" v-for="(item, index) in dataList" :key="index">
  15. <div @click="handleBg(item, index)" :class="active && msg === index ? 'bgColor' : ''" class="cide">
  16. <div class="cide_header">
  17. <p :title="item.name">{{ item.name }}</p>
  18. <el-checkbox :label="index"></el-checkbox>
  19. </div>
  20. </div>
  21. </el-col>
  22. </el-checkbox-group>
  23. </el-row>
  24. </el-scrollbar>
  25. </template>
  26. <template v-if="total > 1">
  27. <p class="center" v-if="loading">加载中...</p>
  28. <p class="center" v-if="noMore">没有更多数据了~</p>
  29. </template>
  30. </div>
  31. </template>
  32. <template v-else-if="mainData.length">
  33. <div :class="active ? 'bgActive' : 'bgActivecheckbox'" class="paren_content">
  34. <template v-if="type">
  35. <el-scrollbar class="scrollBar" style="height: 100%">
  36. <el-row :gutter="16">
  37. <el-radio-group style="display: block" @change="radioChange" v-model="radio">
  38. <el-col :span="number" v-for="(item, index) in mainData" :key="index">
  39. <div @click.stop="handleBg(index)" :class="active && msg === index ? 'bgColor' : ''" class="cide">
  40. <div class="cide_header">
  41. <p>{{ item.name }}</p>
  42. <el-radio :label="index"></el-radio>
  43. </div>
  44. </div>
  45. </el-col>
  46. </el-radio-group>
  47. </el-row>
  48. </el-scrollbar>
  49. </template>
  50. </div>
  51. </template>
  52. <template v-else>
  53. <el-empty :imageSize="imageSize" description="暂无数据"></el-empty>
  54. </template>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { GetAccountList } from "@/api/Account";
  60. import { GetRoleByGroup } from "@/api/AccountGroup";
  61. import { QueryRole } from '@/api/apiAuthority';
  62. export default {
  63. props: {
  64. title: {
  65. type: String,
  66. default: "",
  67. },
  68. type: {
  69. type: Boolean,
  70. default: false,
  71. },
  72. number: {
  73. type: Number,
  74. default: 3,
  75. },
  76. active: {
  77. type: Boolean,
  78. default: false,
  79. },
  80. checkBoxList: {
  81. type: Array,
  82. default: () => [],
  83. },
  84. mainData: {
  85. type: Array,
  86. default: () => [],
  87. },
  88. radioCheck: {
  89. type: Number,
  90. default: 0,
  91. },
  92. imageSize: {
  93. type: Number,
  94. default: 200,
  95. },
  96. roleType: {
  97. type: String,
  98. default: "",
  99. },
  100. GroupIds: {
  101. type: Array,
  102. default: () => [],
  103. },
  104. },
  105. data () {
  106. return {
  107. radio: null,
  108. checkList: [],
  109. dataList: [],
  110. arrsList: [],
  111. msg: null,
  112. pageSize: 100,
  113. pageNum: 1,
  114. total: "",
  115. loading: false,
  116. asyncData: [],
  117. msgDatas: []
  118. };
  119. },
  120. watch: {
  121. radioCheck: {
  122. handler (num) {
  123. this.radio = num;
  124. },
  125. deep: true,
  126. },
  127. roleType: {
  128. handler (msg) {
  129. const obj = {};
  130. obj[msg] = msg;
  131. this.msgDatas.push(obj);
  132. },
  133. deep: true,
  134. },
  135. dataList: {
  136. handler (arr) {
  137. if (arr && arr.length) {
  138. this.asyncData.push(true);
  139. }
  140. },
  141. deep: true,
  142. },
  143. checkBoxList: {
  144. handler (arr) {
  145. if (arr && arr.length) {
  146. this.asyncData.push(true);
  147. }
  148. },
  149. deep: true,
  150. },
  151. asyncData: {
  152. handler (arr) {
  153. if (arr && arr.length >= 2) {
  154. if (this.roleType == "account") {
  155. this.checkBoxs("UserId");
  156. }
  157. if (this.roleType == "onlyRole" || this.roleType == 'roleByUpId') {
  158. this.checkBoxs("RoleId");
  159. }
  160. }
  161. },
  162. deep: true
  163. },
  164. GroupIds: {
  165. handler () {
  166. const obj = {};
  167. obj['GroupIds'] = 'GroupIds';
  168. this.msgDatas.push(obj);
  169. },
  170. deep: true
  171. },
  172. msgDatas: {
  173. handler (arr) {
  174. if (arr && arr.length >= 2) {
  175. this.getRoleDataByUpId();
  176. } else {
  177. if (this.roleType == 'account') {
  178. this.getRoleData('UserId', 'UserName');
  179. }
  180. if (this.roleType == "roleByUpId") {
  181. this.getRoleDataByUpId("roleId");
  182. }
  183. if (this.roleType == "onlyRole") {
  184. this.getRoleData('RoleId', 'RoleName');
  185. }
  186. }
  187. },
  188. deep: true
  189. }
  190. },
  191. computed: {
  192. noMore () {
  193. return this.pageNum >= this.total;
  194. },
  195. disabled () {
  196. return this.loading || this.noMore;
  197. },
  198. },
  199. methods: {
  200. // 选中
  201. handleBg (item, i) {
  202. this.msg = i;
  203. this.$emit("checkClick", item);
  204. },
  205. //多选框
  206. checkChange (arr) {
  207. const datas = this.formatChecks(arr);
  208. // if (this.roleType == 'account') {
  209. // datas = this.formatChecks(arr, 'UserId');
  210. // }
  211. this.$emit("checkChange", datas);
  212. },
  213. //单选框
  214. radioChange (val) {
  215. this.$emit("radioChange", val);
  216. },
  217. //格式化选中回调
  218. formatChecks (arr, key) {
  219. const datas = [];
  220. // const ids = []
  221. this.dataList.forEach((item, index) => {
  222. arr.forEach((p) => {
  223. if (index == p) {
  224. datas.push(item);
  225. }
  226. });
  227. });
  228. // datas.forEach(item => {
  229. // ids.push(item[key])
  230. // })
  231. return datas;
  232. },
  233. //多选框默认选中
  234. checkBoxs (ids) {
  235. const datas = [];
  236. const type = typeof this.checkBoxList[0];
  237. if (type == 'object') {
  238. this.dataList.forEach((item, index) => {
  239. this.checkBoxList.forEach((p) => {
  240. if (item[ids] == p[ids]) {
  241. datas.push(index);
  242. }
  243. });
  244. });
  245. } else {
  246. this.dataList.forEach((item, index) => {
  247. this.checkBoxList.forEach((p) => {
  248. if (item[ids] == p) {
  249. datas.push(index);
  250. }
  251. });
  252. });
  253. }
  254. this.checkList = datas;
  255. },
  256. checkRole () {
  257. const datas = [];
  258. this.dataList.forEach((item, index) => {
  259. this.checkBoxList.forEach((p) => {
  260. if (item.RoleId == p.RoleId) {
  261. datas.push(index);
  262. }
  263. });
  264. });
  265. this.checkList = datas;
  266. },
  267. //获取列表
  268. async getRoleData (ids, names) {
  269. try {
  270. this.loading = true;
  271. const obj = {
  272. QueryName: "",
  273. PageIndex: this.pageNum,
  274. PageSize: this.pageSize,
  275. };
  276. let result = null;
  277. if (this.roleType == "account") {
  278. result = await GetAccountList(obj);
  279. }
  280. if (this.roleType == "onlyRole") {
  281. result = await QueryRole(obj);
  282. }
  283. if (result.code === 0) {
  284. const datas = result.returnData.records;
  285. const num = result.returnData.pages;
  286. this.arrsList.push(datas);
  287. const arrs = this.arrsList.flat();
  288. const msgs = _.unionBy(arrs, ids);
  289. msgs.forEach(item => {
  290. item.name = item[names]
  291. });
  292. this.dataList = msgs;
  293. this.total = num;
  294. this.$emit('roleListChange', msgs)
  295. this.loading = false;
  296. } else {
  297. this.$message.error(result.message);
  298. this.loading = false;
  299. }
  300. } catch (error) {
  301. console.log("出错了", error);
  302. this.loading = false;
  303. }
  304. },
  305. //获取列表2
  306. async getRoleDataByUpId () {
  307. try {
  308. this.loading = true;
  309. const obj = {
  310. GroupIds: this.GroupIds
  311. };
  312. const result = await GetRoleByGroup(obj);
  313. if (result.code === 0) {
  314. const datas = result.returnData;
  315. const msgs = [];
  316. if (datas.length) {
  317. datas.forEach(item => {
  318. item.name = item.RoleName
  319. if (item.IsSelected) {
  320. msgs.push(item);
  321. }
  322. })
  323. this.dataList = msgs;
  324. } else {
  325. this.dataList = msgs;
  326. }
  327. this.$emit('roleListChange', msgs)
  328. // this.checkBoxs(this.dataList, "RoleId");
  329. this.loading = false;
  330. } else {
  331. this.$message.error(result.message);
  332. this.loading = false;
  333. }
  334. } catch (error) {
  335. console.log("出错了", error);
  336. this.loading = false;
  337. }
  338. },
  339. //滚动加载数据
  340. load () {
  341. this.pageNum += 1;
  342. if (this.roleType == 'account') {
  343. this.getRoleData('UserId', 'UserName');
  344. }
  345. if (this.roleType == 'onlyRole') {
  346. this.getRoleData('RoleId', 'RoleName');
  347. }
  348. },
  349. },
  350. };
  351. </script>
  352. <style lang="scss" scoped>
  353. @import "./rolelist.scss";
  354. .paren_content {
  355. ::v-deep .el-radio__label {
  356. display: none;
  357. }
  358. ::v-deep .el-checkbox__label {
  359. display: none;
  360. }
  361. // .scCont {
  362. // height: 65vh;
  363. // overflow-x: hidden;
  364. // overflow-y: auto;
  365. // }
  366. }
  367. </style>