parent
							
								
									6bf257eb23
								
							
						
					
					
						commit
						ad8cf4f0fc
					
				| 
						 | 
				
			
			@ -206,7 +206,7 @@ class OperationLog(CoreModel):
 | 
			
		|||
def media_file_name(instance, filename):
 | 
			
		||||
    h = instance.md5sum
 | 
			
		||||
    basename, ext = os.path.splitext(filename)
 | 
			
		||||
    return os.path.join('media/files', h[0:1], h[1:2], h + ext.lower())
 | 
			
		||||
    return os.path.join('files', h[0:1], h[1:2], h + ext.lower())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FileList(CoreModel):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ class FileSerializer(CustomModelSerializer):
 | 
			
		|||
    url = serializers.SerializerMethodField(read_only=True)
 | 
			
		||||
 | 
			
		||||
    def get_url(self, instance):
 | 
			
		||||
        return str(instance.url)
 | 
			
		||||
        return  'media/'+str(instance.url)
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = FileList
 | 
			
		||||
| 
						 | 
				
			
			@ -41,3 +41,4 @@ class FileViewSet(CustomModelViewSet):
 | 
			
		|||
    queryset = FileList.objects.all()
 | 
			
		||||
    serializer_class = FileSerializer
 | 
			
		||||
    filter_fields = ['name', ]
 | 
			
		||||
    permission_classes = []
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,6 +88,7 @@ class LoginSerializer(TokenObtainPairSerializer):
 | 
			
		|||
        data = super().validate(attrs)
 | 
			
		||||
        data['name'] = self.user.name
 | 
			
		||||
        data['userId'] = self.user.id
 | 
			
		||||
        data['avatar'] = self.user.avatar
 | 
			
		||||
        return {
 | 
			
		||||
            "code": 2000,
 | 
			
		||||
            "msg": "请求成功",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -156,7 +156,8 @@ class UserViewSet(CustomModelViewSet):
 | 
			
		|||
            "name": user.name,
 | 
			
		||||
            "mobile": user.mobile,
 | 
			
		||||
            "gender": user.gender,
 | 
			
		||||
            "email": user.email
 | 
			
		||||
            "email": user.email,
 | 
			
		||||
            'avatar':user.avatar
 | 
			
		||||
        }
 | 
			
		||||
        return DetailResponse(data=result, msg="获取成功")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,7 @@
 | 
			
		|||
        注销
 | 
			
		||||
      </el-dropdown-item>
 | 
			
		||||
    </el-dropdown-menu>
 | 
			
		||||
    <el-image v-if="info.avatar" :src="info.avatar" :preview-src-list="[info.avatar]" style="width: 20px;height: 20px" alt="头像"></el-image>
 | 
			
		||||
  </el-dropdown>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,21 @@
 | 
			
		|||
              :label-position="position"
 | 
			
		||||
              center
 | 
			
		||||
            >
 | 
			
		||||
              <el-form-item prop="avatar" required label="头像">
 | 
			
		||||
                <el-upload
 | 
			
		||||
                  class="avatar-uploader"
 | 
			
		||||
                  list-type="picture-card"
 | 
			
		||||
                  :file-list="fileList"
 | 
			
		||||
                  :action="action"
 | 
			
		||||
                  :headers="headers"
 | 
			
		||||
                  :limit="1"
 | 
			
		||||
                  :disabled="fileList.length===1"
 | 
			
		||||
                  :on-success="handleAvatarSuccess">
 | 
			
		||||
<!--                  <el-image v-if="userInfo.avatar" :src="userInfo.avatar" :preview-src-list="[userInfo.avatar]" style="width: 100px;height: 100px" alt="头像"></el-image>-->
 | 
			
		||||
<!--                  <i v-else class="el-icon-plus avatar-uploader-icon" style="width: 100px;height: 100px"></i>-->
 | 
			
		||||
                  <i class="el-icon-plus"></i>
 | 
			
		||||
                </el-upload>
 | 
			
		||||
              </el-form-item>
 | 
			
		||||
              <el-form-item prop="name" required label="昵称">
 | 
			
		||||
                <el-input v-model="userInfo.name" clearable></el-input>
 | 
			
		||||
              </el-form-item>
 | 
			
		||||
