team.vue 19 KB

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