Skip to content

Commit

Permalink
3.3.0,更改配置文件目录结构
Browse files Browse the repository at this point in the history
  • Loading branch information
iZaiZaiA committed Dec 30, 2021
1 parent f473a2c commit 1b6ff0e
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 519 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MP CU

<p><a href="https://mp.color-ui.com/update/">更新日志(Beta V3.2.9)</a> | <a href="https://mp.color-ui.com/">在线文档</a>(完善中...)</p>
<p><a href="https://mp.color-ui.com/update/">更新日志(Beta V3.3.0)</a> | <a href="https://mp.color-ui.com/">在线文档</a></p>

<img width="120px" src="https://github.com/iZaiZaiA/iZaiZaiA/blob/img/mp-cu/mp-cu.jpg" />

Expand Down Expand Up @@ -53,13 +53,13 @@

### 框架配置

您可单独设置一个 `config.js` 里面配置相关信息,然后暴露方法给 `app.js` 在全局引用
您可单独设置一个 `config.js` 里面配置相关信息,然后暴露方法给 `app.js` 在全局引用,默认在 `config/ColorUI.js`

```javascript

import { ColorUi } from './config'
App({
ColorUi, //挂载到app上,此步骤必须要有!
import { colorUI } from './config/ColorUI'
App({
colorUI, //挂载到app上,此步骤必须要有!
onLaunch() {

}
Expand All @@ -84,13 +84,13 @@ App({
相关文件路径:

```
/config // (MP-CU配置文件)
/mp-cu // ColorUi主框架的文件夹,不建议修改这里面的文件,以免后续升级时,被覆盖。
/mp-sdk // ColorUi框架的辅助文件夹,封装了一些常用的方法函数、扩展图标库等,按需使用,如不需要,可删除此文件夹。
/packageA // 项目演示demo的分包,此包为模板包路径
/packageB // 项目演示demo的分包,此包为实验室包路径
...
/config.js // 框架的配置项,建议在此文件中配置,后续更新升级时,不会被覆盖
/config.js // 框架的配置项,(新版本中,已移除该文件)
```

Expand All @@ -117,7 +117,7 @@ App({
> 由于微信小程序无法使用vue.key来全局命名变量,导致习惯vue的用户很不习惯,而且微信内部并不存在像vuex这样的状态管理机制,为满足上述想法,colorUI MP-CU 为您定制了一套自有的扩展包,你可以在全局导入变量、函数、方法,同时您也可以定义您自己的状态(` vuex `).

- colorUI 的配置文件需要您定义成类似以下的内容,参考 `/config.js` 文件。
- colorUI 的配置文件需要您定义成类似以下的内容,参考 `config/ColorUI.js` 文件。

```javascript

Expand Down
11 changes: 8 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { colorUI } from './config'
import { colorUI } from './config/ColorUI'
import { colorUISdk } from './config/mp-sdk'

App({
colorUI, //挂载到app上
colorUI,//挂载到app上
colorUISdk,
onLaunch() {

//console.log(colorUISdk.isRandom.getRandom(6))
//console.log(colorUISdk.version)
//console.log(colorUISdk.numberFormat(1000000))
},
onShow() {

Expand Down
3 changes: 2 additions & 1 deletion config.js → config/ColorUI.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ColorUI from './mp-cu/main'
//框架核心配置
import ColorUI from '../mp-cu/main'
export const colorUI = new ColorUI({
config: {
theme: 'auto',
Expand Down
25 changes: 25 additions & 0 deletions config/mp-sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//扩展方法函数配置
import ColorUISdk from '../mp-sdk/index'
export const colorUISdk = new ColorUISdk({
//当前环境,produce,dev,host
env: 'dev',
//实际项目版本
version: '1.0.0',
api: {
//生产环境
produce: {
url: '请求域名'
},
//开发环境
dev: {
url: '请求域名'
},
//本地环境
host: {
url: '请求域名'
},
header: {
"Content-Type": "application/json"
},
},
})
2 changes: 1 addition & 1 deletion mp-cu/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CUStoreInit } from '/store/index'
* @author iZaiZaiA (https://github.com/iZaiZaiA)
*/

let version = '3.2.9';
let version = '3.3.0';

let store = {}, sys_info = wx.getSystemInfoSync();
let baseMethod = {
Expand Down
47 changes: 47 additions & 0 deletions mp-sdk/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import baseLib from './lib/index'
import {request} from './lib/request'

export default class ColorUISdk {
constructor({env, version, api}) {
//默认配置,防止没自定义配置时,出问题。
env = env||'dev'
version = version||'1.0.0'
if (!api.header) {
api.header = {};
api.header['Content-Type'] = 'application/json';
}
this.env = env;
this.version = version;
this.api = api;
this.ColorUISdkInit();
}
ColorUISdkInit() {
Object.keys(baseLib).forEach(key => {
if (typeof baseLib[key] === 'function') {
this[key] = baseLib[key]
}
if (typeof baseLib[key] === 'object') {
//二级方法函数
Object.keys(baseLib[key]).forEach(k => {
if (typeof baseLib[key][k] === 'function' || typeof baseLib[key][k] === 'object') {
this[k] = baseLib[key][k]
}
})
}
})
//console.log(this)
}
//发起请求
request(data, loading = false) {
return new Promise( (resolve, reject) => {
request(data, loading, {
env: this.env,
api: this.api
}).then(res=> {
resolve(res);
}).catch(err=> {
reject(err)
});
});
}
}
80 changes: 0 additions & 80 deletions mp-sdk/js/api.js

This file was deleted.

Loading

0 comments on commit 1b6ff0e

Please sign in to comment.