|
@@ -1,42 +1,42 @@
|
|
|
import cacheManager from "./cacheManager.js"
|
|
|
|
|
|
/**
|
|
|
-* 显示消息提示框
|
|
|
-* @param content 提示的标题
|
|
|
-*/
|
|
|
+ * 显示消息提示框
|
|
|
+ * @param content 提示的标题
|
|
|
+ */
|
|
|
export function toast(content) {
|
|
|
- uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: content
|
|
|
- })
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: content
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
-* 显示模态弹窗
|
|
|
-* @param content 提示的标题
|
|
|
-*/
|
|
|
+ * 显示模态弹窗
|
|
|
+ * @param content 提示的标题
|
|
|
+ */
|
|
|
export function showConfirm(content) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.showModal({
|
|
|
- title: '提示',
|
|
|
- content: content,
|
|
|
- cancelText: '取消',
|
|
|
- confirmText: '确定',
|
|
|
- success: function(res) {
|
|
|
- resolve(res)
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: content,
|
|
|
+ cancelText: '取消',
|
|
|
+ confirmText: '确定',
|
|
|
+ success: function(res) {
|
|
|
+ resolve(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
-* 参数处理
|
|
|
-* @param params 参数
|
|
|
-*/
|
|
|
+ * 参数处理
|
|
|
+ * @param params 参数
|
|
|
+ */
|
|
|
export function tansParams(params) {
|
|
|
- let result = ''
|
|
|
- // FIXME 拼接参数
|
|
|
- return result
|
|
|
+ let result = ''
|
|
|
+ // FIXME 拼接参数
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -44,18 +44,51 @@ export function tansParams(params) {
|
|
|
* @param {Object} promise
|
|
|
*/
|
|
|
export function catchError(promise) {
|
|
|
- return new Promise((resolve,reject) => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
promise.then(data => {
|
|
|
- resolve([undefined, data.data])
|
|
|
+ resolve([undefined, data.data])
|
|
|
}).catch(err => {
|
|
|
- reject([err])
|
|
|
+ reject([err])
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 是否是会员
|
|
|
+const IdentityType = {
|
|
|
+ VIP: 'VIP',
|
|
|
+ NOT_VIP: 'Not-Vip',
|
|
|
+ VISITOR: 'Visitor'
|
|
|
+};
|
|
|
+
|
|
|
+// export function getUserIdentity() {
|
|
|
+// const auth = cacheManager.get('auth');
|
|
|
+// if (!auth) return IdentityType.VISITOR;
|
|
|
+
|
|
|
+// const hasPurchased = auth.subjectId == 2 && auth.typeId == 1 ?
|
|
|
+// (auth.levelIdList || []).includes(auth.levelId.split(',')[0]) :
|
|
|
+// (auth.levelIdList || []).includes(auth.levelId);
|
|
|
+// console.log('hasPurchased',hasPurchased);
|
|
|
+
|
|
|
+// return hasPurchased ? IdentityType.VIP : IdentityType.NOT_VIP;
|
|
|
+// }
|
|
|
+
|
|
|
export function getUserIdentity() {
|
|
|
const auth = cacheManager.get('auth');
|
|
|
+ if(auth.subjectId == 2 && auth.typeId == 1){
|
|
|
+ if (auth) {
|
|
|
+ const arr = auth.levelId.split(",");
|
|
|
+ if ((auth.levelIdList || []).some(item => item == arr[0])) {
|
|
|
+ // 购买此levelId
|
|
|
+ return 'VIP'
|
|
|
+ }
|
|
|
+ // 无购买此levelId
|
|
|
+ return 'Not-Vip';
|
|
|
+ } else {
|
|
|
+ // 游客
|
|
|
+ return 'Visitor';
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //旧数学 新数学 旧英语
|
|
|
if (auth) {
|
|
|
if ((auth.levelIdList || []).some(item => item == auth.levelId)) {
|
|
|
// 购买此levelId
|
|
@@ -67,8 +100,10 @@ export function getUserIdentity() {
|
|
|
// 游客
|
|
|
return 'Visitor';
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
export function hasUserIdentity() {
|
|
|
const auth = cacheManager.get('auth');
|
|
|
if (auth) {
|
|
@@ -85,40 +120,40 @@ export function hasUserIdentity() {
|
|
|
}
|
|
|
|
|
|
export function debounce(func, wait) {
|
|
|
- let timeout;
|
|
|
+ let timeout;
|
|
|
|
|
|
- return function(...args) {
|
|
|
- // 清除之前的定时器
|
|
|
- clearTimeout(timeout);
|
|
|
+ return function(...args) {
|
|
|
+ // 清除之前的定时器
|
|
|
+ clearTimeout(timeout);
|
|
|
|
|
|
- // 设置新的定时器
|
|
|
- timeout = setTimeout(() => {
|
|
|
- func.apply(this, args);
|
|
|
- }, wait);
|
|
|
- };
|
|
|
+ // 设置新的定时器
|
|
|
+ timeout = setTimeout(() => {
|
|
|
+ func.apply(this, args);
|
|
|
+ }, wait);
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
|
|
|
export function findRootNode(tree, targetId, idKey = 'id') {
|
|
|
const path = [];
|
|
|
-
|
|
|
+
|
|
|
function traverse(node) {
|
|
|
- if (node[idKey] === targetId) return true;
|
|
|
- if (node.children) {
|
|
|
- for (const child of node.children) {
|
|
|
- if (traverse(child)) {
|
|
|
- path.unshift(node);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+ if (node[idKey] === targetId) return true;
|
|
|
+ if (node.children) {
|
|
|
+ for (const child of node.children) {
|
|
|
+ if (traverse(child)) {
|
|
|
+ path.unshift(node);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for (const root of tree) {
|
|
|
- if (traverse(root)) {
|
|
|
- return path.length > 0 ? path[0] : root;
|
|
|
- }
|
|
|
+ if (traverse(root)) {
|
|
|
+ return path.length > 0 ? path[0] : root;
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|