Browse Source

优化公共逻辑代码

daxiong.yang 7 years ago
parent
commit
f6c033497e

+ 1 - 1
src/api/requestUrl.js

@ -4,5 +4,5 @@
4 4
 */
5 5
export default function (actionName) {
6 6
  // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
7
  return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseURL) + actionName
7
  return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName
8 8
}

+ 6 - 5
src/assets/scss/_base.scss

@ -10,7 +10,7 @@ body {
10 10
  color: #333;
11 11
  background-color: #f0f0f0;
12 12
}
13
:focus {
13
*:focus {
14 14
  outline: 0;
15 15
}
16 16
a {
@ -188,10 +188,11 @@ img {
188 188
.site-sidebar__menu.el-menu {
189 189
  width: 230px;
190 190
  border-right: 0;
191
}
192
.site-sidebar__menu-icon {
193
  margin-right: 5px;
194
  font-size: 18px;
191
  .site-sidebar__menu-icon {
192
    margin-right: 5px;
193
    font-size: 16px;
194
    color: inherit;
195
  }
195 196
}
196 197
/* site-content */
197 198
.site-content__wrapper {

+ 9 - 7
src/components/sub-menu-nav/index.vue

@ -4,7 +4,7 @@
4 4
    :data-idx="menuNav.menuId + ''"
5 5
    :index="menuNav.menuId + ''">
6 6
    <template slot="title">
7
      <icon-svg name="xitong" class="site-sidebar__menu-icon" :class="menuNav.icon"></icon-svg>
7
      <i :class="['site-sidebar__menu-icon', menuNav.icon ? menuNav.icon : 'fa fa-circle-o']"></i>
8 8
      <span>{{ menuNav.name }}</span>
9 9
    </template>
10 10
    <sub-menu-nav
@ -17,26 +17,28 @@
17 17
    v-else
18 18
    :index="menuNav.menuId + ''"
19 19
    :data-idx="menuNav.menuId + ''"
20
    @click="gotoRouteByMenuNav(menuNav)">
21
    {{ menuNav.name }}
20
    @click="gotoRouteHandle(menuNav.url)">
21
    <i :class="['site-sidebar__menu-icon', menuNav.icon ? menuNav.icon : 'fa fa-circle-o']"></i>
22
    <span>{{ menuNav.name }}</span>
22 23
  </el-menu-item>
23 24
</template>
24 25
25 26
<script>
26
  import { getRouteNameByUrl } from '@/utils'
27 27
  import SubMenuNav from '../sub-menu-nav'
28
  import { getRouteNameByUrl } from '@/utils'
28 29
  export default {
29 30
    name: 'sub-menu-nav',
30 31
    props: {
31
      menuNav: Object
32
      menuNav: Object,
33
      required: true
32 34
    },
33 35
    components: {
34 36
      SubMenuNav
35 37
    },
36 38
    methods: {
37 39
      // 跳转到菜单导航对应路由
38
      gotoRouteByMenuNav (menuNav) {
39
        var routeName = getRouteNameByUrl(menuNav.url)
40
      gotoRouteHandle (url) {
41
        var routeName = getRouteNameByUrl(url)
40 42
        if (/\S/.test(routeName)) {
41 43
          this.$router.push({ name: routeName })
42 44
        }

+ 0 - 0
src/filters/index.js


+ 0 - 12
src/store/getters.js

@ -1,12 +0,0 @@
1
export const cartProducts = state => {
2
  return state.cart.added.map(({ id, quantity }) => {
3
    const product = state.products.all.find(p => p.id === id)
4
    return {
5
      title: product.title,
6
      price: product.price,
7
      quantity
8
    }
9
  })
10
}
11
12
export const siteLayoutMini = state => state.siteLayoutMini

+ 3 - 13
src/store/index.js

@ -3,7 +3,6 @@ import Vuex from 'vuex'
3 3
import * as getters from './getters'
4 4
import mutations from './mutations'
5 5
import * as actions from './actions'
6
import home from './modules/home'
7 6
import user from './modules/user'
8 7
9 8
Vue.use(Vuex)
@ -13,19 +12,11 @@ const state = {
13 12
  sidebarCollapse: false,
14 13
  // 页面文档可视高度(随窗口改变大小)
15 14
  documentClientHeight: 0,
16
  // 菜单导航列表
15
  // 菜单导航
17 16
  menuNavList: [],
18 17
  // 内容区域tabs标签页
19
  contentTabs: {
20
    activeName: '',
21
    tabList: []
22
  },
23
  // 菜单导航iframe嵌套地址
24
  menuNavIframeUrl: '//demo.open.renren.io/renren-fast/',
25
  // 菜单导航类型映射表, module: vue重构(默认), iframe: iframe方式嵌套
26
  menuNavTypeMap: {
27
    'sql': 'iframe'
28
  }
18
  contentTabs: [],
19
  contentTabsActiveName: ''
29 20
}
30 21
31 22
export default new Vuex.Store({
@ -34,7 +25,6 @@ export default new Vuex.Store({
34 25
  mutations,
35 26
  actions,
36 27
  modules: {
37
    home,
38 28
    user
39 29
  },
40 30
  strict: process.env.NODE_ENV !== 'production'

+ 0 - 18
src/store/modules/home.js

@ -1,18 +0,0 @@
1
const state = {
2
}
3
4
const getters = {
5
}
6
7
const actions = {
8
}
9
10
const mutations = {
11
}
12
13
export default {
14
  state,
15
  getters,
16
  actions,
17
  mutations
18
}

+ 7 - 5
src/store/modules/user.js

@ -1,9 +1,8 @@
1 1
import * as types from '../mutation-types'
2
import merge from 'lodash/merge'
3 2
4 3
const state = {
5
  userId: '',
6
  userName: ''
4
  id: 0,
5
  name: ''
7 6
}
8 7
9 8
const getters = {
@ -13,8 +12,11 @@ const actions = {
13 12
}
14 13
15 14
const mutations = {
16
  [types.UPDATE_USER_INFO] (state, info) {
17
    state = merge(state, info)
15
  [types.UPDATE_USER_ID] (state, { id }) {
16
    state.id = id
17
  },
18
  [types.UPDATE_USER_NAME] (state, { name }) {
19
    state.name = name
18 20
  }
19 21
}
20 22

+ 5 - 1
src/store/mutation-types.js

@ -1,6 +1,10 @@
1
// 公共
1 2
export const SWITCH_SIDEBAR_COLLAPSE = 'SWITCH_SIDEBAR_COLLAPSE'
2 3
export const UPDATE_DOCUMENT_CLIENT_HEIGHT = 'UPDATE_DOCUMENT_CLIENT_HEIGHT'
3 4
export const UPDATE_MENU_NAV_LIST = 'UPDATE_MENU_NAV_LIST'
5
export const ADD_CONTENT_TAB = 'ADD_CONTENT_TAB'
4 6
export const UPDATE_CONTENT_TABS = 'UPDATE_CONTENT_TABS'
5 7
export const UPDATE_CONTENT_TABS_ACTIVE_NAME = 'UPDATE_CONTENT_TABS_ACTIVE_NAME'
6
export const UPDATE_USER_INFO = 'UPDATE_USER_INFO'
8
// 用户
9
export const UPDATE_USER_ID = 'UPDATE_USER_ID'
10
export const UPDATE_USER_NAME = 'UPDATE_USER_NAME'

+ 5 - 2
src/store/mutations.js

@ -1,4 +1,3 @@
1
import Vue from 'vue'
2 1
import * as types from './mutation-types'
3 2
4 3
export default {
@ -14,11 +13,15 @@ export default {
14 13
    state.menuNavList = list
15 14
  },
16 15
16
  [types.ADD_CONTENT_TAB] (state, tab) {
17
    state.contentTabs.push(tab)
18
  },
19
17 20
  [types.UPDATE_CONTENT_TABS] (state, tabs) {
18 21
    state.contentTabs = tabs
19 22
  },
20 23
21 24
  [types.UPDATE_CONTENT_TABS_ACTIVE_NAME] (state, { name }) {
22
    Vue.set(state.contentTabs, 'activeName', name)
25
    state.contentTabsActiveName = name
23 26
  }
24 27
}

+ 10 - 8
src/utils/index.js

@ -6,6 +6,15 @@ export function isAuth (key) {
6 6
  return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false
7 7
}
8 8
9
/**
10
 * 获取路由名称, 根据url地址
11
 * @param {*} url
12
 */
13
export function getRouteNameByUrl (url) {
14
  let val = /.*\/(.*)\.html/.exec(url)
15
  return val && val.length >= 1 ? val[1] : ''
16
}
17
9 18
/**
10 19
 * 树形数据转换
11 20
 * @param {*} data
@ -33,15 +42,8 @@ export function treeDataTranslate (data, id = 'id', pid = 'parentId') {
33 42
34 43
/**
35 44
 * 获取字符串字节长度
45
 * @param {*} s
36 46
 */
37 47
export function getStringLength (s) {
38 48
  return s.replace(/[\u4e00-\u9fa5\uff00-\uffff]/g, '**').length
39 49
}
40
41
/**
42
 * 获取路由名称, 根据url地址
43
 */
44
export function getRouteNameByUrl (url) {
45
  let val = /.*\/(.*)\.html/.exec(url)
46
  return val && val.length >= 1 ? val[1] : ''
47
}

+ 3 - 0
src/utils/validate.js

@ -1,5 +1,6 @@
1 1
/**
2 2
 * 邮箱
3
 * @param {*} s
3 4
 */
4 5
export function isEmail (s) {
5 6
  return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
@ -7,6 +8,7 @@ export function isEmail (s) {
7 8
8 9
/**
9 10
 * 手机号码
11
 * @param {*} s
10 12
 */
11 13
export function isMobile (s) {
12 14
  return /^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/.test(s)
@ -14,6 +16,7 @@ export function isMobile (s) {
14 16
15 17
/**
16 18
 * 电话号码
19
 * @param {*} s
17 20
 */
18 21
export function isPhone (s) {
19 22
  return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)

+ 15 - 16
src/views/layout/content-tabs.vue

@ -2,18 +2,18 @@
2 2
  <div class="site-content site-content--tabs">
3 3
    <el-tabs
4 4
      v-model="tabActiveName"
5
      :closable="$store.state.contentTabs.tabList.length > 1"
5
      :closable="$store.state.contentTabs.length > 1"
6 6
      @tab-click="selectedTabHandle"
7 7
      @tab-remove="removeTabHandle">
8 8
        <el-tab-pane
9
          v-for="item in $store.state.contentTabs.tabList"
9
          v-for="item in $store.state.contentTabs"
10 10
          :key="item.name"
11 11
          :label="item.title"
12 12
          :name="item.name">
13 13
          <el-card :body-style="contentViewHeight(item)">
14 14
            <iframe
15 15
              v-if="item.type === 'iframe'"
16
              :src="$store.state.menuNavIframeUrl + item.url"
16
              :src="getNestIframeUrl(item.url)"
17 17
              width="100%" height="100%" frameborder="0" scrolling="yes">
18 18
            </iframe>
19 19
            <keep-alive v-else>
@ -36,7 +36,7 @@
36 36
    computed: {
37 37
      tabActiveName: {
38 38
        get () {
39
          return this.$store.state.contentTabs.activeName
39
          return this.$store.state.contentTabsActiveName
40 40
        },
41 41
        set (val) {
42 42
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: val })
@ -55,28 +55,27 @@
55 55
        height += 'px'
56 56
        return tab.type === 'iframe' ? { height } : { minHeight: height }
57 57
      },
58
      // 获取iframe嵌套地址
59
      getNestIframeUrl (url) {
60
        return window.SITE_CONFIG.nestIframeUrl + url
61
      },
58 62
      // 选中tab
59 63
      selectedTabHandle (tab) {
60
        tab = this.$store.state.contentTabs.tabList.filter(item => item.name === tab.name)
64
        tab = this.$store.state.contentTabs.filter(item => item.name === tab.name)
61 65
        if (!isEmpty(tab)) {
62 66
          this.$router.push({ name: tab[0].name })
63 67
        }
64 68
      },
65 69
      // 删除tab
66 70
      removeTabHandle (tabName) {
67
        var newTabList = this.$store.state.contentTabs.tabList.filter(item => item.name !== tabName)
68
        if (!isEmpty(newTabList)) {
69
          // 当前选中tab被删除
70
          if (this.tabActiveName === tabName) {
71
            this.$router.push({ name: newTabList[newTabList.length - 1].name }, () => {
72
              this.tabActiveName = this.$route.name
73
            })
74
          }
75
          this.UPDATE_CONTENT_TABS({
76
            activeName: this.tabActiveName,
77
            tabList: newTabList
71
        var newTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
72
        // 当前选中tab被删除
73
        if (tabName === this.tabActiveName) {
74
          this.$router.push({ name: newTabs[newTabs.length - 1].name }, () => {
75
            this.tabActiveName = this.$route.name
78 76
          })
79 77
        }
78
        this.UPDATE_CONTENT_TABS(newTabs)
80 79
      },
81 80
      ...mapMutations(['UPDATE_CONTENT_TABS', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
82 81
    }

+ 3 - 5
src/views/layout/index.vue

@ -50,14 +50,12 @@
50 50
      getUserInfo () {
51 51
        API.user.info().then(({data}) => {
52 52
          if (data && data.code === 0) {
53
            this.UPDATE_USER_INFO({
54
              userId: data.user.userId,
55
              userName: data.user.username
56
            })
53
            this.UPDATE_USER_ID({ id: data.user.userId })
54
            this.UPDATE_USER_NAME({ name: data.user.username })
57 55
          }
58 56
        })
59 57
      },
60
      ...mapMutations(['UPDATE_DOCUMENT_CLIENT_HEIGHT', 'UPDATE_USER_INFO'])
58
      ...mapMutations(['UPDATE_DOCUMENT_CLIENT_HEIGHT', 'UPDATE_USER_ID', 'UPDATE_USER_NAME'])
61 59
    }
62 60
  }
63 61
</script>

+ 27 - 42
src/views/layout/sidebar.vue

@ -25,8 +25,8 @@
25 25
<script>
26 26
  import SubMenuNav from '@/components/sub-menu-nav'
27 27
  import API from '@/api'
28
  import { getRouteNameByUrl } from '@/utils'
29 28
  import { mapMutations } from 'vuex'
29
  import { getRouteNameByUrl } from '@/utils'
30 30
  import isEmpty from 'lodash/isEmpty'
31 31
  export default {
32 32
    data () {
@ -41,47 +41,11 @@
41 41
      $route: 'routeHandle'
42 42
    },
43 43
    created () {
44
      this.routeHandle(this.$route, true)
44
      this.getMenuNavList().then(() => {
45
        this.routeHandle(this.$route)
46
      })
45 47
    },
46 48
    methods: {
47
      // 路由操作
48
      // isInit: 页面第一次加载时, 需先获取菜单导航列表, 再进行其他操作
49
      routeHandle (route, isInit) {
50
        if (/^\/n\/.*$/.test(route.path)) {
51
          // tab不存在添加, 存在选中
52
          let tab = this.$store.state.contentTabs.tabList.filter(tab => tab.name === route.name)
53
          if (isEmpty(tab)) {
54
            if (isInit && isEmpty(this.$store.state.menuNavList)) {
55
              this.getMenuNavList().then(() => {
56
                this.addContentTab(route.name)
57
              })
58
            } else {
59
              this.addContentTab(route.name)
60
            }
61
          } else {
62
            this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: route.name })
63
          }
64
        } else {
65
          if (isInit) {
66
            this.getMenuNavList()
67
          }
68
        }
69
      },
70
      // 添加内容tab项
71
      addContentTab (name) {
72
        let menuNav = this.getMenuNavByRouteName(name)
73
        this.UPDATE_CONTENT_TABS({
74
          activeName: name,
75
          tabList: this.$store.state.contentTabs.tabList.concat({
76
            id: menuNav.menuId,
77
            title: menuNav.name,
78
            name: name,
79
            type: this.$store.state.menuNavTypeMap[name] === 'iframe' ? 'iframe' : 'module',
80
            url: menuNav.url
81
          })
82
        })
83
        this.menuNavActive = menuNav.menuId + ''
84
      },
85 49
      // 获取菜单导航列表 / 权限
86 50
      getMenuNavList () {
87 51
        return API.menu.nav().then(({data}) => {
@ -94,8 +58,29 @@
94 58
          }
95 59
        })
96 60
      },
61
      // 路由操作
62
      routeHandle (route) {
63
        if (/^\/n\/.*$/.test(route.path)) {
64
          var tab = this.$store.state.contentTabs.filter(item => item.name === route.name)
65
          // tab不存在, 先添加
66
          if (isEmpty(tab)) {
67
            var menuNav = this.getMenuNavByRouteName(route.name, this.$store.state.menuNavList)
68
            if (!isEmpty(menuNav)) {
69
              this.menuNavActive = menuNav.menuId + ''
70
              this.ADD_CONTENT_TAB({
71
                id: menuNav.menuId,
72
                name: route.name,
73
                title: menuNav.name,
74
                type: (window.SITE_CONFIG.nestIframeRouteNameList || []).indexOf(route.name) !== -1 ? 'iframe' : 'module',
75
                url: menuNav.url
76
              })
77
            }
78
          }
79
          this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: route.name })
80
        }
81
      },
97 82
      // 获取菜单导航, 根据路由名称
98
      getMenuNavByRouteName (name, menuNavList = this.$store.state.menuNavList) {
83
      getMenuNavByRouteName (name, menuNavList) {
99 84
        for (var i = 0; i < menuNavList.length; i++) {
100 85
          if (menuNavList[i].list && menuNavList[i].list.length >= 1) {
101 86
            return this.getMenuNavByRouteName(name, menuNavList[i].list)
@ -106,7 +91,7 @@
106 91
          }
107 92
        }
108 93
      },
109
      ...mapMutations(['UPDATE_MENU_NAV_LIST', 'UPDATE_CONTENT_TABS', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
94
      ...mapMutations(['UPDATE_MENU_NAV_LIST', 'ADD_CONTENT_TAB', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
110 95
    }
111 96
  }
112 97
</script>

+ 13 - 85
src/views/layout/topbar.vue

@ -10,18 +10,18 @@
10 10
      <el-menu
11 11
        class="site-topbar__menu"
12 12
        mode="horizontal">
13
        <el-menu-item class="site-topbar__switch" index="1" @click="switchSidebarCollapse()">
13
        <el-menu-item class="site-topbar__switch" index="1-1" @click="switchSidebarCollapseHandle()">
14 14
          <icon-svg name="zhedie"></icon-svg>
15 15
        </el-menu-item>
16 16
      </el-menu>
17 17
      <el-menu
18 18
        class="site-topbar__menu site-topbar__menu--right"
19 19
        mode="horizontal">
20
        <el-menu-item class="site-topbar__avatar" index="2">
20
        <el-menu-item class="site-topbar__avatar" index="1-2">
21 21
          <el-dropdown placement="bottom" :hide-on-click="false">
22 22
            <span class="el-dropdown-link">
23
              <img src="~@/assets/img/avatar.png" :alt="$store.state.user.userName">
24
              {{ $store.state.user.userName }}
23
              <img src="~@/assets/img/avatar.png" :alt="$store.state.user.name">
24
              {{ $store.state.user.name }}
25 25
            </span>
26 26
            <el-dropdown-menu slot="dropdown">
27 27
              <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
@ -32,105 +32,33 @@
32 32
      </el-menu>
33 33
    </div>
34 34
    <!-- 弹窗, 修改密码 -->
35
    <el-dialog
36
      title="修改密码"
37
      :visible.sync="updatePasswordDialogVisible"
38
      width="550px"
39
      :append-to-body="true">
40
      <el-form :model="updatePasswordForm" :rules="updatePasswordRule" ref="updatePasswordForm" label-width="80px">
41
        <el-form-item label="账号">
42
          <span>{{ $store.state.user.userName }}</span>
43
        </el-form-item>
44
        <el-form-item label="原密码" prop="password">
45
          <el-input type="password" v-model="updatePasswordForm.password"></el-input>
46
        </el-form-item>
47
        <el-form-item label="新密码" prop="newPassword">
48
          <el-input type="password" v-model="updatePasswordForm.newPassword"></el-input>
49
        </el-form-item>
50
        <el-form-item label="确认密码" prop="confirmPassword">
51
          <el-input type="password" v-model="updatePasswordForm.confirmPassword"></el-input>
52
        </el-form-item>
53
      </el-form>
54
      <span slot="footer" class="dialog-footer">
55
        <el-button @click="updatePasswordDialogVisible = false">取消</el-button>
56
        <el-button type="primary" @click="updatePasswordFormSubmit()">确定</el-button>
57
      </span>
58
    </el-dialog>
35
    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
59 36
  </header>
60 37
</template>
61 38
62 39
<script>
40
  import UpdatePassword from './update-password'
63 41
  import API from '@/api'
64 42
  import { mapMutations } from 'vuex'
65 43
  export default {
66 44
    data () {
67
      var validateConfirmPassword = (rule, value, callback) => {
68
        if (this.updatePasswordForm.newPassword !== value) {
69
          callback(new Error('确认密码与新密码不一致'))
70
        } else {
71
          callback()
72
        }
73
      }
74 45
      return {
75
        updatePasswordDialogVisible: false,
76
        updatePasswordForm: {
77
          password: '',
78
          newPassword: '',
79
          confirmPassword: ''
80
        },
81
        updatePasswordRule: {
82
          password: [
83
            { required: true, message: '原密码不能为空', trigger: 'blur' }
84
          ],
85
          newPassword: [
86
            { required: true, message: '新密码不能为空', trigger: 'blur' }
87
          ],
88
          confirmPassword: [
89
            { required: true, message: '确认密码不能为空', trigger: 'blur' },
90
            { validator: validateConfirmPassword, trigger: 'blur' }
91
          ]
92
        }
46
        updatePassowrdVisible: false
93 47
      }
94 48
    },
49
    components: {
50
      UpdatePassword
51
    },
95 52
    methods: {
96 53
      // 切换侧边栏, 水平折叠收起状态
97
      switchSidebarCollapse () {
54
      switchSidebarCollapseHandle () {
98 55
        this.SWITCH_SIDEBAR_COLLAPSE({ collapse: !this.$store.state.sidebarCollapse })
99 56
      },
100 57
      // 修改密码
101 58
      updatePasswordHandle () {
102
        this.updatePasswordDialogVisible = true
59
        this.updatePassowrdVisible = true
103 60
        this.$nextTick(() => {
104
          this.$refs['updatePasswordForm'].resetFields()
105
        })
106
      },
107
      // 修改密码, 提交
108
      updatePasswordFormSubmit () {
109
        this.$refs['updatePasswordForm'].validate((valid) => {
110
          if (valid) {
111
            var params = {
112
              'password': this.updatePasswordForm.password,
113
              'newPassword': this.updatePasswordForm.newPassword
114
            }
115
            API.user.updatePassword(params).then(({data}) => {
116
              if (data && data.code === 0) {
117
                this.$message({
118
                  message: '操作成功',
119
                  type: 'success',
120
                  duration: 1500,
121
                  onClose: () => {
122
                    this.updatePasswordDialogVisible = false
123
                    this.$nextTick(() => {
124
                      this.$cookie.delete('token')
125
                      this.$router.replace({ name: 'login' })
126
                    })
127
                  }
128
                })
129
              } else {
130
                this.$message.error(data.msg)
131
              }
132
            })
133
          }
61
          this.$refs.updatePassowrd.init()
134 62
        })
135 63
      },
136 64
      // 退出

+ 99 - 0
src/views/layout/update-password.vue

@ -0,0 +1,99 @@
1
<template>
2
  <el-dialog
3
    title="修改密码"
4
    :visible.sync="visible"
5
    :append-to-body="true">
6
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
7
      <el-form-item label="账号">
8
        <span>{{ $store.state.user.name }}</span>
9
      </el-form-item>
10
      <el-form-item label="原密码" prop="password">
11
        <el-input type="password" v-model="dataForm.password"></el-input>
12
      </el-form-item>
13
      <el-form-item label="新密码" prop="newPassword">
14
        <el-input type="password" v-model="dataForm.newPassword"></el-input>
15
      </el-form-item>
16
      <el-form-item label="确认密码" prop="confirmPassword">
17
        <el-input type="password" v-model="dataForm.confirmPassword"></el-input>
18
      </el-form-item>
19
    </el-form>
20
    <span slot="footer" class="dialog-footer">
21
      <el-button @click="visible = false">取消</el-button>
22
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
23
    </span>
24
  </el-dialog>
25
</template>
26
27
<script>
28
  import API from '@/api'
29
  export default {
30
    data () {
31
      var validateConfirmPassword = (rule, value, callback) => {
32
        if (this.dataForm.newPassword !== value) {
33
          callback(new Error('确认密码与新密码不一致'))
34
        } else {
35
          callback()
36
        }
37
      }
38
      return {
39
        visible: false,
40
        dataForm: {
41
          password: '',
42
          newPassword: '',
43
          confirmPassword: ''
44
        },
45
        dataRule: {
46
          password: [
47
            { required: true, message: '原密码不能为空', trigger: 'blur' }
48
          ],
49
          newPassword: [
50
            { required: true, message: '新密码不能为空', trigger: 'blur' }
51
          ],
52
          confirmPassword: [
53
            { required: true, message: '确认密码不能为空', trigger: 'blur' },
54
            { validator: validateConfirmPassword, trigger: 'blur' }
55
          ]
56
        }
57
      }
58
    },
59
    methods: {
60
      // 初始化
61
      init () {
62
        this.visible = true
63
        this.$nextTick(() => {
64
          this.$refs['dataForm'].resetFields()
65
        })
66
      },
67
      // 表单提交
68
      dataFormSubmit () {
69
        this.$refs['dataForm'].validate((valid) => {
70
          if (valid) {
71
            var params = {
72
              'password': this.dataForm.password,
73
              'newPassword': this.dataForm.newPassword
74
            }
75
            API.user.updatePassword(params).then(({data}) => {
76
              if (data && data.code === 0) {
77
                this.$message({
78
                  message: '操作成功',
79
                  type: 'success',
80
                  duration: 1500,
81
                  onClose: () => {
82
                    this.visible = false
83
                    this.$nextTick(() => {
84
                      this.$cookie.delete('token')
85
                      this.$router.replace({ name: 'login' })
86
                    })
87
                  }
88
                })
89
              } else {
90
                this.$message.error(data.msg)
91
              }
92
            })
93
          }
94
        })
95
      }
96
    }
97
  }
98
</script>
99

+ 6 - 1
static/config/index.js

@ -1,5 +1,10 @@
1 1
;(function () {
2 2
  window.SITE_CONFIG = {
3
    baseURL: 'http://demo.renren.io/renren-fast/'
3
    // api请求地址
4
    baseUrl: '//demo.renren.io/renren-fast/',
5
    // 嵌套iframe地址
6
    nestIframeUrl: '//demo.renren.io/renren-fast/',
7
    // 嵌套iframe路由名称列表
8
    nestIframeRouteNameList: ['sql']
4 9
  }
5 10
})()