| 
						 | 
				
			
			@ -130,6 +145,11 @@ export default {
 | 
			
		|||
    return {
 | 
			
		||||
      position: 'left',
 | 
			
		||||
      activeName: 'userInfo',
 | 
			
		||||
      action: util.baseURL() + 'api/system/file/',
 | 
			
		||||
      headers: {
 | 
			
		||||
        Authorization: 'JWT ' + util.cookies.get('token')
 | 
			
		||||
      },
 | 
			
		||||
      fileList:[],
 | 
			
		||||
      userInfo: {
 | 
			
		||||
        name: '',
 | 
			
		||||
        gender: '',
 | 
			
		||||
| 
						 | 
				
			
			@ -177,6 +197,7 @@ export default {
 | 
			
		|||
        params: {}
 | 
			
		||||
      }).then((res) => {
 | 
			
		||||
        _self.userInfo = res.data
 | 
			
		||||
        _self.fileList = [{name:'avatar.png',url:res.data.avatar}]
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -251,6 +272,16 @@ export default {
 | 
			
		|||
          this.$message.error('表单校验失败,请检查')
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    /**
 | 
			
		||||
     * 头像上传
 | 
			
		||||
     * @param res
 | 
			
		||||
     * @param file
 | 
			
		||||
     */
 | 
			
		||||
    handleAvatarSuccess(res, file) {
 | 
			
		||||
      console.log(11,res)
 | 
			
		||||
      this.fileList =[{ url: util.baseURL() + res.data.url, name:file.name }]
 | 
			
		||||
      this.userInfo.avatar = util.baseURL() + res.data.url;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,25 +88,25 @@ const frameIn = [{
 | 
			
		|||
    //   component: _import('system/user')
 | 
			
		||||
    // },
 | 
			
		||||
    // // 系统 按钮配置
 | 
			
		||||
    {
 | 
			
		||||
      path: 'button',
 | 
			
		||||
      name: 'button',
 | 
			
		||||
      meta: {
 | 
			
		||||
        title: '按钮',
 | 
			
		||||
        auth: true
 | 
			
		||||
      },
 | 
			
		||||
      component: _import('system/button')
 | 
			
		||||
    },
 | 
			
		||||
    // // 系统 菜单权限
 | 
			
		||||
    {
 | 
			
		||||
      path: 'menuButton/:id',
 | 
			
		||||
      name: 'menuButton',
 | 
			
		||||
      meta: {
 | 
			
		||||
        title: '菜单按钮',
 | 
			
		||||
        auth: true
 | 
			
		||||
      },
 | 
			
		||||
      component: _import('system/menuButton')
 | 
			
		||||
    },
 | 
			
		||||
    // {
 | 
			
		||||
    //   path: 'button',
 | 
			
		||||
    //   name: 'button',
 | 
			
		||||
    //   meta: {
 | 
			
		||||
    //     title: '按钮',
 | 
			
		||||
    //     auth: true
 | 
			
		||||
    //   },
 | 
			
		||||
    //   component: _import('system/button')
 | 
			
		||||
    // },
 | 
			
		||||
    // // // 系统 菜单权限
 | 
			
		||||
    // {
 | 
			
		||||
    //   path: 'menuButton/:id',
 | 
			
		||||
    //   name: 'menuButton',
 | 
			
		||||
    //   meta: {
 | 
			
		||||
    //     title: '菜单按钮',
 | 
			
		||||
    //     auth: true
 | 
			
		||||
    //   },
 | 
			
		||||
    //   component: _import('system/menuButton')
 | 
			
		||||
    // },
 | 
			
		||||
    // // 系统 角色管理
 | 
			
		||||
    // {
 | 
			
		||||
    //   path: 'role',
 | 
			
		||||
| 
						 | 
				
			
			@ -149,15 +149,15 @@ const frameIn = [{
 | 
			
		|||
    //   component: _import('system/log/operationLog')
 | 
			
		||||
    // },
 | 
			
		||||
    // 系统 前端日志
 | 
			
		||||
    {
 | 
			
		||||
      path: 'frontendLog',
 | 
			
		||||
      name: 'frontendLog',
 | 
			
		||||
      meta: {
 | 
			
		||||
        title: '前端日志',
 | 
			
		||||
        auth: true
 | 
			
		||||
      },
 | 
			
		||||
      component: _import('system/log/frontendLog')
 | 
			
		||||
    },
 | 
			
		||||
    // {
 | 
			
		||||
    //   path: 'frontendLog',
 | 
			
		||||
    //   name: 'frontendLog',
 | 
			
		||||
    //   meta: {
 | 
			
		||||
    //     title: '前端日志',
 | 
			
		||||
    //     auth: true
 | 
			
		||||
    //   },
 | 
			
		||||
    //   component: _import('system/log/frontendLog')
 | 
			
		||||
    // },
 | 
			
		||||
    // 刷新页面 必须保留
 | 
			
		||||
    {
 | 
			
		||||
      path: 'refresh',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,7 +42,7 @@ export default {
 | 
			
		|||
      util.cookies.set('token', res.access)
 | 
			
		||||
      util.cookies.set('refresh', res.refresh)
 | 
			
		||||
      // 设置 vuex 用户信息
 | 
			
		||||
      await dispatch('d2admin/user/set', { name: res.name, user_id: res.userId }, { root: true })
 | 
			
		||||
      await dispatch('d2admin/user/set', { name: res.name, user_id: res.userId,avatar:res.avatar }, { root: true })
 | 
			
		||||
      // 用户登录后从持久化数据加载一系列的设置
 | 
			
		||||
      await dispatch('load')
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ import { BUTTON_STATUS_BOOL } from '@/config/button'
 | 
			
		|||
import { urlPrefix as deptPrefix } from '../dept/api'
 | 
			
		||||
import util from '@/libs/util'
 | 
			
		||||
 | 
			
		||||
const uploadUrl = util.baseURL() + 'api/system/img/'
 | 
			
		||||
const uploadUrl = util.baseURL() + 'api/system/file/'
 | 
			
		||||
export const crudOptions = (vm) => {
 | 
			
		||||
  return {
 | 
			
		||||
    pageOptions: {
 | 
			
		||||
| 
						 | 
				
			
			@ -261,7 +261,6 @@ export const crudOptions = (vm) => {
 | 
			
		|||
            props: {
 | 
			
		||||
              uploader: {
 | 
			
		||||
                action: uploadUrl,
 | 
			
		||||
                name: 'url',
 | 
			
		||||
                headers: {
 | 
			
		||||
                  Authorization: 'JWT ' + util.cookies.get('token')
 | 
			
		||||
                },
 | 
			
		||||
| 
						 | 
				
			
			@ -270,7 +269,7 @@ export const crudOptions = (vm) => {
 | 
			
		|||
                  if (ret.data === null || ret.data === '') {
 | 
			
		||||
                    throw new Error('上传失败')
 | 
			
		||||
                  }
 | 
			
		||||
                  return { url: ret.data.data.url, key: option.data.key }
 | 
			
		||||
                  return { url: util.baseURL() + ret.data.url, key: option.data.key }
 | 
			
		||||
                }
 | 
			
		||||
              },
 | 
			
		||||
              elProps: { // 与el-uploader 配置一致
 | 
			
		||||
| 
						 | 
				
			
			@ -297,7 +296,7 @@ export const crudOptions = (vm) => {
 | 
			
		|||
          props: {
 | 
			
		||||
            buildUrl (value, item) {
 | 
			
		||||
              if (value && value.indexOf('http') !== 0) {
 | 
			
		||||
                return '/api/upload/form/download?key=' + value
 | 
			
		||||
                return util.baseURL() + value
 | 
			
		||||
              }
 | 
			
		||||
              return value
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue