diff --git a/bin/deploy/build.js b/bin/deploy/build.js index ada04bc..517f10d 100644 --- a/bin/deploy/build.js +++ b/bin/deploy/build.js @@ -64,7 +64,7 @@ class BuildProcess { this.options = { cwd: path.join(releaseDir, templateName), env: { - API_SERVER: 'https://mockapi.eolinker.com/IeZWjzy87c204a1f7030b2a17b00f3776ce0a07a5030a1b', + API_SERVER: 'https://mockapi.eolinker.com/jttjNwp60fc1c9e944fdf1cc494b28a7ca4cfe66bbafee1', ...process.env, ...env, PUBLIC_PATH: `${process.env.PUBLIC_PATH || ''}/${this.folderName}` diff --git a/bin/deploy/env.json b/bin/deploy/env.json index 1a2108d..814f879 100644 --- a/bin/deploy/env.json +++ b/bin/deploy/env.json @@ -1,6 +1,6 @@ { "nuxt-admin": { - "API_SERVER": "https://mockapi.eolinker.com/IeZWjzy87c204a1f7030b2a17b00f3776ce0a07a5030a1b", + "API_SERVER": "https://mockapi.eolinker.com/jttjNwp60fc1c9e944fdf1cc494b28a7ca4cfe66bbafee1", "APP_ID": "1204701543597604893" } } diff --git a/docs/api.md b/docs/api.md index c1ca700..e517530 100644 --- a/docs/api.md +++ b/docs/api.md @@ -23,7 +23,7 @@ this.$axios.$post('/security/users', body) ## 使用 ```javascript -// 创建一个 API 资源,修改文件 src/api/index.js +// 创建一个 API 资源,修改文件 src/services/basis.js // 创建了一个菜单资源的 CRUD 接口方法 + export const menus = new Repository(`${DEEPEXI_CLOUD_TENANT}/${VERSION}/menus`) @@ -33,23 +33,23 @@ this.$axios.$post('/security/users', body) // 在 page 中 mounted() { // 获取资源的服务器路径 - this.$http.menus.uri() + this.$services.basis.menus.uri() // 获取所有菜单资源,返回一个列表 - this.$http.menus.list() + this.$services.basis.menus.list() // 获取某个菜单资源的详情 - this.$http.menus.detail(MENUS_ID) + this.$services.basis.menus.detail(MENUS_ID) // 创建一个菜单资源 - this.$http.menus.create(payload) + this.$services.basis.menus.create(payload) // 更新一个菜单资源 - this.$http.menus.update(MENUS_ID, payload) + this.$services.basis.menus.update(MENUS_ID, payload) // 删除一个菜单资源 - this.$http.menus.delete(MENUS_ID) + this.$services.basis.menus.delete(MENUS_ID) } // 在 store 中 export const actions = { async getMenus(store, payload) { - const data = await this.$http.menus.detail(payload) + const data = await this.$services.basis.menus.detail(payload) ... } } @@ -60,7 +60,7 @@ export const actions = { 有些时候,后端的接口并不是严格遵循 RESTful 的最佳实践,这个时候就需要自己重新实现默认的方法 ```javascript -// 在 src/api/repository.js 中增加一个类,继承 Repository +// 在 src/services/repository.js 中增加一个类,继承 Repository export class ExampleRepository extends Repository { constructor(resource, id) { super(resource) @@ -78,13 +78,58 @@ export class ExampleRepository extends Repository { } // 基于 ExampleRepository 创建一个 API -export const example = new ExampleRepository('/example/api') +export default new ExampleRepository('/example/api') // 调用 -this.$http.example.uri(appId) -this.$http.example.detail(id) -this.$http.example.list() -this.$http.example.create(payload) -this.$http.example.update(appId, payload) -this.$http.example.delete(id) +this.$services.example.uri(appId) +this.$services.example.detail(id) +this.$services.example.list() +this.$services.example.create(payload) +this.$services.example.update(appId, payload) +this.$services.example.delete(id) ``` +## 注意 + +services 会根据文件名作为 scope,将该文件 export 出去的所有值挂在这个 scope 下。 + +比如 `basic.js` +```js +export const login = new Repository(`${SECURITY_CLOUD}/${VERSION}/login`) + +export const userInfo = new Repository(`${SECURITY_CLOUD}/${VERSION}/token`) + +export const menus = new Repository(`${SECURITY_CLOUD_TENANT}/${VERSION}/menus`) + +export const subMenus = new Repository( + `${SECURITY_CLOUD_TENANT}/${VERSION}/sub-menus`, +) +``` + +就会将它们挂在 `this.$services.basic` 下: +```js +this.$services.basic.menus.list() +``` + +如果文件中有 `export default`,则会有些不同。 + +比如 `example.js`: +```js +export default new Repository(`${VERSION}/example/api`) + +// 使用 +this.$services.example.list() +``` + +如果文件中既有 `export default` 又有 `export const`: +```js +export default new Repository(`${VERSION}/example/api`) + +export const other = new Repository(`${VERSION}/example/api/other`) + +// 使用 +this.$services.example.list() +this.$services.example.other.list() +``` + +**需要注意**:导出的 `service` 名字不能与 `Repository` 的接口名字重复,接口名字列表可以在这里看到: +https://github.com/femessage/create-nuxt-app/blob/dev/template/modules/service/services/common/repository.js#L8 diff --git a/template/framework-admin/store/index.js b/template/framework-admin/store/index.js index 1e5e929..75d635e 100644 --- a/template/framework-admin/store/index.js +++ b/template/framework-admin/store/index.js @@ -104,7 +104,7 @@ export const mutations = { export const actions = { async login({commit, dispatch}, {body, redirect = '/'}) { - const userInfo = await this.$http.login.create(body) + const userInfo = await this.$services.basic.login.create(body) commit('setUserInfo', userInfo.payload) dispatch('getHeaderMenu') dispatch('getSiderMenu') @@ -114,7 +114,7 @@ export const actions = { }, async refresh({commit, dispatch}, token) { - const userInfo = await this.$http.userInfo.list({ + const userInfo = await this.$services.basic.userInfo.list({ params: { token, }, @@ -125,7 +125,7 @@ export const actions = { }, async getHeaderMenu({commit}) { - const menus = await this.$http.menus.list({ + const menus = await this.$services.basic.menus.list({ params: { appId: process.env.APP_ID, }, @@ -134,7 +134,7 @@ export const actions = { }, async getSiderMenu({commit}) { - const menus = await this.$http.subMenus.list({ + const menus = await this.$services.basic.subMenus.list({ params: { appId: process.env.APP_ID, }, diff --git a/template/framework-base/README.md b/template/framework-base/README.md index 95b04e1..30dcbb0 100644 --- a/template/framework-base/README.md +++ b/template/framework-base/README.md @@ -74,10 +74,13 @@ yarn generate ├── nuxt.config.js 框架配置文件 ├── package.json ├── src 开发目录 -│   ├── api api 资源管理 -│   │   ├── index.js 统一入口,定义 RESTful API 资源 -│   │   ├── repository.js RESTful 生成类,可以继承实现满足业务需求 -│   │   └── serverList.js 统一管理服务路径和 API version +│   ├── services api 资源管理 +│   │   ├── common service 公用的类库、BASE URL 定义等 +│   │   │   ├── api.js 统一管理服务路径和 API version +│   │   │   └── repository.js RESTful 生成类,可以继承实现满足业务需求 +│   │   ├── basic.js 一些基本的 services +│   │   ├── example.js 一个 example 的 service +│   │   └── index.js 统一入口,会导出所有 services │   ├── assets 资源,包括样式文件与图片 │   │   ├── global.less 全局样式类 │   │   └── var.less 样式变量,支持less变量自动引入,即不用在less中import就能直接使用变量 @@ -130,28 +133,32 @@ Nuxt.js 会依据 `pages` 目录中的所有 `*.vue` 文件生成应用的路由 [推荐使用 service 层管理 API:](https://github.com/FEMessage/create-nuxt-app/blob/dev/docs/api.md) -1. 在 `api/index.js` 中定义一个 API +1. 在 `services` 中定义一个 API +在 `src/services` 下新建一个 `example.js` ```js -// 创建了一个菜单资源的 RESTful API -export const menus = new Repository(`${SERVICE}/${VERSION}/menus`) +// 创建了一个 example 的 RESTful API +import {Repository} from './common/repository' +import {VERSION} from './common/api' + +export default new Repository(`${VERSION}/example/api`) ``` 2. 在 `*.vue`、`store/*.js` 的 `actions` 都可以调用 ```js // 获取资源的服务器路径 -this.$http.menus.uri() -// 获取所有菜单资源,返回一个列表 -this.$http.menus.list() -// 获取某个菜单资源的详情 -this.$http.menus.detail(MENUS_ID) -// 创建一个菜单资源 -this.$http.menus.create(payload) -// 更新一个菜单资源 -this.$http.menus.update(MENUS_ID, payload) -// 删除一个菜单资源 -this.$http.menus.delete(MENUS_ID) +this.$services.example.uri() +// 获取所有资源,返回一个列表 +this.$services.example.list() +// 获取某个资源的详情 +this.$services.example.detail(ID) +// 创建一个资源 +this.$services.example.create(payload) +// 更新一个资源 +this.$services.example.update(ID, payload) +// 删除一个资源 +this.$services.example.delete(ID) ``` 3. 如果接口是非标准的 RESTful API 可以参考此[文档](https://github.com/FEMessage/create-nuxt-app/blob/dev/docs/api.md#%E8%BF%9B%E9%98%B6) diff --git a/template/framework-base/_package.json b/template/framework-base/_package.json index 32bb517..83ad6e9 100644 --- a/template/framework-base/_package.json +++ b/template/framework-base/_package.json @@ -57,7 +57,7 @@ "eslint-config-prettier": "6.15.0", "eslint-friendly-formatter": "4.0.1", "eslint-plugin-jest": "24.1.3", - "eslint-plugin-nuxt": "^1.0.0", + "eslint-plugin-nuxt": "1.0.0", "eslint-plugin-prettier": "3.1.4", "github-release-notes": "0.17.1", "husky": "1.3.1", diff --git a/template/framework-base/nuxt.config.js b/template/framework-base/nuxt.config.js index 9dd3098..bc60cbd 100644 --- a/template/framework-base/nuxt.config.js +++ b/template/framework-base/nuxt.config.js @@ -233,7 +233,7 @@ module.exports = { plugins: [ {src: '~plugins/axios'}, {src: '~plugins/filters'}, - {src: '~plugins/api'}, + {src: '~plugins/services'}, <%_ if (template === 'mobile') { _%> {src: '~plugins/vant'}, <%_ } else { _%> diff --git a/template/modules/jest/test/unit/parseServices.test.js b/template/modules/jest/test/unit/parseServices.test.js new file mode 100644 index 0000000..ddd6c75 --- /dev/null +++ b/template/modules/jest/test/unit/parseServices.test.js @@ -0,0 +1,59 @@ +const {parseServices} = require('@/utils') +import {Repository} from '@/services/common/repository' + +const moackAxios = { + $get() {}, + $post() {}, + $put() {}, + $delete() {}, +} + +describe('测试 utils.parseServices 函数', () => { + test('普通处理 scope', () => { + const serviceModules = { + basis: { + login: new Repository('login'), + menus: new Repository('menus'), + subMenus: new Repository('subMenus'), + token: new Repository('token'), + }, + } + const expected = { + basis: { + login: serviceModules.basis.login.init(moackAxios), + menus: serviceModules.basis.menus.init(moackAxios), + subMenus: serviceModules.basis.subMenus.init(moackAxios), + token: serviceModules.basis.token.init(moackAxios), + }, + } + expect(parseServices(serviceModules, moackAxios)).toMatchObject(expected) + }) + + test('正常处理导出 default 时直接挂在 scope', () => { + const serviceModules = { + example: { + default: new Repository('example'), + }, + } + const expected = { + example: serviceModules.example.default.init(moackAxios), + } + expect(parseServices(serviceModules, moackAxios)).toMatchObject(expected) + }) + + test('正常处理同时导出 default 和 const', () => { + const serviceModules = { + example: { + default: new Repository('example'), + other: new Repository('example/other'), + }, + } + const expected = { + example: { + ...serviceModules.example.default.init(moackAxios), + other: serviceModules.example.other.init(moackAxios), + }, + } + expect(parseServices(serviceModules, moackAxios)).toMatchObject(expected) + }) +}) diff --git a/template/modules/service/api/index.js b/template/modules/service/api/index.js deleted file mode 100644 index 5d064d0..0000000 --- a/template/modules/service/api/index.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * @Author: Han - * @Date: 2020-01-14 11:43:00 - * @Last Modified by: Han - * @Last Modified time: 2020-02-18 17:36:32 - * @Description 项目接口统一定义入口,定义后可以直接通过 this.$http.login.create 的方式调用接口 - * 所有需要使用的定义都要 export - */ - -// import {ExampleRepository} from './repository' -import {Repository} from './repository' -import {VERSION, SECURITY_CLOUD, SECURITY_CLOUD_TENANT} from './serviceList' - -export const login = new Repository(`${SECURITY_CLOUD}/${VERSION}/login`) - -export const userInfo = new Repository(`${SECURITY_CLOUD}/${VERSION}/token`) - -export const menus = new Repository(`${SECURITY_CLOUD_TENANT}/${VERSION}/menus`) - -export const subMenus = new Repository( - `${SECURITY_CLOUD_TENANT}/${VERSION}/sub-menus`, -) - -// 重新定义请求方法的例子 -// export const example = new ExampleRepository('/example/api') diff --git a/template/modules/service/api/serviceList.js b/template/modules/service/api/serviceList.js deleted file mode 100644 index ac8e94d..0000000 --- a/template/modules/service/api/serviceList.js +++ /dev/null @@ -1,17 +0,0 @@ -/* - * @Author: Han - * @Date: 2020-01-13 18:08:25 - * @Last Modified by: Han - * @Last Modified time: 2020-02-18 17:33:53 - * @Description 如果服务很多,可以将服务 API 的公共部分抽离出来 - * @Example /security/api/v1/login, /security/api/v1/token - * 将 /security/api 抽离后,如果服务路径更改只需要改动此处 - */ - -export const VERSION = 'v1' - -// security 接口服务 -export const SECURITY_CLOUD = '/security/api' - -// security 租户接口服务 -export const SECURITY_CLOUD_TENANT = '/security/tenant/api' diff --git a/template/modules/service/plugins/api.js b/template/modules/service/plugins/api.js deleted file mode 100644 index bc6d8da..0000000 --- a/template/modules/service/plugins/api.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * @Author: Han - * @Date: 2020-01-14 10:57:11 - * @Last Modified by: Han - * @Last Modified time: 2020-02-17 16:49:55 - * @Description 将 @/api/index.js 中的 api 注入到 nuxt 上下文中 - * @Example 在 nuxt 的 pages 中以 this.$http[`${api_resource_name}`] 的方式调用对的 CRUD 方法 - * 详情查看 '../api/repository.js' - */ -import * as api from '@/api' - -export default (ctx, inject) => { - const http = {} - Object.keys(api).forEach(key => { - http[key] = api[key].init(ctx.$axios) - }) - inject('http', http) -} diff --git a/template/modules/service/plugins/services.js b/template/modules/service/plugins/services.js new file mode 100644 index 0000000..38c4ff9 --- /dev/null +++ b/template/modules/service/plugins/services.js @@ -0,0 +1,12 @@ +/** + * @see https://github.com/FEMessage/create-nuxt-app/blob/dev/docs/api.md + */ + +import modules from '~/services' +import {parseServices} from '~/utils' + +export default (ctx, inject) => { + const services = parseServices(modules, ctx.$axios) + + inject('services', services) +} diff --git a/template/modules/service/services/basic.js b/template/modules/service/services/basic.js new file mode 100644 index 0000000..89643a0 --- /dev/null +++ b/template/modules/service/services/basic.js @@ -0,0 +1,12 @@ +import {Repository} from './common/repository' +import {VERSION, SECURITY_CLOUD, SECURITY_CLOUD_TENANT} from './common/api' + +export const login = new Repository(`${SECURITY_CLOUD}/${VERSION}/login`) + +export const userInfo = new Repository(`${SECURITY_CLOUD}/${VERSION}/token`) + +export const menus = new Repository(`${SECURITY_CLOUD_TENANT}/${VERSION}/menus`) + +export const subMenus = new Repository( + `${SECURITY_CLOUD_TENANT}/${VERSION}/sub-menus`, +) diff --git a/template/modules/service/services/common/api.js b/template/modules/service/services/common/api.js new file mode 100644 index 0000000..e0c213d --- /dev/null +++ b/template/modules/service/services/common/api.js @@ -0,0 +1,7 @@ +export const VERSION = 'v1' + +// security 接口服务 +export const SECURITY_CLOUD = '/security/api' + +// security 租户接口服务 +export const SECURITY_CLOUD_TENANT = '/security/tenant/api' diff --git a/template/modules/service/api/repository.js b/template/modules/service/services/common/repository.js similarity index 75% rename from template/modules/service/api/repository.js rename to template/modules/service/services/common/repository.js index e75dcf5..f2d8952 100644 --- a/template/modules/service/api/repository.js +++ b/template/modules/service/services/common/repository.js @@ -1,10 +1,3 @@ -/* - * @Author: Han - * @Date: 2020-01-13 17:22:51 - * @Last Modified by: Han - * @Last Modified time: 2020-02-17 16:49:38 - */ - const RepositoryInterface = { URI: 'uri', CREATE: 'create', @@ -28,6 +21,9 @@ export class Repository { */ constructor(resource) { this.resource = resource + + this.$axios = null + this.methods = null } /** @@ -111,25 +107,30 @@ export class Repository { * @memberof Repository */ init($axios) { - // bind this 是为了继承 Repository 的属性方法,方便扩展 - return { - [RepositoryInterface.URI]: this[RepositoryInterface.URI].bind(this), - [RepositoryInterface.CREATE]: this[RepositoryInterface.CREATE]( - $axios, - ).bind(this), - [RepositoryInterface.DETAIL]: this[RepositoryInterface.DETAIL]( - $axios, - ).bind(this), - [RepositoryInterface.LIST]: this[RepositoryInterface.LIST]($axios).bind( - this, - ), - [RepositoryInterface.DELETE]: this[RepositoryInterface.DELETE]( - $axios, - ).bind(this), - [RepositoryInterface.UPDATE]: this[RepositoryInterface.UPDATE]( - $axios, - ).bind(this), + // 确保多次 init 且传入相同的 axios 实例时返回相同的引用 + if (!this.methods && this.$axios !== $axios) { + // bind this 是为了继承 Repository 的属性方法,方便扩展 + this.methods = { + [RepositoryInterface.URI]: this[RepositoryInterface.URI].bind(this), + [RepositoryInterface.CREATE]: this[RepositoryInterface.CREATE]( + $axios, + ).bind(this), + [RepositoryInterface.DETAIL]: this[RepositoryInterface.DETAIL]( + $axios, + ).bind(this), + [RepositoryInterface.LIST]: this[RepositoryInterface.LIST]($axios).bind( + this, + ), + [RepositoryInterface.DELETE]: this[RepositoryInterface.DELETE]( + $axios, + ).bind(this), + [RepositoryInterface.UPDATE]: this[RepositoryInterface.UPDATE]( + $axios, + ).bind(this), + } } + + return this.methods } } diff --git a/template/modules/service/services/example.js b/template/modules/service/services/example.js new file mode 100644 index 0000000..2670e54 --- /dev/null +++ b/template/modules/service/services/example.js @@ -0,0 +1,4 @@ +import {ExampleRepository} from './common/repository' +import {VERSION} from './common/api' + +export default new ExampleRepository(`${VERSION}/example/api`) diff --git a/template/modules/service/services/index.js b/template/modules/service/services/index.js new file mode 100644 index 0000000..c658940 --- /dev/null +++ b/template/modules/service/services/index.js @@ -0,0 +1,24 @@ +/** + * 将 @/services 第一层 .js|.ts 文件中的所有 service 导出去 + * 一个业务模块的 service 应该单独一个文件 + */ +const serviceModules = require.context('./', false, /\.js|.ts$/) + +/** + * 使用文件名作为 scope,然后将该文件的所有导出内容挂在这个 scope 下 + * 就如 basis.js 导出了 login、menus 等,就会变成 servers.basis.login 这样 + * 另外需要注意的是 export default 时 default 会作为 key + * 关于如何处理该数据可以看 src/plugins/services.js + */ +export default serviceModules + .keys() + .filter(key => key !== './index.js') // 排除当前文件 + .reduce((services, path) => { + // set './app.js' => 'app' + const moduleName = path.replace(/^\.\/(.*)\.\w+$/, '$1') + const modules = serviceModules(path) + + services[moduleName] = modules + + return services + }, {}) diff --git a/template/modules/typescript/src/types/extend.d.ts b/template/modules/typescript/src/types/extend.d.ts new file mode 100644 index 0000000..c4225a5 --- /dev/null +++ b/template/modules/typescript/src/types/extend.d.ts @@ -0,0 +1,8 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars +import Vue from 'vue' + +declare module 'vue/types/vue' { + interface Vue { + readonly $services: any + } +} diff --git a/template/modules/utils/utils/index.js b/template/modules/utils/utils/index.js index 2f323da..af9a407 100644 --- a/template/modules/utils/utils/index.js +++ b/template/modules/utils/utils/index.js @@ -1,3 +1,12 @@ +const RepositoryInterface = { + URI: 'uri', + CREATE: 'create', + LIST: 'list', + DETAIL: 'detail', + UPDATE: 'update', + DELETE: 'delete', +} + function getRouterBase(href = '') { if (!href || typeof href !== 'string') { return '/' @@ -14,12 +23,37 @@ function getRouterBase(href = '') { const routeBase = pathname .split('/') - .filter((p) => !/\./g.test(p)) + .filter(p => !/\./g.test(p)) .join('/') return routeBase.endsWith('/') ? routeBase : routeBase + '/' } +function parseServices(serviceModules, axios) { + const services = {} + Object.keys(serviceModules).forEach(scope => { + services[scope] = {} + + Object.keys(serviceModules[scope]).forEach(key => { + // 将 export default 直接挂在 scope 下 + if (key === 'default') { + services[scope] = serviceModules[scope].default.init(axios) + } + + if (Object.values(RepositoryInterface).includes(key)) { + throw new Error( + `Service 名字「${scope}.${key}」与 Repository 接口名字冲突`, + ) + } + + services[scope][key] = serviceModules[scope][key].init(axios) + }) + }) + + return services +} + module.exports = { getRouterBase, + parseServices, } diff --git a/test/snapshots/cypress.test.js.md b/test/snapshots/cypress.test.js.md index 1c7877b..a6b4a1a 100644 --- a/test/snapshots/cypress.test.js.md +++ b/test/snapshots/cypress.test.js.md @@ -26,9 +26,6 @@ Generated by [AVA](https://ava.li). 'jsconfig.json', 'nuxt.config.js', 'package.json', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/export.less', 'src/assets/global.less', @@ -71,12 +68,17 @@ Generated by [AVA](https://ava.li). 'src/pages/index.vue', 'src/pages/login.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/element.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/svg-icon.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', @@ -96,6 +98,7 @@ Generated by [AVA](https://ava.li). 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', ] > package.json @@ -142,7 +145,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', @@ -228,9 +231,6 @@ Generated by [AVA](https://ava.li). 'nuxt.config.js', 'package.json', 'postcss.config.js', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/global.less', 'src/assets/icon.png', @@ -261,11 +261,16 @@ Generated by [AVA](https://ava.li). 'src/pages/my.vue', 'src/pages/order-list.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/vant.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', @@ -284,6 +289,7 @@ Generated by [AVA](https://ava.li). 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', ] > package.json @@ -332,7 +338,7 @@ Generated by [AVA](https://ava.li). 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-cypress': '^2.11.2', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', diff --git a/test/snapshots/cypress.test.js.snap b/test/snapshots/cypress.test.js.snap index ac7fc6b..ba8f4f9 100644 Binary files a/test/snapshots/cypress.test.js.snap and b/test/snapshots/cypress.test.js.snap differ diff --git a/test/snapshots/docker.test.js.md b/test/snapshots/docker.test.js.md index f3eac4c..95b9682 100644 --- a/test/snapshots/docker.test.js.md +++ b/test/snapshots/docker.test.js.md @@ -26,9 +26,6 @@ Generated by [AVA](https://ava.li). 'jsconfig.json', 'nuxt.config.js', 'package.json', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/export.less', 'src/assets/global.less', @@ -71,12 +68,17 @@ Generated by [AVA](https://ava.li). 'src/pages/index.vue', 'src/pages/login.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/element.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/svg-icon.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', @@ -87,6 +89,7 @@ Generated by [AVA](https://ava.li). 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', ] > package.json @@ -133,7 +136,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', @@ -220,9 +223,6 @@ Generated by [AVA](https://ava.li). 'nuxt.config.js', 'package.json', 'postcss.config.js', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/global.less', 'src/assets/icon.png', @@ -253,11 +253,16 @@ Generated by [AVA](https://ava.li). 'src/pages/my.vue', 'src/pages/order-list.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/vant.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', @@ -267,6 +272,7 @@ Generated by [AVA](https://ava.li). 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', ] > package.json @@ -313,7 +319,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', diff --git a/test/snapshots/docker.test.js.snap b/test/snapshots/docker.test.js.snap index 8671ace..41bf051 100644 Binary files a/test/snapshots/docker.test.js.snap and b/test/snapshots/docker.test.js.snap differ diff --git a/test/snapshots/index.test.js.md b/test/snapshots/index.test.js.md index 4c7727c..01889f9 100644 --- a/test/snapshots/index.test.js.md +++ b/test/snapshots/index.test.js.md @@ -25,9 +25,6 @@ Generated by [AVA](https://ava.li). 'jsconfig.json', 'nuxt.config.js', 'package.json', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/export.less', 'src/assets/global.less', @@ -70,12 +67,17 @@ Generated by [AVA](https://ava.li). 'src/pages/index.vue', 'src/pages/login.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/element.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/svg-icon.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', @@ -86,6 +88,7 @@ Generated by [AVA](https://ava.li). 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', ] > package.json @@ -132,7 +135,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', @@ -217,9 +220,6 @@ Generated by [AVA](https://ava.li). 'nuxt.config.js', 'package.json', 'postcss.config.js', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/global.less', 'src/assets/icon.png', @@ -250,11 +250,16 @@ Generated by [AVA](https://ava.li). 'src/pages/my.vue', 'src/pages/order-list.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/vant.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', @@ -264,6 +269,7 @@ Generated by [AVA](https://ava.li). 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', ] > package.json @@ -310,7 +316,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', diff --git a/test/snapshots/index.test.js.snap b/test/snapshots/index.test.js.snap index fe62484..a352ade 100644 Binary files a/test/snapshots/index.test.js.snap and b/test/snapshots/index.test.js.snap differ diff --git a/test/snapshots/typescript.test.js.md b/test/snapshots/typescript.test.js.md index b710147..6b2c241 100644 --- a/test/snapshots/typescript.test.js.md +++ b/test/snapshots/typescript.test.js.md @@ -24,9 +24,6 @@ Generated by [AVA](https://ava.li). 'jest.config.js', 'nuxt.config.js', 'package.json', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/export.less', 'src/assets/global.less', @@ -69,24 +66,31 @@ Generated by [AVA](https://ava.li). 'src/pages/index.vue', 'src/pages/login.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/element.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/svg-icon.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', 'src/store/README.md', 'src/store/bread.js', 'src/store/index.js', + 'src/types/extend.d.ts', 'src/types/tsx-shim.d.ts', 'src/types/vue-shim.d.ts', 'src/utils/index.js', 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', 'tsconfig.json', ] @@ -133,7 +137,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', @@ -217,9 +221,6 @@ Generated by [AVA](https://ava.li). 'nuxt.config.js', 'package.json', 'postcss.config.js', - 'src/api/index.js', - 'src/api/repository.js', - 'src/api/serviceList.js', 'src/assets/README.md', 'src/assets/global.less', 'src/assets/icon.png', @@ -250,22 +251,29 @@ Generated by [AVA](https://ava.li). 'src/pages/my.vue', 'src/pages/order-list.vue', 'src/plugins/README.md', - 'src/plugins/api.js', 'src/plugins/axios.js', 'src/plugins/filters.js', 'src/plugins/icon-font.js', + 'src/plugins/services.js', 'src/plugins/vant.js', + 'src/services/basic.js', + 'src/services/common/api.js', + 'src/services/common/repository.js', + 'src/services/example.js', + 'src/services/index.js', 'src/static/README.md', 'src/static/favicon.ico', 'src/static/icon.png', 'src/store/README.md', 'src/store/index.js', + 'src/types/extend.d.ts', 'src/types/tsx-shim.d.ts', 'src/types/vue-shim.d.ts', 'src/utils/index.js', 'test/unit/.eslintrc.js', 'test/unit/filters.test.js', 'test/unit/getRouterBase.test.js', + 'test/unit/parseServices.test.js', 'tsconfig.json', ] @@ -316,7 +324,7 @@ Generated by [AVA](https://ava.li). 'eslint-config-prettier': '6.15.0', 'eslint-friendly-formatter': '4.0.1', 'eslint-plugin-jest': '24.1.3', - 'eslint-plugin-nuxt': '^1.0.0', + 'eslint-plugin-nuxt': '1.0.0', 'eslint-plugin-prettier': '3.1.4', 'github-release-notes': '0.17.1', husky: '1.3.1', diff --git a/test/snapshots/typescript.test.js.snap b/test/snapshots/typescript.test.js.snap index d9debcb..13d0c92 100644 Binary files a/test/snapshots/typescript.test.js.snap and b/test/snapshots/typescript.test.js.snap differ