Explorar o código

联调:接入 Java 后端(本地代理 + 驼峰字段)

- 代理:devServer 打开 /api -> http://127.0.0.1:18080,pathRewrite /api -> /admin;
  public/config.js BASE_API 改为 /api(生产打包前改回实际域名)
- 出入参全量转驼峰:storeId/storeName/menuId/apiId/parentId/isPage/moduleKey/actionMark/
  userName/adminUserId/passwordConfirm/createTime,STable 分页改 currentPage
- 登录态与动态路由同步适配(userInfo.adminUserId、菜单树字段)
- 修复:回收站、API 权限列表的列配置挂了不存在的 scopedSlots,导致整列空白
tanlie hai 1 día
pai
achega
caf7ea4f89

+ 2 - 1
public/config.js

@@ -4,7 +4,8 @@ window.serverConfig = {
   // 必填: api地址, 换成自己的域名即可
   // 例如: https://www.你的域名.com/index.php?s=/admin
   // BASE_API: '../index.php?s=/admin',
-  BASE_API: 'http://yoshop2-feel.cn/index.php?s=/admin',
+  // 开发环境走 vue.config.js 的 devServer.proxy(/api -> http://127.0.0.1:18080/admin)
+  BASE_API: '/api',
   // 必填: store模块的入口地址
   // 例如: https://www.你的域名.com/store
   STORE_URL: '../store'

+ 2 - 2
src/components/Table/index.js

@@ -161,7 +161,7 @@ export default {
       if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
         result.then(r => {
           this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
-            current: r.current_page, // 返回结果中的当前分页数
+            current: r.currentPage, // 返回结果中的当前分页数
             total: r.total, // 返回结果中的总记录数
             showSizeChanger: this.showSizeChanger,
             pageSize: (pagination && pagination.pageSize) ||
@@ -177,7 +177,7 @@ export default {
           // 这里用于判断接口是否有返回 r.totalCount 且 this.showPagination = true 且 page 和 pageSize 存在 且 totalCount 小于等于 page * pageSize 的大小
           // 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能
           try {
-            if ((['auto', true].includes(this.showPagination) && r.total <= (r.current_page * this.localPagination.pageSize))) {
+            if ((['auto', true].includes(this.showPagination) && r.total <= (r.currentPage * this.localPagination.pageSize))) {
               this.localPagination.hideOnSinglePage = true
             }
           } catch (e) {

+ 1 - 1
src/permission.js

@@ -27,7 +27,7 @@ router.beforeEach((to, from, next) => {
       NProgress.done()
     } else {
       // 判断是否存在用户信息
-      if (!store.getters.userInfo.admin_user_id) {
+      if (!store.getters.userInfo.adminUserId) {
         store
           .dispatch('GetInfo')
           .then(data => {

+ 1 - 1
src/store/modules/user.js

@@ -57,7 +57,7 @@ const user = {
         getInfo().then(response => {
           const data = response.data
           commit('SET_INFO', data['userInfo'])
-          commit('SET_NAME', { name: data['userInfo']['user_name'], welcome: welcome() })
+          commit('SET_NAME', { name: data['userInfo']['userName'], welcome: welcome() })
           // commit('SET_ROLES', data.roles)
           // commit('SET_AVATAR', data.avatar)
           resolve(data)

+ 3 - 3
src/views/manage/renew.vue

@@ -4,7 +4,7 @@
     <a-form :form="form">
       <a-form-item label="管理员用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="后台登录用户名">
         <a-input
-          v-decorator="['user_name', {rules: [{required: true, min: 4, message: '请输入至少4个字符'}]}]"
+          v-decorator="['userName', {rules: [{required: true, min: 4, message: '请输入至少4个字符'}]}]"
         />
       </a-form-item>
       <a-form-item label="用户密码" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="后台登录密码">
@@ -18,7 +18,7 @@
       <a-form-item label="确认密码" :labelCol="labelCol" :wrapperCol="wrapperCol">
         <a-input
           type="password"
-          v-decorator="['password_confirm', {rules: [
+          v-decorator="['passwordConfirm', {rules: [
             {required: true, message: '请输入确认密码'},
             {validator: compareToFirstPassword}
           ]}]"
@@ -72,7 +72,7 @@ export default {
       infoApi()
         .then((result) => {
           const { data: { userInfo } } = result
-          this.form.setFieldsValue({ user_name: userInfo['user_name'] })
+          this.form.setFieldsValue({ userName: userInfo['userName'] })
         })
         .finally(() => this.isLoading = false)
     },

+ 7 - 12
src/views/menu/access/index.vue

@@ -6,7 +6,7 @@
       <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
     </div>
     <a-table
-      rowKey="api_id"
+      rowKey="apiId"
       :columns="columns"
       :data-source="list"
       :loading="isLoading"
@@ -45,29 +45,24 @@ export default {
       columns: [
         {
           title: '权限ID',
-          dataIndex: 'api_id',
+          dataIndex: 'apiId'
           // width: '25%',
-          scopedSlots: { customRender: 'api_id' }
         },
         {
           title: '权限名称',
-          dataIndex: 'name',
-          scopedSlots: { customRender: 'name' }
+          dataIndex: 'name'
         },
         {
           title: '权限url',
-          dataIndex: 'url',
-          scopedSlots: { customRender: 'url' }
+          dataIndex: 'url'
         },
         {
           title: '排序',
-          dataIndex: 'sort',
-          scopedSlots: { customRender: 'sort' }
+          dataIndex: 'sort'
         },
         {
           title: '添加时间',
-          dataIndex: 'create_time',
-          scopedSlots: { customRender: 'create_time' }
+          dataIndex: 'createTime'
         },
         {
           title: '操作',
@@ -130,7 +125,7 @@ export default {
      * 确认删除
      */
     onSubmitDelete (item) {
-      return Api.deleted({ apiId: item['api_id'] })
+      return Api.deleted({ apiId: item['apiId'] })
         .then((result) => {
           this.$message.success(result.message)
           this.handleRefresh()

+ 4 - 4
src/views/menu/access/modules/AddForm.vue

@@ -20,7 +20,7 @@
             :tree-data="apiListTreeData"
             :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
             allow-clear
-            v-decorator="['parent_id']"
+            v-decorator="['parentId']"
           ></a-tree-select>
         </a-form-item>
         <a-form-item
@@ -96,7 +96,7 @@ export default {
     setFieldsValue () {
       this.$nextTick(() => {
         this.form.resetFields()
-        this.form.setFieldsValue({ parent_id: 0 })
+        this.form.setFieldsValue({ parentId: 0 })
       })
     },
 
@@ -124,8 +124,8 @@ export default {
       list.forEach(item => {
         const newItem = {
           title: item.name,
-          key: item.api_id,
-          value: item.api_id
+          key: item.apiId,
+          value: item.apiId
         }
         if (item.children && item.children.length) {
           newItem['children'] = this.formatTreeData(item['children'])

+ 6 - 6
src/views/menu/access/modules/EditForm.vue

@@ -20,7 +20,7 @@
             :tree-data="apiListTreeData"
             :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
             allow-clear
-            v-decorator="['parent_id']"
+            v-decorator="['parentId']"
           ></a-tree-select>
         </a-form-item>
         <a-form-item
@@ -101,7 +101,7 @@ export default {
      */
     setFieldsValue () {
       this.$nextTick(() => {
-        this.form.setFieldsValue(pick(this.record, ['name', 'url', 'parent_id', 'sort']))
+        this.form.setFieldsValue(pick(this.record, ['name', 'url', 'parentId', 'sort']))
       })
     },
 
@@ -130,12 +130,12 @@ export default {
         // 新的元素
         const newItem = {
           title: item.name,
-          key: item.api_id,
-          value: item.api_id
+          key: item.apiId,
+          value: item.apiId
         }
         // 禁用的权限
         if (
-          [item.api_id, item.parent_id].includes(this.record.api_id) ||
+          [item.apiId, item.parentId].includes(this.record.apiId) ||
           disabled === true
         ) {
           newItem.disabled = true
@@ -177,7 +177,7 @@ export default {
     * 提交到后端api
     */
     onFormSubmit (values) {
-      Api.edit({ apiId: this.record['api_id'], form: values })
+      Api.edit({ apiId: this.record['apiId'], form: values })
         .then((result) => {
           // 显示成功
           this.$message.success(result.message)

+ 4 - 4
src/views/menu/index.vue

@@ -6,7 +6,7 @@
       <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
     </div>
     <a-table
-      rowKey="menu_id"
+      rowKey="menuId"
       :columns="columns"
       :data-source="list"
       :loading="isLoading"
@@ -78,7 +78,7 @@ export default {
       columns: [
         {
           title: '菜单ID',
-          dataIndex: 'menu_id'
+          dataIndex: 'menuId'
           // width: '25%',
         },
         {
@@ -199,7 +199,7 @@ export default {
      * 确认删除
      */
     onSubmitDelete (item) {
-      return Api.deleted({ menuId: item['menu_id'] })
+      return Api.deleted({ menuId: item['menuId'] })
         .then((result) => {
           this.$message.success(result.message)
           this.handleRefresh()
@@ -217,7 +217,7 @@ export default {
      * 新增操作权限
      */
     handleActionAdd (menu) {
-      this.$refs.ActionForm.add(menu.menu_id)
+      this.$refs.ActionForm.add(menu.menuId)
     },
 
     /**

+ 5 - 5
src/views/menu/modules/ActionForm.vue

@@ -17,11 +17,11 @@
         </a-form-item>
         <a-form-item label="权限标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
           <a-input
-            v-decorator="['action_mark', {rules: [{required: true, min: 2, message: '请输入至少2个字符'}]}]"
+            v-decorator="['actionMark', {rules: [{required: true, min: 2, message: '请输入至少2个字符'}]}]"
           />
         </a-form-item>
         <a-form-item label="功能模块key" :labelCol="labelCol" :wrapperCol="wrapperCol">
-          <a-input v-decorator="['module_key']" />
+          <a-input v-decorator="['moduleKey']" />
         </a-form-item>
         <a-form-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="数字越小越靠前">
           <a-input-number
@@ -110,7 +110,7 @@ export default {
     setFieldsValue (record) {
       this.$nextTick(() => {
         this.form.resetFields()
-        record && this.form.setFieldsValue(pick(record, ['name', 'action_mark', 'sort']))
+        record && this.form.setFieldsValue(pick(record, ['name', 'actionMark', 'sort']))
       })
     },
 
@@ -155,12 +155,12 @@ export default {
       }
       // 新增数据
       if (this.scene === 'add') {
-        values.parent_id = this.parentId
+        values.parentId = this.parentId
         Api.add({ form: { type: 20, ...values } })
           .then(result => Success(result))
           .finally(() => { this.confirmLoading = false })
       } else if (this.scene === 'edit') { // 编辑数据
-        Api.edit({ menuId: this.record['menu_id'], form: values })
+        Api.edit({ menuId: this.record['menuId'], form: values })
           .then(result => Success(result))
           .finally(() => { this.confirmLoading = false })
       }

+ 6 - 6
src/views/menu/modules/AddForm.vue

@@ -20,7 +20,7 @@
             :tree-data="menuListTreeData"
             :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
             allow-clear
-            v-decorator="['parent_id', { rules: [{ required: true }] }]"
+            v-decorator="['parentId', { rules: [{ required: true }] }]"
           ></a-tree-select>
         </a-form-item>
         <a-form-item label="菜单path" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="指向的页面path">
@@ -33,14 +33,14 @@
           extra="如果为否,则为纯菜单项,仅做用于父级菜单使用"
         >
           <a-radio-group
-            v-decorator="['is_page', { initialValue: 1, rules: [{ required: true }] }]"
+            v-decorator="['isPage', { initialValue: 1, rules: [{ required: true }] }]"
           >
             <a-radio :value="1">是</a-radio>
             <a-radio :value="0">否</a-radio>
           </a-radio-group>
         </a-form-item>
         <a-form-item label="功能模块key" :labelCol="labelCol" :wrapperCol="wrapperCol">
-          <a-input v-decorator="['module_key']" />
+          <a-input v-decorator="['moduleKey']" />
         </a-form-item>
         <a-form-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="数字越小越靠前">
           <a-input-number
@@ -108,7 +108,7 @@ export default {
     setFieldsValue () {
       this.$nextTick(() => {
         this.form.resetFields()
-        this.form.setFieldsValue({ parent_id: 0 })
+        this.form.setFieldsValue({ parentId: 0 })
       })
     },
 
@@ -136,8 +136,8 @@ export default {
       list.forEach(item => {
         const newItem = {
           title: item.name,
-          key: item.menu_id,
-          value: item.menu_id
+          key: item.menuId,
+          value: item.menuId
         }
         if (item.hasOwnProperty('children')) {
           newItem['children'] = this.formatTreeData(item['children'])

+ 9 - 9
src/views/menu/modules/EditForm.vue

@@ -20,7 +20,7 @@
             :tree-data="menuListTreeData"
             :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
             allow-clear
-            v-decorator="['parent_id', { rules: [{ required: true }] }]"
+            v-decorator="['parentId', { rules: [{ required: true }] }]"
           ></a-tree-select>
         </a-form-item>
         <a-form-item label="菜单path" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="指向的页面path">
@@ -33,14 +33,14 @@
           extra="如果为否,则为纯菜单项,仅做用于父级菜单使用"
         >
           <a-radio-group
-            v-decorator="['is_page', { initialValue: 1, rules: [{ required: true }] }]"
+            v-decorator="['isPage', { initialValue: 1, rules: [{ required: true }] }]"
           >
             <a-radio :value="1">是</a-radio>
             <a-radio :value="0">否</a-radio>
           </a-radio-group>
         </a-form-item>
         <a-form-item label="功能模块key" :labelCol="labelCol" :wrapperCol="wrapperCol">
-          <a-input v-decorator="['module_key']" />
+          <a-input v-decorator="['moduleKey']" />
         </a-form-item>
         <a-form-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="数字越小越靠前">
           <a-input-number
@@ -114,7 +114,7 @@ export default {
     async getMenuInfo (record) {
       this.confirmLoading = true
       // 当前菜单记录
-      this.record = await Api.info({ menu_id: record.menu_id }).then(result => result.data.info)
+      this.record = await Api.info({ menuId: record.menuId }).then(result => result.data.info)
       this.confirmLoading = false
     },
 
@@ -123,7 +123,7 @@ export default {
      */
     setFieldsValue () {
       this.$nextTick(() => {
-        this.form.setFieldsValue(pick(this.record, ['name', 'path', 'module_key', 'is_page', 'parent_id', 'sort']))
+        this.form.setFieldsValue(pick(this.record, ['name', 'path', 'moduleKey', 'isPage', 'parentId', 'sort']))
       })
     },
 
@@ -152,12 +152,12 @@ export default {
         // 新的元素
         const newItem = {
           title: item.name,
-          key: item.menu_id,
-          value: item.menu_id
+          key: item.menuId,
+          value: item.menuId
         }
         // 禁用的菜单
         if (
-          [item.menu_id, item.parent_id].includes(this.record.menu_id) ||
+          [item.menuId, item.parentId].includes(this.record.menuId) ||
           disabled === true
         ) {
           newItem.disabled = true
@@ -200,7 +200,7 @@ export default {
     * 提交到后端api
     */
     onFormSubmit (values) {
-      Api.edit({ menuId: this.record['menu_id'], form: values })
+      Api.edit({ menuId: this.record['menuId'], form: values })
         .then((result) => {
           // 显示成功
           this.$message.success(result.message)

+ 3 - 3
src/views/menu/modules/SetApiForm.vue

@@ -88,7 +88,7 @@ export default {
       // 显示窗口
       this.visible = true
       this.record = record
-      this.menuId = record.menu_id
+      this.menuId = record.menuId
       // 获取API权限列表
       this.getApiList()
       // 默认选中的API权限
@@ -136,7 +136,7 @@ export default {
         // 新的元素
         const newItem = {
           title: item.name,
-          key: item.api_id
+          key: item.apiId
         }
         // 递归整理子集
         if (item.children && item.children.length) {
@@ -187,7 +187,7 @@ export default {
         this.$emit('handleSubmit', values)
       }
       // 数据提交
-      Api.setApis({ menu_id: this.record['menu_id'], form: values })
+      Api.setApis({ menuId: this.record['menuId'], form: values })
         .then(result => Success(result))
         .finally(() => { this.confirmLoading = false })
     }

+ 9 - 9
src/views/store/index.vue

@@ -7,15 +7,15 @@
     <s-table
       ref="table"
       size="default"
-      rowKey="store_id"
+      rowKey="storeId"
       :columns="columns"
       :data="loadData"
       showPagination="auto"
       :pageSize="15"
     >
       <!-- 账户名 -->
-      <template slot="user_name" slot-scope="item">
-        <span>{{ item.superUser.user_name }}</span>
+      <template slot="userName" slot-scope="item">
+        <span>{{ item.superUser.userName }}</span>
       </template>
       <!-- 备注信息 -->
       <template slot="remark" slot-scope="text">
@@ -76,18 +76,18 @@ export default {
       columns: [
         {
           title: '商城ID',
-          dataIndex: 'store_id',
+          dataIndex: 'storeId',
           width: '120px'
         },
         {
           title: '商城名称',
-          dataIndex: 'store_name',
+          dataIndex: 'storeName',
           width: '200px'
         },
         {
           title: '账户名',
-          // dataIndex: 'user_name',
-          scopedSlots: { customRender: 'user_name' },
+          // dataIndex: 'userName',
+          scopedSlots: { customRender: 'userName' },
           width: '180px'
         },
         {
@@ -101,7 +101,7 @@ export default {
         },
         {
           title: '添加时间',
-          dataIndex: 'create_time'
+          dataIndex: 'createTime'
         },
         {
           title: '操作',
@@ -144,7 +144,7 @@ export default {
 
     // 确认删除
     onSubmitDelete (item) {
-      return Api.recovery({ storeId: item['store_id'] })
+      return Api.recovery({ storeId: item['storeId'] })
         .then(result => {
           this.$message.success(result.message)
           this.handleRefresh()

+ 5 - 5
src/views/store/modules/AccountForm.vue

@@ -11,11 +11,11 @@
     <a-spin :spinning="confirmLoading">
       <a-form :form="form">
         <a-form-item label="商城名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
-          <span>{{ record.store_name }}</span>
+          <span>{{ record.storeName }}</span>
         </a-form-item>
         <a-form-item label="商家用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="商家后台登录用户名">
           <a-input
-            v-decorator="['user_name', { rules: [{ required: true, min: 4, message: '请输入至少4个字符' }] }]"
+            v-decorator="['userName', { rules: [{ required: true, min: 4, message: '请输入至少4个字符' }] }]"
           />
         </a-form-item>
         <a-form-item label="用户密码" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="商家后台登录密码">
@@ -27,7 +27,7 @@
         <a-form-item label="确认密码" :labelCol="labelCol" :wrapperCol="wrapperCol">
           <a-input
             type="password"
-            v-decorator="['password_confirm', { rules: [
+            v-decorator="['passwordConfirm', { rules: [
               { message: '请输入确认密码' },
               { validator: compareToFirstPassword }
             ] }]"
@@ -81,7 +81,7 @@ export default {
       this.$nextTick(() => this.form.setFieldsValue({
         'remark': this.record['remark'],
         'sort': this.record['sort'],
-        'user_name': this.record['superUser']['user_name'],
+        'userName': this.record['superUser']['userName'],
       }))
     },
 
@@ -113,7 +113,7 @@ export default {
     // 提交到后端api
     onFormSubmit (values) {
       this.confirmLoading = true
-      Api.edit({ storeId: this.record['store_id'], form: values })
+      Api.edit({ storeId: this.record['storeId'], form: values })
         .then(result => {
           // 显示成功提示
           this.$message.success(result.message, 1.2)

+ 3 - 3
src/views/store/modules/CreateForm.vue

@@ -12,12 +12,12 @@
       <a-form :form="form">
         <a-form-item label="商城名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
           <a-input
-            v-decorator="['store_name', {rules: [{required: true, min: 3, message: '请输入至少3个字符'}]}]"
+            v-decorator="['storeName', {rules: [{required: true, min: 3, message: '请输入至少3个字符'}]}]"
           />
         </a-form-item>
         <a-form-item label="商家用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="商家后台登录用户名">
           <a-input
-            v-decorator="['user_name', {rules: [{required: true, min: 4, message: '请输入至少4个字符'}]}]"
+            v-decorator="['userName', {rules: [{required: true, min: 4, message: '请输入至少4个字符'}]}]"
           />
         </a-form-item>
         <a-form-item label="用户密码" :labelCol="labelCol" :wrapperCol="wrapperCol" extra="商家后台登录密码">
@@ -31,7 +31,7 @@
         <a-form-item label="确认密码" :labelCol="labelCol" :wrapperCol="wrapperCol">
           <a-input
             type="password"
-            v-decorator="['password_confirm', {rules: [
+            v-decorator="['passwordConfirm', {rules: [
               {required: true, message: '请输入确认密码'},
               {validator: compareToFirstPassword}
             ]}]"

+ 5 - 8
src/views/store/recycle.vue

@@ -4,7 +4,7 @@
     <s-table
       ref="table"
       size="default"
-      rowKey="store_id"
+      rowKey="storeId"
       :columns="columns"
       :data="loadData"
       showPagination="auto"
@@ -35,18 +35,15 @@ export default {
       columns: [
         {
           title: '商城ID',
-          dataIndex: 'store_id',
-          scopedSlots: { customRender: 'store_id' }
+          dataIndex: 'storeId'
         },
         {
           title: '商城名称',
-          dataIndex: 'store_name',
-          scopedSlots: { customRender: 'store_name' }
+          dataIndex: 'storeName'
         },
         {
           title: '添加时间',
-          dataIndex: 'create_time',
-          scopedSlots: { customRender: 'create_time' }
+          dataIndex: 'createTime'
         },
         {
           title: '操作',
@@ -86,7 +83,7 @@ export default {
      * 确认还原
      */
     onSubmitReturn (item) {
-      return moveApi({ storeId: item['store_id'] })
+      return moveApi({ storeId: item['storeId'] })
         .then(result => {
           this.$message.success(result.message)
           this.handleRefresh()

+ 13 - 13
vue.config.js

@@ -94,19 +94,19 @@ const vueConfig = {
    * 开发环境proxy代理 [用于跨域]
    */
   devServer: {
-    // development server port 8000
-    port: 8110
-    // If you want to turn on the proxy, please remove the mockjs /src/main.js L11
-    // proxy: {
-    //   '/api': {
-    //     target: 'https://www.abc.com/index.php/admin',
-    //     ws: false,
-    //     changeOrigin: true,
-    //     pathRewrite: {
-    //       '/api': ''
-    //     }
-    //   }
-    // }
+    // development server port 8110
+    port: 8110,
+    // 开发环境代理:/api/** -> http://127.0.0.1:18080/admin/**
+    proxy: {
+      '/api': {
+        target: 'http://127.0.0.1:18080',
+        ws: false,
+        changeOrigin: true,
+        pathRewrite: {
+          '/api': '/admin'
+        }
+      }
+    }
   },
 
   // disable source map in production