解绑微信
This commit is contained in:
parent
ae345f232d
commit
5b5e7a5dd3
|
@ -16,37 +16,43 @@
|
|||
//var that=this
|
||||
// 小程序自动登录
|
||||
uni.showLoading({
|
||||
title:'微信自动登录中...',
|
||||
title: '微信自动登录中...',
|
||||
mask: true
|
||||
})
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (loginRes)=>{
|
||||
this.$u.api.wxmplogin({code:loginRes.code}).then(res=>{
|
||||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res=>{
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:"登录成功",
|
||||
icon:"none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:"/pages/home/home"
|
||||
})
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
})
|
||||
}).catch(e=>{
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:"暂未绑定微信!",
|
||||
icon:"none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:'/pages/login/login'
|
||||
})})
|
||||
}
|
||||
provider: 'weixin',
|
||||
success: (loginRes) => {
|
||||
this.$u.api.wxmplogin({
|
||||
code: loginRes.code
|
||||
}).then(res => {
|
||||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: "登录成功",
|
||||
icon: "none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url: "/pages/home/home"
|
||||
})
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
// 修改资源请求地址
|
||||
this.$u.vuex('vuex_user.avatar', this.vuex_user.avatar +
|
||||
'?token=' + this.vuex_token)
|
||||
})
|
||||
}).catch(e => {
|
||||
uni.hideLoading()
|
||||
// uni.showToast({
|
||||
// title: "暂未绑定微信!",
|
||||
// icon: "none"
|
||||
// })
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -54,4 +60,4 @@
|
|||
<style lang="scss">
|
||||
@import "uview-ui/index.scss";
|
||||
@import "common/demo.scss";
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -23,6 +23,8 @@ const install = (Vue, vm) => {
|
|||
|
||||
let bindmp = (params = {}) => vm.$u.post('/system/user/bindwxmp/', params); //微信绑定
|
||||
|
||||
let unbindmp = (params = {}) => vm.$u.post('/system/user/unbindwxmp/', params); //微信绑定
|
||||
|
||||
let getMyInspectTaskList = (params = {}) => vm.$u.get('/quality/subinspecttask/self/', params);
|
||||
|
||||
let getSubinspectTask = (id, params)=> vm.$u.get(`/quality/subinspecttask/${id}/`, params);
|
||||
|
@ -49,6 +51,7 @@ const install = (Vue, vm) => {
|
|||
login,
|
||||
wxmplogin,
|
||||
bindmp,
|
||||
unbindmp,
|
||||
getMyInspectTaskList,
|
||||
getSubinspectTask,
|
||||
getSubtaskDepts,
|
||||
|
|
|
@ -45,24 +45,22 @@ const install = (Vue, vm) => {
|
|||
return res;
|
||||
}
|
||||
else if(res.code === 401){
|
||||
vm.$u.toast('验证失败,请重新登录');
|
||||
uni.showToast({
|
||||
title: "验证失败,请重新登录!",
|
||||
icon: "none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:'/pages/login/login'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
if(typeof(res.msg)=='string'){
|
||||
vm.$u.toast(res.msg)
|
||||
}else{
|
||||
let msg = JSON.stringify(res.msg)
|
||||
vm.$u.toast(res.msg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: "none"
|
||||
})
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,10 +77,11 @@
|
|||
for (var i = 0; i < res.data.imgs_.length; i++) {
|
||||
fileList.push({
|
||||
id: res.data.imgs_[i].id,
|
||||
url: res.data.imgs_[i].file
|
||||
url: res.data.imgs_[i].file + '?token='+ this.vuex_token
|
||||
})
|
||||
}
|
||||
this.fileList = fileList
|
||||
console.log(this.fileList)
|
||||
})
|
||||
},
|
||||
submit() {
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
</u-form-item>
|
||||
</u-form>
|
||||
<!-- <button :style="[inputStyle]" class="getCaptcha">登录</button> -->
|
||||
<!-- <u-gap height="0.5" bg-color="#bbb"></u-gap> -->
|
||||
<view style="margin-top: 16rpx;">
|
||||
<u-button @click="submit" type="warning" >登录</u-button>
|
||||
<!-- <u-gap height="0.5" bg-color="#bbb"></u-gap> -->
|
||||
<view style="margin-top: 16rpx;">
|
||||
<u-button @click="submit" type="warning">登录</u-button>
|
||||
</view>
|
||||
<view class="alternative">
|
||||
<navigator url="login_password" class="password" open-type="navigate">密码登录</navigator>
|
||||
|
@ -24,7 +24,9 @@
|
|||
</view>
|
||||
<u-verification-code seconds="30" ref="uCode" @change="codeChange"></u-verification-code>
|
||||
<view style="text-align: center;">
|
||||
<view class="icon"><u-icon size="70" name="weixin-fill" color="rgb(83,194,64)" @click="mpLogin"></u-icon></view>
|
||||
<view class="icon">
|
||||
<u-icon size="70" name="weixin-fill" color="rgb(83,194,64)" @click="mpLogin"></u-icon>
|
||||
</view>
|
||||
微信登录
|
||||
</view>
|
||||
<!-- <view class="buttom">
|
||||
|
@ -43,215 +45,225 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
imageURL: '/static/banner3.jpg',
|
||||
loginForm:{
|
||||
mail:"",
|
||||
msg:""
|
||||
},
|
||||
codeTips:"获取验证码",
|
||||
rules:{
|
||||
mail:[
|
||||
{
|
||||
required: true,
|
||||
message: '请输入邮箱号',
|
||||
trigger: ['change','blur'],
|
||||
},
|
||||
{
|
||||
// 正则不能含有两边的引号
|
||||
pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
|
||||
message: '格式有误',
|
||||
trigger: ['change','blur'],
|
||||
}
|
||||
// {
|
||||
// // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
|
||||
// validator: (rule, value, callback) => {
|
||||
// // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
|
||||
// return this.$u.test.idCard(value);
|
||||
// },
|
||||
// message: '格式有误',
|
||||
// // 触发器可以同时用blur和change,二者之间用英文逗号隔开
|
||||
// trigger: ['change','blur'],
|
||||
// }
|
||||
],
|
||||
msg:[
|
||||
{
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
imageURL: '/static/banner3.jpg',
|
||||
loginForm: {
|
||||
mail: "",
|
||||
msg: ""
|
||||
},
|
||||
codeTips: "获取验证码",
|
||||
rules: {
|
||||
mail: [{
|
||||
required: true,
|
||||
message: '请输入邮箱号',
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
{
|
||||
// 正则不能含有两边的引号
|
||||
pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
|
||||
message: '格式有误',
|
||||
trigger: ['change', 'blur'],
|
||||
}
|
||||
// {
|
||||
// // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
|
||||
// validator: (rule, value, callback) => {
|
||||
// // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
|
||||
// return this.$u.test.idCard(value);
|
||||
// },
|
||||
// message: '格式有误',
|
||||
// // 触发器可以同时用blur和change,二者之间用英文逗号隔开
|
||||
// trigger: ['change','blur'],
|
||||
// }
|
||||
],
|
||||
msg: [{
|
||||
required: true,
|
||||
message: '请输入验证码',
|
||||
trigger: ['change','blur'],
|
||||
},
|
||||
]
|
||||
},
|
||||
errorType: ['message'],
|
||||
}
|
||||
},
|
||||
onReady() {
|
||||
this.$refs.uForm.setRules(this.rules);
|
||||
uni.hideHomeButton()
|
||||
},
|
||||
computed: {
|
||||
inputStyle() {
|
||||
let style = {};
|
||||
if(this.loginForm.mail && this.loginForm.msg) {
|
||||
style.color = "#fff";
|
||||
style.backgroundColor = this.$u.color['warning'];
|
||||
trigger: ['change', 'blur'],
|
||||
}, ]
|
||||
},
|
||||
errorType: ['message'],
|
||||
}
|
||||
return style;
|
||||
},
|
||||
submitEnable(){
|
||||
if(this.loginForm.mail && this.loginForm.msg) {
|
||||
return false;
|
||||
onReady() {
|
||||
this.$refs.uForm.setRules(this.rules);
|
||||
uni.hideHomeButton()
|
||||
},
|
||||
computed: {
|
||||
inputStyle() {
|
||||
let style = {};
|
||||
if (this.loginForm.mail && this.loginForm.msg) {
|
||||
style.color = "#fff";
|
||||
style.backgroundColor = this.$u.color['warning'];
|
||||
}
|
||||
return style;
|
||||
},
|
||||
submitEnable() {
|
||||
if (this.loginForm.mail && this.loginForm.msg) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
this.$refs.uForm.validate(valid => {
|
||||
if (valid) {
|
||||
uni.showLoading({
|
||||
})
|
||||
this.$u.api.codeLogin(this.loginForm).then(res=>{
|
||||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res=>{
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
this.$refs.uForm.validate(valid => {
|
||||
if (valid) {
|
||||
uni.showLoading({})
|
||||
this.$u.api.codeLogin(this.loginForm).then(res => {
|
||||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res => {
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
// 修改资源请求地址
|
||||
this.$u.vuex('vuex_user.avatar', this.vuex_user.avatar +
|
||||
'?token=' + this.vuex_token)
|
||||
uni.hideLoading()
|
||||
})
|
||||
uni.reLaunch({
|
||||
url: '/pages/home/home'
|
||||
})
|
||||
}).catch(e => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:'/pages/home/home'
|
||||
})
|
||||
}).catch(e=>{uni.hideLoading()})
|
||||
}
|
||||
});
|
||||
},
|
||||
codeChange(text) {
|
||||
this.codeTips = text;
|
||||
},
|
||||
// 获取验证码
|
||||
getCode() {
|
||||
if(this.$refs.uCode.canGetCode && this.loginForm.mail) {
|
||||
}
|
||||
});
|
||||
},
|
||||
codeChange(text) {
|
||||
this.codeTips = text;
|
||||
},
|
||||
// 获取验证码
|
||||
getCode() {
|
||||
if (this.$refs.uCode.canGetCode && this.loginForm.mail) {
|
||||
uni.showLoading({
|
||||
title: '正在获取验证码',
|
||||
mask: true
|
||||
})
|
||||
this.$u.api.getCode(this.loginForm).then(res => {
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
// 这里此提示会被this.start()方法中的提示覆盖
|
||||
this.$u.toast('验证码已发送');
|
||||
// 通知验证码组件内部开始倒计时
|
||||
this.$refs.uCode.start();
|
||||
}, 2000);
|
||||
})
|
||||
} else {
|
||||
this.$u.toast('倒计时结束后再发送');
|
||||
}
|
||||
},
|
||||
mpLogin() {
|
||||
uni.showLoading({
|
||||
title: '正在获取验证码',
|
||||
title: '微信登录中...',
|
||||
mask: true
|
||||
})
|
||||
this.$u.api.getCode(this.loginForm).then(res=>{
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
// 这里此提示会被this.start()方法中的提示覆盖
|
||||
this.$u.toast('验证码已发送');
|
||||
// 通知验证码组件内部开始倒计时
|
||||
this.$refs.uCode.start();
|
||||
}, 2000);
|
||||
})
|
||||
} else {
|
||||
this.$u.toast('倒计时结束后再发送');
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (loginRes) => {
|
||||
this.$u.api.wxmplogin({
|
||||
code: loginRes.code
|
||||
}).then(res => {
|
||||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: "登录成功",
|
||||
icon: "none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url: "/pages/home/home"
|
||||
})
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
// 修改资源请求地址
|
||||
this.$u.vuex('vuex_user.avatar', this.vuex_user.avatar +
|
||||
'?token=' + this.vuex_token)
|
||||
})
|
||||
}).catch(e => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: "暂未绑定微信!",
|
||||
icon: "none"
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
mpLogin(){
|
||||
uni.showLoading({
|
||||
title:'微信登录中...',
|
||||
mask: true
|
||||
})
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (loginRes)=>{
|
||||
this.$u.api.wxmplogin({code:loginRes.code}).then(res=>{
|
||||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res=>{
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:"登录成功",
|
||||
icon:"none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:"/pages/home/home"
|
||||
})
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
})
|
||||
}).catch(e=>{
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:"暂未绑定微信!",
|
||||
icon:"none"
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:'/pages/login/login'
|
||||
})})
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrap {
|
||||
font-size: 28rpx;
|
||||
.content {
|
||||
width: 90%;
|
||||
margin: 40rpx auto 0;
|
||||
.wrap {
|
||||
font-size: 28rpx;
|
||||
|
||||
.title {
|
||||
text-align: center;
|
||||
font-size: 40rpx;
|
||||
font-weight: 500;
|
||||
margin-bottom: 100rpx;
|
||||
}
|
||||
input {
|
||||
text-align: left;
|
||||
margin-bottom: 10rpx;
|
||||
padding-bottom: 6rpx;
|
||||
}
|
||||
.tips {
|
||||
color: $u-type-info;
|
||||
margin-bottom: 60rpx;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
.getCaptcha {
|
||||
background-color: rgb(253, 243, 208);
|
||||
color: $u-tips-color;
|
||||
border: none;
|
||||
font-size: 30rpx;
|
||||
padding: 12rpx 0;
|
||||
margin-top:6rpx;
|
||||
|
||||
&::after {
|
||||
.content {
|
||||
width: 90%;
|
||||
margin: 40rpx auto 0;
|
||||
|
||||
.title {
|
||||
text-align: center;
|
||||
font-size: 40rpx;
|
||||
font-weight: 500;
|
||||
margin-bottom: 100rpx;
|
||||
}
|
||||
|
||||
input {
|
||||
text-align: left;
|
||||
margin-bottom: 10rpx;
|
||||
padding-bottom: 6rpx;
|
||||
}
|
||||
|
||||
.tips {
|
||||
color: $u-type-info;
|
||||
margin-bottom: 60rpx;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.getCaptcha {
|
||||
background-color: rgb(253, 243, 208);
|
||||
color: $u-tips-color;
|
||||
border: none;
|
||||
font-size: 30rpx;
|
||||
padding: 12rpx 0;
|
||||
margin-top: 6rpx;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
.alternative {
|
||||
color: $u-tips-color;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
}
|
||||
.buttom {
|
||||
.loginType {
|
||||
display: flex;
|
||||
padding: 350rpx 150rpx 150rpx 150rpx;
|
||||
justify-content:space-between;
|
||||
|
||||
.item {
|
||||
|
||||
.alternative {
|
||||
color: $u-tips-color;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
color: $u-content-color;
|
||||
font-size: 28rpx;
|
||||
justify-content: space-between;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.hint {
|
||||
padding: 20rpx 40rpx;
|
||||
font-size: 20rpx;
|
||||
color: $u-tips-color;
|
||||
|
||||
.link {
|
||||
color: $u-type-warning;
|
||||
|
||||
.buttom {
|
||||
.loginType {
|
||||
display: flex;
|
||||
padding: 350rpx 150rpx 150rpx 150rpx;
|
||||
justify-content: space-between;
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
color: $u-content-color;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.hint {
|
||||
padding: 20rpx 40rpx;
|
||||
font-size: 20rpx;
|
||||
color: $u-tips-color;
|
||||
|
||||
.link {
|
||||
color: $u-type-warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -81,6 +81,10 @@ export default {
|
|||
this.$u.vuex('vuex_token', res.data.access)
|
||||
this.$u.api.getUserInfo().then(res=>{
|
||||
this.$u.vuex('vuex_user', res.data)
|
||||
// 修改资源请求地址
|
||||
this.$u.vuex('vuex_user.avatar', this.vuex_user.avatar +
|
||||
'?token=' + this.vuex_token)
|
||||
console.log(this.vuex_user)
|
||||
})
|
||||
uni.reLaunch({
|
||||
url:'/pages/home/home'
|
||||
|
|
|
@ -61,10 +61,14 @@
|
|||
},
|
||||
methods: {
|
||||
Logout(){
|
||||
this.$u.vuex('vuex_token', '')
|
||||
uni.redirectTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
this.$u.api.unbindmp().then(res=>{
|
||||
this.$u.vuex('vuex_token', '')
|
||||
uni.redirectTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}
|
||||
)
|
||||
|
||||
},
|
||||
bindMP(){
|
||||
uni.login({
|
||||
|
|
|
@ -352,7 +352,14 @@ class UserViewSet(PageOrNot, ModelViewSet):
|
|||
UserThird.objects.get_or_create(openid=openid, type='wx_mp', user=request.user, defaults={'openid':openid, 'user':request.user, 'type':'wx_mp'})
|
||||
return Response({'wxmp_openid':openid},status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@action(methods=['post'], detail=False, permission_classes=[IsAuthenticated])
|
||||
def unbindwxmp(self, request, pk=None):
|
||||
"""
|
||||
解除微信绑定
|
||||
"""
|
||||
UserThird.objects.filter(user=request.user, type='wx_mp').delete()
|
||||
return Response()
|
||||
|
||||
class WXMPlogin(APIView):
|
||||
authentication_classes=[]
|
||||
permission_classes=[]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class VodConfig(AppConfig):
|
||||
name = 'vod'
|
|
@ -0,0 +1,24 @@
|
|||
from django.db import models
|
||||
from utils.model import BaseModel
|
||||
from apps.system.models import User, CommonAModel
|
||||
# Create your models here.
|
||||
|
||||
class Video(CommonAModel):
|
||||
pass
|
||||
|
||||
class WatchRecord(BaseModel):
|
||||
|
||||
# 观看记录
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='观看人')
|
||||
num = models.IntegerField(verbose_name='观看次数', default=0)
|
||||
total = models.IntegerField(verbose_name='观看总时长', default=0)
|
||||
current = models.IntegerField(verbose_name='当前观看进度', default=0)
|
||||
|
||||
vod_id = models.CharField(verbose_name='视频id', max_length=100)
|
||||
vod_title = models.CharField(verbose_name='视频标题', max_length=100)
|
||||
vod_cover = models.CharField(verbose_name='视频封面地址', max_length=200)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '点播观看记录'
|
||||
verbose_name_plural = verbose_name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path, include
|
||||
from .views import ClassView, VideoView
|
||||
from rest_framework import routers
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('class/', ClassView.as_view()),
|
||||
path('video/', VideoView.as_view())
|
||||
]
|
|
@ -0,0 +1,32 @@
|
|||
from django.shortcuts import render
|
||||
from .vodclient import getAllClass, searchMedia
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
# Create your views here.
|
||||
|
||||
class ClassView(APIView):
|
||||
|
||||
perms_map={'get':'*'}
|
||||
def get(self, request, format=None):
|
||||
"""
|
||||
查询分类
|
||||
"""
|
||||
return getAllClass()
|
||||
|
||||
class VideoView(APIView):
|
||||
|
||||
perms_map={'get':'video_view'}
|
||||
def get(self, request, format=None):
|
||||
"""
|
||||
查询视频
|
||||
"""
|
||||
params={'Filters':['basicInfo', 'metaData']}
|
||||
params['Offset'] = request.query_params.get('Offset', 0)
|
||||
params['Limit'] = request.query_params.get('Limit', 20)
|
||||
params['Names'] = request.query_params.getlist('name') if request.query_params.get('name') else []
|
||||
params['ClassIds']= request.query_params.getlist('classid') if request.query_params.get('classid') else []
|
||||
return searchMedia(params)
|
||||
|
||||
class RecordViewSet(ModelViewSet):
|
||||
pass
|
|
@ -0,0 +1,48 @@
|
|||
import json
|
||||
from tencentcloud.common import credential
|
||||
from tencentcloud.common.profile.client_profile import ClientProfile
|
||||
from tencentcloud.common.profile.http_profile import HttpProfile
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
from tencentcloud.vod.v20180717 import vod_client, models
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.status import HTTP_400_BAD_REQUEST
|
||||
SecretId = 'AKIDhDTaV9WeXAXcQxEH4buwg9LGvJQHr9Au'
|
||||
SecretKey = 'VjfKjrhGYrte8MIxMUMxHL9h39zYqrc6'
|
||||
|
||||
# 初始化点播client
|
||||
def initClient():
|
||||
cred = credential.Credential(SecretId, SecretKey)
|
||||
httpProfile = HttpProfile()
|
||||
httpProfile.endpoint = "vod.tencentcloudapi.com"
|
||||
clientProfile = ClientProfile()
|
||||
clientProfile.httpProfile = httpProfile
|
||||
client = vod_client.VodClient(cred, "", clientProfile)
|
||||
return client
|
||||
|
||||
def doResponse(res):
|
||||
# 处理返回结果
|
||||
# 转变为常用返回Response
|
||||
if hasattr(res, 'Error'):
|
||||
return Response(res._serialize(allow_none=True), status=HTTP_400_BAD_REQUEST)
|
||||
return Response(res._serialize(allow_none=True))
|
||||
|
||||
def getAllClass(params={}):
|
||||
# 获取所有分类
|
||||
try:
|
||||
client = initClient()
|
||||
req = models.DescribeAllClassRequest()
|
||||
req.from_json_string(json.dumps(params))
|
||||
resp = client.DescribeAllClass(req)
|
||||
return doResponse(resp)
|
||||
except TencentCloudSDKException as err:
|
||||
print(err)
|
||||
|
||||
def searchMedia(params={}):
|
||||
try:
|
||||
client = initClient()
|
||||
req = models.SearchMediaRequest()
|
||||
req.from_json_string(json.dumps(params))
|
||||
resp = client.SearchMedia(req)
|
||||
return doResponse(resp)
|
||||
except TencentCloudSDKException as err:
|
||||
print(err)
|
|
@ -45,7 +45,8 @@ INSTALLED_APPS = [
|
|||
'apps.crm',
|
||||
'apps.ability',
|
||||
'apps.supervision',
|
||||
'apps.quality'
|
||||
'apps.quality',
|
||||
'apps.vod'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -47,6 +47,7 @@ urlpatterns = [
|
|||
path('api/ability/', include('apps.ability.urls')),
|
||||
path('api/supervision/', include('apps.supervision.urls')),
|
||||
path('api/quality/', include('apps.quality.urls')),
|
||||
path('api/vod/', include('apps.vod.urls')),
|
||||
path('api/docs/', include_docs_urls(title="接口文档",authentication_classes=[], permission_classes=[])),
|
||||
path('api/', include(router.urls)),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
|
Loading…
Reference in New Issue