Skip to content

Commit

Permalink
Merge pull request #136 from ArtisanCloud/dev/michaelhu
Browse files Browse the repository at this point in the history
feat(oa): media with voice type
  • Loading branch information
Matrix-X authored Nov 26, 2023
2 parents c28d891 + 3e53b8e commit a7d32e4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/api/wechat/official-account/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function GetMedia(request: GetMediaRequest) {
`${PrefixUriAdmin + UriOAMedia}/${request.mediaId}`,
);
}
export function GetMediaByVideo(request: GetMediaRequest) {
return axios.get<GetMediaReply>(
`${PrefixUriAdmin + UriOAMedia}/video/${request.mediaId}`,
);
}

export interface GetMediaOtherListRequest {
type: string;
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import globalComponents from '@/components';
import WujieVue from 'wujie-vue3';
import { loadPluginRoutes } from '@/router/routes';
import WeyUI from '@yaoyaochi/weyui';
// import '@yaoyaochi/weyui/lib/style.css';
import router from './router';
import store from './store';
import i18n from './locale';
Expand All @@ -23,6 +25,7 @@ app.use(i18n);
app.use(globalComponents);
app.use(directive);
app.use(WujieVue);
app.use(WeyUI);

app.mount('#app');

Expand Down
48 changes: 34 additions & 14 deletions src/views/wechat/official-account/media/index.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
<template>
<div class="content">
<w-offi-account-media
<w-media
:action="`${PrefixUriAdmin + UriOAMedia}/upload`"
:headers="header"
:media-data="mediaData"
:total="total"
:current="current"
:page-size="pageSize"
:page-size-options="[5, 10, 20, 30, 50, 100]"
:tem-url="temUrl"
:preview-url="temUrl"
@on-down-load="downLoadImage"
@on-delete="onDeleteMedia"
@page-change="pageChange"
@page-size-change="pageSizeChange"
@onChangeTab="onChangeTab"
@onPreview="onPreview"
@on-upload-success="onUploadSuccess"
/>
</div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { WOffiAccountMedia } from '@yaoyaochi/weyui';
import { WMedia } from '@yaoyaochi/weyui';
import {
DeleteMedia,
GetMedia,
GetMediaByVideo,
GetMediaOtherList,
UriOAMedia,
} from '@/api/wechat/official-account/media';
Expand All @@ -49,26 +51,39 @@
offset: current.value,
count: pageSize.value,
});
console.log(res);
// console.log(res);
mediaData.value.item = res.data.item;
total.value = res.data.total_count;
// console.log(total.value);
};
const getMediaById = async (mediaId: string, type: string) => {
// 获取素材
const res: any = await GetMedia({ mediaId });
if ((res.data && type === 'video') || type === 'news') {
temUrl.value = res.data.data.down_url;
return;
}
if (res.data) {
temUrl.value = URL.createObjectURL(res.data);
// console.log(mediaId, type);
// if ((res.data && type === 'video') || type === 'news') {
if (type === 'video') {
const res: any = await GetMediaByVideo({ mediaId });
temUrl.value = res.data.down_url;
// console.log(temUrl);
} else {
const res: any = await GetMedia({ mediaId });
// 将 Base64 字符串转换为 Uint8Array
const arrayBuffer = Uint8Array.from(atob(res.data.media), (c) =>
c.charCodeAt(0),
);
// 创建 Blob 对象
const blob = new Blob([arrayBuffer], {
type: 'application/octet-stream',
});
temUrl.value = URL.createObjectURL(blob);
}
};
const onDeleteMedia = async (itemId: string) => {
// 删除图片
console.log(itemId);
// console.log(itemId);
const res = await DeleteMedia({ mediaId: itemId });
if (res.data.success) {
await refreshMediaList(dataType.value);
Expand All @@ -79,11 +94,16 @@
// 切换tab
dataType.value = item;
await refreshMediaList(item);
console.log(dataType.value);
// console.log(dataType.value);
};
const downLoadImage = (item: any) => {
// 获取图片URL
console.log(item);
// console.log(item);
};
const onUploadSuccess = async () => {
// console.log('onUploadSuccess', dataType.value);
await refreshMediaList(dataType.value);
};
const deleteImg = (item: any) => {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
"@/*": ["src/*"]
},
"lib": ["es2020", "dom"],
"skipLibCheck": true
"skipLibCheck": true,
"types": [
"node",
"@yaoyaochi/weyui/components.d.ts",
]
},
"include": ["src/**/*.ts", "src/**/*.vue"],
"exclude": ["src/**/*.js", "src/**/*.vue.js","node_modules"]
Expand Down

0 comments on commit a7d32e4

Please sign in to comment.