Invite.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="container">
  3. <el-row class="row-item title">
  4. <h4>生成邀请码</h4>
  5. </el-row>
  6. <div class="row-item">
  7. <span>邀请码:</span>
  8. <span @click="copy(relateCode)">{{relateCode}}</span>
  9. </div>
  10. <div class="row-item">
  11. <span>
  12. <el-button
  13. @click="generateRelateCode()"
  14. type="primary"
  15. size="small"
  16. >
  17. 生成
  18. </el-button>
  19. </span>
  20. </div>
  21. <el-divider content-position="left">或</el-divider>
  22. <el-row class="row-item title">
  23. <h4>关联其他项目</h4>
  24. </el-row>
  25. <el-row style="row-item">
  26. <el-input v-model="targetCode" placeholder="请输入要关联的项目生成的邀请码" style="width: 270px"></el-input>
  27. <el-button
  28. @click="relate()"
  29. type="primary"
  30. size="small"
  31. style="margin-left: 16px"
  32. >
  33. 关联
  34. </el-button>
  35. </el-row>
  36. </div>
  37. </template>
  38. <script>
  39. import { ProjectAPI } from '@/api';
  40. import { ElMessage } from 'element-plus';
  41. import { copy } from '@/utils/clipboard';
  42. export default {
  43. data() {
  44. return {
  45. relateCode: '',
  46. targetCode: '',
  47. };
  48. },
  49. methods: {
  50. copy,
  51. async generateRelateCode() {
  52. this.relateCode = await ProjectAPI.generateRelateCode(this.$store.state.workspace.currentProjectId);
  53. ElMessage.success('邀请码将在5分钟后失效,请及时完成操作!');
  54. },
  55. async relate() {
  56. await ProjectAPI.relateProject(this.$store.state.workspace.currentProjectId, this.targetCode).then((res) => {
  57. if (res === '验证码有效时间为五分钟,已过期') {
  58. ElMessage.warning('验证码有效时间为五分钟,已过期');
  59. } else if (res === '不可将本项目与自身关联!') {
  60. ElMessage.error('不可将本项目与自身关联!');
  61. } else if (res === '该项目已与目标项目关联过,无须重复关联') {
  62. ElMessage.warning('该项目已与目标项目关联过,无须重复关联');
  63. } else {
  64. ElMessage.success('关联成功');
  65. }
  66. });
  67. this.targetCode = '';
  68. },
  69. },
  70. };
  71. </script>
  72. <style scoped>
  73. .container {
  74. margin: 50px 100px;
  75. width: 30%
  76. }
  77. .row-item {
  78. display: flex;
  79. flex-direction: row;
  80. align-items: center;
  81. margin-bottom: 10px;
  82. }
  83. .title {
  84. color: #333333
  85. }
  86. </style>