123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <template>
- <div id="app">
- <div class="top">
- <p v-if="account">{{ '欢迎 ' + account.displayName }}</p>
- <p v-else>欢迎使用野火IM工作台</p>
- </div>
- <div v-if="!showManageFavApp" class="apps-container">
- <div class="title-action-container">
- <p class="title">我的</p>
- <p class="action" @click="showManageFavAppView">管理</p>
- </div>
- <div class="apps">
- <div v-for="(app, index) in favApps" :key="index" class="app" @click="openApp(app)">
- <img :src="app.portraitUrl">
- <p>{{ app.name }}</p>
- </div>
- </div>
- <p v-if="favApps.length === 0" class="empty">没有应用,请点击管理按钮进行配置</p>
- </div>
- <div v-if="showManageFavApp" class="apps-container">
- <div class="title-action-container">
- <p class="title">管理</p>
- <div class="action-container">
- <p class="action" @click="cancelManageFavApp">取消</p>
- <p class="action" @click="manageFavApp">确定</p>
- </div>
- </div>
- <div class="apps">
- <div v-for="(app, index) in apps" :key="index" class="app" :class="{checked: app._checked}" @click="checkApp(app)">
- <img :src="app.portraitUrl">
- <p>{{ app.name }}</p>
- <input type="checkbox" :value="app.targetId" v-model="checkedAppIds">
- </div>
- </div>
- <p v-if="apps.length === 0" class="empty">没有应用,请到开放平台创建</p>
- </div>
- <div class="apps-container">
- <p class="title">全员</p>
- <div class="apps">
- <div v-for="(app, index) in globalApps" :key="index" class="app" @click="openApp(app)">
- <img :src="app.portraitUrl">
- <p>{{ app.name }}</p>
- </div>
- </div>
- <p v-if="globalApps.length === 0" class="empty">没有应用,请到开放平台添加</p>
- </div>
- </div>
- </template>
- <script>
- import wf from "@/jssdk/wf";
- import api from "@/api/api";
- import './jssdk/bridgeClientImpl.uni'
- export default {
- name: 'App',
- data() {
- return {
- account: null,
- favApps: [],
- apps: [], // 非 globalApps
- globalApps: [],
- checkedAppIds: [],
- showManageFavApp: false,
- }
- },
- components: {},
- created() {
- document.title = '野火IM工作台'
- this.getAppList();
- this.getAccount();
- },
- methods: {
- getAccount(failToLogin = true) {
- api.getAccount().then(account => {
- this.account = account;
- this.getFavAppList();
- }).catch(reason => {
- wf.toast('开放平台登录中...')
- if (reason.code === 13 && failToLogin) {
- console.log('getAuthCode and login')
- this.login();
- }
- })
- },
- getAppList() {
- api.getAppList().then((apps) => {
- console.log('apps', apps)
- this.apps = apps.filter(app => app.global !== true)
- this.globalApps = apps.filter(app => app.global === true)
- });
- },
- getFavAppList() {
- api.getFavAppList().then(favApps => {
- this.favApps = favApps;
- this.favApps.forEach(app => {
- this.checkedAppIds.push(app.targetId);
- })
- }).catch(reason => {
- console.log('getFavAppList error', reason)
- })
- },
- login() {
- // type: 0, robot; 1, channel; 2, admin
- wf.biz.getAuthCode('wfcadmin', 2, (authCode) => {
- console.log('getAuthCode success', authCode)
- api.login({
- appId: 'wfcadmin',
- appType: 2,
- authCode: authCode,
- }).then(() => {
- this.getFavAppList(false);
- this.getAccount(false);
- }).catch(reason => {
- console.log('login failed', reason);
- wf.toast('开放平台登录失败 ' + reason);
- })
- }, err => {
- console.log('getAuthCode error', err)
- })
- },
- showManageFavAppView() {
- if (this.account) {
- this.showManageFavApp = true;
- } else {
- console.log('not login, to login')
- this.login();
- }
- },
- openApp(app) {
- let url = process ? app.desktopUrl : app.mobileUrl;
- wf.openUrl(url);
- },
- checkApp(app) {
- let index = this.checkedAppIds.indexOf(app.targetId);
- if (index >= 0) {
- this.checkedAppIds = this.checkedAppIds.filter(id => id !== app.targetId);
- } else {
- this.checkedAppIds.push(app.targetId);
- }
- },
- cancelManageFavApp() {
- this.showManageFavApp = false;
- this.checkedAppIds = [];
- },
- manageFavApp() {
- let toUnFavApps = [];
- let toFavApps = [];
- this.favApps.forEach(app => {
- if (this.checkedAppIds.indexOf(app.targetId) === -1) {
- toUnFavApps.push(app.targetId);
- }
- })
- this.checkedAppIds.forEach(targetId => {
- if (this.favApps.length > 0) {
- if (this.favApps.indexOf(targetId) === -1) {
- toFavApps.push(targetId);
- }
- } else {
- toFavApps.push(targetId);
- }
- })
- console.log('manageFavApp', toFavApps, toUnFavApps);
- let fp = api.favApps(toFavApps);
- let ufp = api.unFavApps(toUnFavApps);
- Promise.all([fp, ufp]).then(value => {
- console.log('manageFavApp result', value);
- this.getFavAppList(false);
- })
- this.showManageFavApp = false;
- this.checkedAppIds = [];
- }
- }
- }
- </script>
- <style lang="css" scoped>
- @import "./assets/main.css";
- body {
- margin: 0;
- padding: 0;
- }
- #app {
- font-family: Avenir, Helvetica, Arial, sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- text-align: center;
- color: #2c3e50;
- background-color: #EDEDED;
- width: 100vw;
- height: 100vh;
- }
- .top {
- height: 60px;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: flex-start;
- background-color: white;
- }
- .top p {
- padding-left: 15px;
- font-size: 18px;
- font-weight: bold;
- }
- .apps-container {
- background-color: white;
- border-radius: 5px;
- margin: 5px;
- }
- .apps-container .title {
- text-align: left;
- padding: 5px;
- }
- .title-action-container {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .title-action-container .action-container {
- display: flex;
- flex-direction: row;
- }
- .title-action-container .action {
- padding: 5px 10px;
- border-radius: 5px;
- }
- .title-action-container .action:active {
- background-color: lightgrey;
- }
- .apps-container .empty {
- padding: 10px 0;
- font-size: 14px;
- }
- .apps {
- display: grid;
- grid-template-columns: repeat(auto-fill, 80px);
- justify-content: space-between;
- }
- .app {
- margin: 5px 0;
- width: 80px;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- padding: 5px 0;
- position: relative;
- }
- .app:active {
- background-color: lightgrey;
- border-radius: 5px;
- }
- .app img {
- width: 40px;
- height: 40px;
- }
- .app p {
- margin: 5px 0 0 0;
- font-size: 12px;
- }
- .app input {
- position: absolute;
- top: 5px;
- left: 5px;
- }
- </style>
|