team.vue 20 KB

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