index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="app-wrapper">
  3. <div class='fixed-header'>
  4. <homebar />
  5. </div>
  6. <section class="app-main">
  7. <transition name="fade-transform" mode="out-in">
  8. <router-view />
  9. </transition>
  10. </section>
  11. <el-dialog width="30%" title="联系我们" :visible.sync="dialogVisible">
  12. <img width="100%" src="@/assets/images/wx.jpg" alt="">
  13. </el-dialog>
  14. <el-dialog width="30%" title="切换企业/团队" :visible.sync="teamWorkVisible">
  15. <div class="switch-corp-pane">
  16. <div class="corp-block">
  17. <div class="corp-desc">我创建的企业/团队</div>
  18. <div class="corp-wrapper" v-for="(item, index) in myTeamList" :key="index" @mouseover="showMyTeam = index"
  19. @mouseleave="showMyTeam = null">
  20. <div class="corp-item">
  21. <div class="corp-name" :class="{ 'is-owner': item.actived }" :title="item.name">{{ item.name }}</div>
  22. <div class="corp-op">
  23. <span class="op-current" v-show="item.actived">当前所在企业/团队</span>
  24. <el-button v-show="!item.actived && showMyTeam == index" type="text" class="style-text"
  25. @click.stop="changeTeam(item)">
  26. <span>进入企业/团队<i class="el-icon-right"></i></span>
  27. </el-button>
  28. </div>
  29. </div>
  30. </div>
  31. <el-button type="primary" plain class="corp-switch-btn" @click="joinOrCreateCorp('创建')">
  32. <span>创建企业/团队</span>
  33. </el-button>
  34. </div>
  35. <div class="corp-block" style="margin-top: 10px;">
  36. <div class="corp-desc">我加入的企业/团队</div>
  37. <div class="corp-wrapper" v-for="(item, index) in joinTeamList" :key="index" @mouseover="showJoinTeam = index"
  38. @mouseleave="showJoinTeam = null">
  39. <div class="corp-item">
  40. <div class="corp-name" :title="item.name">{{ item.name }}</div>
  41. <div class="corp-op">
  42. <span class="op-current" v-show="item.actived">当前所在企业/团队</span>
  43. <el-button v-show="!item.actived && showJoinTeam == index" type="text" class="style-text"
  44. @click.stop="changeTeam(item)">
  45. <span>进入企业/团队<i class="el-icon-right"></i></span>
  46. </el-button>
  47. </div>
  48. </div>
  49. </div>
  50. <el-button type="primary" plain class="corp-switch-btn" @click="joinOrCreateCorp('加入')">
  51. <span>加入企业/团队</span>
  52. </el-button>
  53. </div>
  54. </div>
  55. <el-dialog width="30%" :title="corpTitle + '企业/团队'" :visible.sync="joinOrCreateVisible" append-to-body>
  56. <el-form :model="form" :rules="rules" ref="ruleForm" label-position="top" label-width="80px" size="small">
  57. <el-form-item label="企业/团队名称" prop="name" v-if="corpTitle == '创建'">
  58. <el-input v-model="form.name" placeholder='请输入你的企业/团队名称'></el-input>
  59. </el-form-item>
  60. <el-form-item label="邀请码" prop="tenantId" v-if="corpTitle == '加入'">
  61. <el-input v-model="form.tenantId" placeholder='请输入你的邀请码'></el-input>
  62. </el-form-item>
  63. <el-button size="small" type="primary" style="text-align: center;width: 100%;margin-top: 10px;"
  64. @click="submitForm('ruleForm')">
  65. <span v-if="!loading"> {{ corpTitle }}</span>
  66. <span v-else> {{ corpTitle }}中...</span>
  67. </el-button>
  68. </el-form>
  69. </el-dialog>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. import { mapGetters } from 'vuex'
  75. import {setTenantId} from "@/utils/auth";
  76. import { createTenant, joinTenant, getOwnCreateTenants, getOwnJoinTenants } from "@/api/system/tenant";
  77. import store from '@/store'
  78. import Homebar from '@/layout/components/Homebar'
  79. export default {
  80. name: 'Mayout',
  81. components: {
  82. Homebar,
  83. },
  84. data() {
  85. return {
  86. loading: false,
  87. showMyTeam: null,
  88. myTeamList: [],
  89. showJoinTeam: null,
  90. joinTeamList: [],
  91. corpTitle: '',
  92. form: {
  93. type: 1,
  94. name: '',
  95. tenantId: '',
  96. },
  97. rules: {
  98. name: [
  99. { required: true, message: '请输入你的企业/团队名称', trigger: 'blur' },
  100. // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
  101. ],
  102. tenantId: [
  103. { required: true, message: '请输入你的邀请码', trigger: 'blur' },
  104. ],
  105. },
  106. dialogVisible: false,
  107. teamWorkVisible: false,
  108. joinOrCreateVisible: false,
  109. }
  110. },
  111. computed: {
  112. ...mapGetters([
  113. 'tenantId',
  114. ]),
  115. },
  116. created() {
  117. this.getOwnJoinTenantList();
  118. this.getOwnCreateTenantList();
  119. },
  120. methods: {
  121. // 获取我加入的租户列表
  122. getOwnJoinTenantList() {
  123. getOwnJoinTenants().then(response => {
  124. this.joinTeamList = response.data;
  125. })
  126. },
  127. // 获取我创建的租户列表
  128. getOwnCreateTenantList() {
  129. getOwnCreateTenants().then(response => {
  130. this.myTeamList = response.data;
  131. })
  132. },
  133. //切换企业
  134. changeTeam(val) {
  135. console.log(val);
  136. store.dispatch("ChangeTenant", val).then(() => {
  137. this.$modal.msgSuccess("切换成功");
  138. setTenantId(val.id)
  139. setTimeout(() => {
  140. location.reload()
  141. }, 1500)
  142. .catch(() => {});
  143. })
  144. .catch(() => {});
  145. },
  146. joinOrCreateCorp(val) {
  147. this.corpTitle = val;
  148. this.joinOrCreateVisible = true;
  149. },
  150. submitForm(formName) {
  151. this.$refs[formName].validate((valid) => {
  152. if (valid) {
  153. this.loading = true;
  154. console.log(this.form);
  155. if (this.corpTitle == '创建') {
  156. createTenant({ status: 0, name: this.form.name }).then(response => {
  157. this.$modal.msgSuccess("创建成功");
  158. this.loading = false;
  159. this.joinOrCreateVisible = false;
  160. this.getOwnJoinTenantList();
  161. this.getOwnCreateTenantList();
  162. });
  163. }
  164. else {
  165. joinTenant({ corpId: this.form.tenantId }).then(response => {
  166. this.$modal.msgSuccess("加入成功");
  167. this.loading = false;
  168. this.joinOrCreateVisible = false;
  169. this.getOwnJoinTenantList();
  170. this.getOwnCreateTenantList();
  171. });
  172. }
  173. } else {
  174. this.loading = false;
  175. console.log('error submit!!');
  176. return false;
  177. }
  178. });
  179. },
  180. fatherMethod() {
  181. this.dialogVisible = true;
  182. },
  183. showTeamWork() {
  184. this.teamWorkVisible = true;
  185. },
  186. }
  187. }
  188. </script>
  189. <style>
  190. .el-drawer__header {
  191. color: black;
  192. font-size: 20px;
  193. font-weight: 500;
  194. }
  195. .el-drawer__open .el-drawer.btt {
  196. height: auto !important;
  197. top: 45px;
  198. }
  199. </style>
  200. <style lang="scss" scoped>
  201. .el-empty {
  202. padding: 10px 0 !important;
  203. }
  204. .fixed-header {
  205. position: fixed;
  206. top: 0;
  207. right: 0;
  208. z-index: 9;
  209. width: 100%;
  210. transition: width 0.28s;
  211. }
  212. .app-main {
  213. background: #f5f6f8;
  214. bottom: 0;
  215. left: 0;
  216. overflow: auto;
  217. position: absolute;
  218. right: 0;
  219. top: 60px;
  220. padding: 32px;
  221. }
  222. .switch-corp-pane {
  223. min-height: 400px;
  224. .corp-block {
  225. .corp-desc {
  226. color: #525967;
  227. margin-bottom: 10px;
  228. }
  229. .corp-wrapper {
  230. border-radius: 4px;
  231. box-shadow: 0 1px 6px 0 rgba(0, 0, 0, .1);
  232. margin-bottom: 12px;
  233. max-height: 200px;
  234. overflow: auto;
  235. .corp-item {
  236. align-items: center;
  237. display: flex;
  238. height: 50px;
  239. justify-content: space-between;
  240. line-height: 50px;
  241. .is-owner {
  242. font-size: 18px;
  243. font-weight: 700;
  244. }
  245. .corp-name {
  246. flex: auto;
  247. max-width: 350px;
  248. overflow: hidden;
  249. padding: 0 30px;
  250. text-overflow: ellipsis;
  251. white-space: nowrap;
  252. }
  253. .corp-op {
  254. flex: none;
  255. .style-text {
  256. padding: 0 16px;
  257. }
  258. .op-current {
  259. color: #838892;
  260. padding-right: 20px;
  261. }
  262. }
  263. }
  264. }
  265. .corp-switch-btn {
  266. text-align: center;
  267. width: 100%;
  268. }
  269. }
  270. }
  271. </style>