team.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <div class="w-main team">
  3. <v-title>{{$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. isAdmin: false,
  127. columns: [],
  128. lists: [],
  129. listPage: 1,
  130. listTotal: 0,
  131. noDataText: "",
  132. addShow: false,
  133. formData: {
  134. id: 0,
  135. userimg: '',
  136. profession: '',
  137. username: '',
  138. nickname: '',
  139. userpass: '',
  140. },
  141. }
  142. },
  143. mounted() {
  144. this.getLists(true);
  145. },
  146. deactivated() {
  147. this.addShow = false;
  148. },
  149. watch: {
  150. usrName() {
  151. this.usrLogin && this.getLists(true);
  152. }
  153. },
  154. methods: {
  155. initLanguage() {
  156. this.isAdmin = $A.identity('admin');
  157. this.noDataText = this.$L("数据加载中.....");
  158. this.columns = [{
  159. "title": this.$L("头像"),
  160. "minWidth": 60,
  161. "maxWidth": 100,
  162. render: (h, params) => {
  163. return h('UserImg', {
  164. props: {
  165. info: params.row,
  166. },
  167. style: {
  168. width: "30px",
  169. height: "30px",
  170. fontSize: "16px",
  171. lineHeight: "30px",
  172. borderRadius: "15px",
  173. verticalAlign: "middle"
  174. },
  175. });
  176. }
  177. }, {
  178. "title": this.$L("用户名"),
  179. "key": 'username',
  180. "minWidth": 80,
  181. "ellipsis": true,
  182. render: (h, params) => {
  183. let arr = [];
  184. if (params.row.username == this.usrName) {
  185. arr.push(h('span', {
  186. style: {
  187. color: '#ff0000',
  188. paddingRight: '4px'
  189. }
  190. }, '[自己]'))
  191. }
  192. if ($A.identityRaw('admin', params.row.identity)) {
  193. arr.push(h('span', {
  194. style: {
  195. color: '#ff0000',
  196. paddingRight: '4px'
  197. }
  198. }, '[管理员]'))
  199. }
  200. arr.push(h('span', params.row.username))
  201. return h('span', arr);
  202. }
  203. }, {
  204. "title": this.$L("昵称"),
  205. "minWidth": 80,
  206. "ellipsis": true,
  207. render: (h, params) => {
  208. return h('span', params.row.nickname || '-');
  209. }
  210. }, {
  211. "title": this.$L("职位/职称"),
  212. "minWidth": 100,
  213. "ellipsis": true,
  214. render: (h, params) => {
  215. return h('span', params.row.profession || '-');
  216. }
  217. }, {
  218. "title": this.$L("加入时间"),
  219. "width": 160,
  220. render: (h, params) => {
  221. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.regdate));
  222. }
  223. }, {
  224. "title": this.$L("操作"),
  225. "key": 'action',
  226. "width": this.isAdmin ? 160 : 80,
  227. "align": 'center',
  228. render: (h, params) => {
  229. let array = [];
  230. array.push(h('Button', {
  231. props: {
  232. type: 'primary',
  233. size: 'small'
  234. },
  235. style: {
  236. fontSize: '12px'
  237. },
  238. on: {
  239. click: () => {
  240. this.$Modal.info({
  241. title: this.$L('会员信息'),
  242. content: `<p>${this.$L('昵称')}: ${params.row.nickname || '-'}</p><p>${this.$L('职位/职称')}: ${params.row.profession || '-'}</p>`
  243. });
  244. }
  245. }
  246. }, this.$L('查看')));
  247. if (this.isAdmin) {
  248. array.push(h('Dropdown', {
  249. props: {
  250. trigger: 'click',
  251. transfer: true
  252. },
  253. on: {
  254. 'on-click': (name) => {
  255. this.handleUser(name, params.row)
  256. }
  257. }
  258. }, [
  259. h('Button', {
  260. props: {
  261. type: 'warning',
  262. size: 'small'
  263. },
  264. style: {
  265. fontSize: '12px',
  266. marginLeft: '5px'
  267. },
  268. }, this.$L('操作')),
  269. h('DropdownMenu', {
  270. slot: 'list',
  271. }, [
  272. h('DropdownItem', {
  273. props: {
  274. name: 'edit',
  275. },
  276. }, this.$L('修改成员信息')),
  277. h('DropdownItem', {
  278. props: {
  279. name: $A.identityRaw('admin', params.row.identity) ? 'deladmin' : 'setadmin',
  280. },
  281. }, this.$L($A.identityRaw('admin', params.row.identity) ? '取消管理员' : '设为管理员')),
  282. h('DropdownItem', {
  283. props: {
  284. name: 'delete',
  285. },
  286. }, this.$L('删除'))
  287. ])
  288. ]))
  289. }
  290. return h('div', array);
  291. }
  292. }];
  293. },
  294. setPage(page) {
  295. this.listPage = page;
  296. this.getLists();
  297. },
  298. setPageSize(size) {
  299. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  300. this.listPageSize = size;
  301. this.getLists();
  302. }
  303. },
  304. getLists(resetLoad) {
  305. if (resetLoad === true) {
  306. this.listPage = 1;
  307. }
  308. this.loadIng++;
  309. this.noDataText = this.$L("数据加载中.....");
  310. $A.apiAjax({
  311. url: 'users/team/lists',
  312. data: {
  313. page: Math.max(this.listPage, 1),
  314. pagesize: Math.max($A.runNum(this.listPageSize), 10),
  315. },
  316. complete: () => {
  317. this.loadIng--;
  318. },
  319. error: () => {
  320. this.noDataText = this.$L("数据加载失败!");
  321. },
  322. success: (res) => {
  323. if (res.ret === 1) {
  324. this.lists = res.data.lists;
  325. this.listTotal = res.data.total;
  326. this.noDataText = this.$L("没有相关的数据");
  327. }else{
  328. this.lists = [];
  329. this.listTotal = 0;
  330. this.noDataText = res.msg;
  331. }
  332. }
  333. });
  334. },
  335. onAdd() {
  336. this.loadIng++;
  337. let id = $A.runNum(this.formData.id);
  338. $A.apiAjax({
  339. url: 'users/team/add',
  340. data: this.formData,
  341. complete: () => {
  342. this.loadIng--;
  343. },
  344. success: (res) => {
  345. if (res.ret === 1) {
  346. this.addShow = false;
  347. this.$Message.success(res.msg);
  348. this.$refs.add.resetFields();
  349. //
  350. this.getLists(id == 0);
  351. }else{
  352. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  353. }
  354. }
  355. });
  356. },
  357. handleUser(act, info) {
  358. switch (act) {
  359. case "add": {
  360. this.addShow = true;
  361. this.formData = {
  362. id: 0,
  363. userimg: '',
  364. profession: '',
  365. username: '',
  366. nickname: '',
  367. userpass: '',
  368. changepass: 1
  369. }
  370. break;
  371. }
  372. case "edit": {
  373. this.addShow = true;
  374. this.formData = Object.assign($A.cloneData(info))
  375. break;
  376. }
  377. case "delete": {
  378. this.$Modal.confirm({
  379. title: this.$L('删除团队成员'),
  380. content: this.$L('你确定要删除此团队成员吗?'),
  381. loading: true,
  382. onOk: () => {
  383. $A.apiAjax({
  384. url: 'users/team/delete?username=' + info.username,
  385. error: () => {
  386. this.$Modal.remove();
  387. alert(this.$L('网络繁忙,请稍后再试!'));
  388. },
  389. success: (res) => {
  390. this.$Modal.remove();
  391. this.getLists();
  392. setTimeout(() => {
  393. if (res.ret === 1) {
  394. this.$Message.success(res.msg);
  395. }else{
  396. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  397. }
  398. }, 350);
  399. }
  400. });
  401. }
  402. });
  403. break;
  404. }
  405. case "setadmin":
  406. case "deladmin": {
  407. this.$Modal.confirm({
  408. title: this.$L('确定操作'),
  409. content: this.$L(act=='deladmin' ? '你确定取消管理员身份的操作吗?' : '你确定设置管理员的操作吗?'),
  410. loading: true,
  411. onOk: () => {
  412. $A.apiAjax({
  413. url: 'users/team/admin?act=' + (act=='deladmin'?'del':'set') + '&username=' + info.username,
  414. error: () => {
  415. this.$Modal.remove();
  416. alert(this.$L('网络繁忙,请稍后再试!'));
  417. },
  418. success: (res) => {
  419. this.$Modal.remove();
  420. if (res.ret === 1) {
  421. this.lists.some((item) => {
  422. if (item.username == info.username) {
  423. this.$set(item, 'identity', res.data.identity);
  424. return true;
  425. }
  426. });
  427. if (res.data.up === 1) {
  428. let data = {
  429. type: 'text',
  430. username: this.usrInfo.username,
  431. userimg: this.usrInfo.userimg,
  432. indate: Math.round(new Date().getTime() / 1000),
  433. text: this.$L(act=='deladmin' ? '您的管理员身份已被撤销。' : '恭喜您成为管理员。')
  434. };
  435. $A.WSOB.sendTo('user', info.username, data, 'special');
  436. $A.WSOB.sendTo('info', info.username, { 'type': 'update'});
  437. }
  438. }
  439. setTimeout(() => {
  440. if (res.ret === 1) {
  441. this.$Message.success(res.msg);
  442. } else {
  443. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  444. }
  445. }, 350);
  446. }
  447. });
  448. }
  449. });
  450. break;
  451. }
  452. }
  453. }
  454. },
  455. }
  456. </script>