team.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <div class="w-main team">
  3. <v-title>{{$L('团队')}}-{{$L('轻量级的团队在线协作')}}</v-title>
  4. <div class="w-nav">
  5. <div class="nav-row">
  6. <div class="w-nav-left">
  7. <div class="page-nav-left">
  8. <span><i class="ft icon">&#xE90D;</i> {{$L('团队成员')}}</span>
  9. <div v-if="loadIng > 0" class="page-nav-loading"><w-loading></w-loading></div>
  10. <div v-else class="page-nav-refresh"><em @click="getLists(true)">{{$L('刷新')}}</em></div>
  11. </div>
  12. </div>
  13. <div class="w-nav-flex"></div>
  14. <div class="w-nav-right">
  15. <span class="ft hover" @click="handleUser('add')"><i class="ft icon">&#xE740;</i> {{$L('添加团队成员')}}</span>
  16. </div>
  17. </div>
  18. </div>
  19. <w-content>
  20. <div class="team-main">
  21. <div class="team-body">
  22. <!-- 列表 -->
  23. <Table class="tableFill" ref="tableRef" :columns="columns" :data="lists" :loading="loadIng > 0" :no-data-text="noDataText" stripe></Table>
  24. <!-- 分页 -->
  25. <Page class="pageBox" :total="listTotal" :current="listPage" :disabled="loadIng > 0" @on-change="setPage" @on-page-size-change="setPageSize" :page-size-opts="[10,20,30,50,100]" placement="top" show-elevator show-sizer show-total></Page>
  26. </div>
  27. </div>
  28. </w-content>
  29. <Modal
  30. v-model="addShow"
  31. :title="$L(formData.id > 0 ? '修改团队成员' : '添加团队成员')"
  32. :closable="false"
  33. :mask-closable="false"
  34. class-name="simple-modal">
  35. <Form ref="add" :model="formData" :label-width="80" @submit.native.prevent>
  36. <FormItem prop="userimg" :label="$L('头像')">
  37. <ImgUpload v-model="formData.userimg"></ImgUpload>
  38. </FormItem>
  39. <FormItem prop="nickname" :label="$L('昵称')">
  40. <Input type="text" v-model="formData.nickname"></Input>
  41. </FormItem>
  42. <FormItem prop="profession" :label="$L('职位/职称')">
  43. <Input v-model="formData.profession"></Input>
  44. </FormItem>
  45. <FormItem prop="username">
  46. <div slot="label"><em v-if="formData.id == 0" class="team-add-red-input">*</em>{{$L('用户名')}}</div>
  47. <Input v-if="formData.id > 0" disabled v-model="formData.username"></Input>
  48. <TagInput v-else v-model="formData.username" :placeholder="$L('添加后不可修改,使用英文逗号添加多个。')"/>
  49. </FormItem>
  50. <FormItem prop="userpass">
  51. <div slot="label"><em v-if="formData.id == 0" class="team-add-red-input">*</em>{{$L('登录密码')}}</div>
  52. <Input type="password" v-model="formData.userpass" :placeholder="$L(formData.id > 0 ? '留空不修改' : '最少6位数')"></Input>
  53. </FormItem>
  54. <FormItem class="team-add-form-item-changepass" :class="{show:formData.userpass}" v-if="formData.id == 0" prop="changepass">
  55. <Checkbox v-model="formData.changepass" :true-value="1" :false-value="0">{{$L('首次登陆需修改密码')}}</Checkbox>
  56. </FormItem>
  57. </Form>
  58. <div slot="footer">
  59. <Button type="default" @click="addShow=false">{{$L('取消')}}</Button>
  60. <Button type="primary" :loading="loadIng > 0" @click="onAdd">{{$L(formData.id > 0 ? '修改' : '添加')}}</Button>
  61. </div>
  62. </Modal>
  63. </div>
  64. </template>
  65. <style lang="scss">
  66. .team-add-red-input {
  67. display: inline-block;
  68. margin-right: 4px;
  69. line-height: 1;
  70. font-family: SimSun,serif;
  71. font-size: 14px;
  72. color: #ed4014;
  73. }
  74. .team-add-form-item-changepass {
  75. margin-top: -18px;
  76. margin-bottom: 18px;
  77. height: 0;
  78. overflow: hidden;
  79. transition: all 0.2s;
  80. &.show {
  81. height: 32px;
  82. }
  83. }
  84. </style>
  85. <style lang="scss" scoped>
  86. .team {
  87. .team-main {
  88. display: flex;
  89. flex-direction: column;
  90. width: 100%;
  91. height: 100%;
  92. padding: 15px;
  93. .team-body {
  94. display: flex;
  95. flex-direction: column;
  96. width: 100%;
  97. height: 100%;
  98. min-height: 500px;
  99. background: #fefefe;
  100. border-radius: 3px;
  101. .tableFill {
  102. margin: 20px;
  103. background-color: #ffffff;
  104. }
  105. }
  106. }
  107. }
  108. </style>
  109. <script>
  110. import WContent from "../components/WContent";
  111. import ImgUpload from "../components/ImgUpload";
  112. import TagInput from "../components/TagInput";
  113. export default {
  114. components: {TagInput, ImgUpload, WContent},
  115. data () {
  116. return {
  117. loadIng: 0,
  118. userInfo: {},
  119. isAdmin: false,
  120. columns: [],
  121. lists: [],
  122. listPage: 1,
  123. listTotal: 0,
  124. noDataText: "",
  125. addShow: false,
  126. formData: {
  127. id: 0,
  128. userimg: '',
  129. profession: '',
  130. username: '',
  131. nickname: '',
  132. userpass: '',
  133. },
  134. }
  135. },
  136. created() {
  137. this.isAdmin = $A.identity('admin');
  138. this.noDataText = this.$L("数据加载中.....");
  139. this.columns = [{
  140. "title": this.$L("头像"),
  141. "minWidth": 60,
  142. "maxWidth": 100,
  143. render: (h, params) => {
  144. return h('UserImg', {
  145. props: {
  146. info: params.row,
  147. },
  148. style: {
  149. width: "30px",
  150. height: "30px",
  151. fontSize: "16px",
  152. lineHeight: "30px",
  153. borderRadius: "15px",
  154. verticalAlign: "middle"
  155. },
  156. });
  157. }
  158. }, {
  159. "title": this.$L("用户名"),
  160. "key": 'username',
  161. "minWidth": 80,
  162. "ellipsis": true,
  163. render: (h, params) => {
  164. let arr = [];
  165. if (params.row.username == $A.getUserName()) {
  166. arr.push(h('span', {
  167. style: {
  168. color: '#ff0000',
  169. paddingRight: '4px'
  170. }
  171. }, '[自己]'))
  172. }
  173. if ($A.identityRaw('admin', params.row.identity)) {
  174. arr.push(h('span', {
  175. style: {
  176. color: '#ff0000',
  177. paddingRight: '4px'
  178. }
  179. }, '[管理员]'))
  180. }
  181. arr.push(h('span', params.row.username))
  182. return h('span', arr);
  183. }
  184. }, {
  185. "title": this.$L("昵称"),
  186. "minWidth": 80,
  187. "ellipsis": true,
  188. render: (h, params) => {
  189. return h('span', params.row.nickname || '-');
  190. }
  191. }, {
  192. "title": this.$L("职位/职称"),
  193. "minWidth": 100,
  194. "ellipsis": true,
  195. render: (h, params) => {
  196. return h('span', params.row.profession || '-');
  197. }
  198. }, {
  199. "title": this.$L("加入时间"),
  200. "width": 160,
  201. render: (h, params) => {
  202. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.regdate));
  203. }
  204. }, {
  205. "title": this.$L("操作"),
  206. "key": 'action',
  207. "width": this.isAdmin ? 160 : 80,
  208. "align": 'center',
  209. render: (h, params) => {
  210. let array = [];
  211. array.push(h('Button', {
  212. props: {
  213. type: 'primary',
  214. size: 'small'
  215. },
  216. style: {
  217. fontSize: '12px'
  218. },
  219. on: {
  220. click: () => {
  221. this.$Modal.info({
  222. title: this.$L('会员信息'),
  223. content: `<p>${this.$L('昵称')}: ${params.row.nickname || '-'}</p><p>${this.$L('职位/职称')}: ${params.row.profession || '-'}</p>`
  224. });
  225. }
  226. }
  227. }, this.$L('查看')));
  228. if (this.isAdmin) {
  229. array.push(h('Dropdown', {
  230. props: {
  231. trigger: 'click',
  232. transfer: true
  233. },
  234. on: {
  235. 'on-click': (name) => {
  236. this.handleUser(name, params.row)
  237. }
  238. }
  239. }, [
  240. h('Button', {
  241. props: {
  242. type: 'warning',
  243. size: 'small'
  244. },
  245. style: {
  246. fontSize: '12px',
  247. marginLeft: '5px'
  248. },
  249. }, this.$L('操作')),
  250. h('DropdownMenu', {
  251. slot: 'list',
  252. }, [
  253. h('DropdownItem', {
  254. props: {
  255. name: 'edit',
  256. },
  257. }, this.$L('修改成员信息')),
  258. h('DropdownItem', {
  259. props: {
  260. name: $A.identityRaw('admin', params.row.identity) ? 'deladmin' : 'setadmin',
  261. },
  262. }, this.$L($A.identityRaw('admin', params.row.identity) ? '取消管理员' : '设为管理员')),
  263. h('DropdownItem', {
  264. props: {
  265. name: 'delete',
  266. },
  267. }, this.$L('删除'))
  268. ])
  269. ]))
  270. }
  271. return h('div', array);
  272. }
  273. }];
  274. },
  275. mounted() {
  276. this.getLists(true);
  277. this.userInfo = $A.getUserInfo((res, isLogin) => {
  278. if (this.userInfo.id != res.id) {
  279. this.userInfo = res;
  280. isLogin && this.getLists(true);
  281. } else {
  282. this.userInfo = res;
  283. }
  284. }, false);
  285. },
  286. deactivated() {
  287. this.addShow = false;
  288. },
  289. methods: {
  290. setPage(page) {
  291. this.listPage = page;
  292. this.getLists();
  293. },
  294. setPageSize(size) {
  295. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  296. this.listPageSize = size;
  297. this.getLists();
  298. }
  299. },
  300. getLists(resetLoad) {
  301. if (resetLoad === true) {
  302. this.listPage = 1;
  303. }
  304. this.loadIng++;
  305. this.noDataText = this.$L("数据加载中.....");
  306. $A.apiAjax({
  307. url: 'users/team/lists',
  308. data: {
  309. page: Math.max(this.listPage, 1),
  310. pagesize: Math.max($A.runNum(this.listPageSize), 10),
  311. },
  312. complete: () => {
  313. this.loadIng--;
  314. },
  315. error: () => {
  316. this.noDataText = this.$L("数据加载失败!");
  317. },
  318. success: (res) => {
  319. if (res.ret === 1) {
  320. this.lists = res.data.lists;
  321. this.listTotal = res.data.total;
  322. this.noDataText = this.$L("没有相关的数据");
  323. }else{
  324. this.lists = [];
  325. this.listTotal = 0;
  326. this.noDataText = res.msg;
  327. }
  328. }
  329. });
  330. },
  331. onAdd() {
  332. this.loadIng++;
  333. let id = $A.runNum(this.formData.id);
  334. $A.apiAjax({
  335. url: 'users/team/add',
  336. data: this.formData,
  337. complete: () => {
  338. this.loadIng--;
  339. },
  340. success: (res) => {
  341. if (res.ret === 1) {
  342. this.addShow = false;
  343. this.$Message.success(res.msg);
  344. this.$refs.add.resetFields();
  345. //
  346. this.getLists(id == 0);
  347. }else{
  348. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  349. }
  350. }
  351. });
  352. },
  353. handleUser(act, info) {
  354. switch (act) {
  355. case "add": {
  356. this.addShow = true;
  357. this.formData = {
  358. id: 0,
  359. userimg: '',
  360. profession: '',
  361. username: '',
  362. nickname: '',
  363. userpass: '',
  364. changepass: 1
  365. }
  366. break;
  367. }
  368. case "edit": {
  369. this.addShow = true;
  370. this.formData = Object.assign($A.cloneData(info))
  371. break;
  372. }
  373. case "delete": {
  374. this.$Modal.confirm({
  375. title: this.$L('删除团队成员'),
  376. content: this.$L('你确定要删除此团队成员吗?'),
  377. loading: true,
  378. onOk: () => {
  379. $A.apiAjax({
  380. url: 'users/team/delete?username=' + info.username,
  381. error: () => {
  382. this.$Modal.remove();
  383. alert(this.$L('网络繁忙,请稍后再试!'));
  384. },
  385. success: (res) => {
  386. this.$Modal.remove();
  387. this.getLists();
  388. setTimeout(() => {
  389. if (res.ret === 1) {
  390. this.$Message.success(res.msg);
  391. }else{
  392. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  393. }
  394. }, 350);
  395. }
  396. });
  397. }
  398. });
  399. break;
  400. }
  401. case "setadmin":
  402. case "deladmin": {
  403. this.$Modal.confirm({
  404. title: this.$L('确定操作'),
  405. content: this.$L(act=='deladmin' ? '你确定取消管理员身份的操作吗?' : '你确定设置管理员的操作吗?'),
  406. loading: true,
  407. onOk: () => {
  408. $A.apiAjax({
  409. url: 'users/team/admin?act=' + (act=='deladmin'?'del':'set') + '&username=' + info.username,
  410. error: () => {
  411. this.$Modal.remove();
  412. alert(this.$L('网络繁忙,请稍后再试!'));
  413. },
  414. success: (res) => {
  415. this.$Modal.remove();
  416. if (res.ret === 1) {
  417. this.lists.some((item) => {
  418. if (item.username == info.username) {
  419. this.$set(item, 'identity', res.data.identity);
  420. return true;
  421. }
  422. });
  423. if (res.data.up === 1) {
  424. let data = {
  425. type: 'text',
  426. username: this.userInfo.username,
  427. userimg: this.userInfo.userimg,
  428. indate: Math.round(new Date().getTime() / 1000),
  429. text: this.$L(act=='deladmin' ? '您的管理员身份已被撤销。' : '恭喜您成为管理员。')
  430. };
  431. $A.WSOB.sendTo('user', info.username, data, 'special');
  432. $A.WSOB.sendTo('info', info.username, { 'type': 'update'});
  433. }
  434. }
  435. setTimeout(() => {
  436. if (res.ret === 1) {
  437. this.$Message.success(res.msg);
  438. } else {
  439. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  440. }
  441. }, 350);
  442. }
  443. });
  444. }
  445. });
  446. break;
  447. }
  448. }
  449. }
  450. },
  451. }
  452. </script>