Files
YwxAppThink/public/assets/ywxapp/ywxapp.js
T

246 lines
8.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 在脚本【同步执行阶段】捕获当前 <script> 标签(异步回调中 document.currentScript 会失效)。
// 注意:appName 真正取自 ThinkPHP 注入的 layui.app(真实应用目录名),
// 这里仅作为兜底缓存 <script module> 标签上的属性值。
var _scriptEl = document.currentScript || document.scripts[document.scripts.length - 1];
var _appNameFromTag = _scriptEl ? _scriptEl.getAttribute('module') : null;
// 【关键】在脚本顶层同步配置 layui 模块 base 目录。
// 原因:普通业务模块(如 login,未在下方 extend 列表中)由 layui 用 base + 名称 + '.js' 解析路径。
// 若 base 未提前配置,页面里直接 layui.use('login') 时 base 为 undefined
// 会请求 /当前路径/undefinedlogin.js 而 404。
// 之前只在 define 回调里配置 base,而该回调是异步触发的(需有人 use('ywxapp') 才执行),
// 页面 use 业务模块时它往往还没跑,导致 base 缺失。此处同步先行配置即可规避执行顺序问题。
var _appName = (layui.app && layui.app.app) || _appNameFromTag || null;
if (layui && _appName) {
layui.config({ base: '/static/' + _appName + '/modules/' });
}
layui.extend({
ywxapp: "{/}/assets/ywxapp/modules/ywxapp",
route: "{/}/assets/ywxapp/modules/route",
view: "{/}/assets/ywxapp/modules/view",
wxapp: "{/}/assets/ywxapp/modules/wxapp",
auth: "{/}/assets/ywxapp/modules/auth",
iconPicker: "{/}/assets/ywxapp/modules/iconPicker",
ueditor: "{/}/assets/ywxapp/modules/ueditor",
http: "{/}/assets/ywxapp/modules/http",
wxedit: "{/}/assets/ywxapp/modules/wxedit",
chatClient: "{/}/assets/ywxapp/modules/chat-client",
JsonCrypto: "{/}/assets/ywxapp/modules/JsonCrypto",
cropper: "{/}/assets/ywxapp/modules/cropper/cropper",
croppers: "{/}/assets/ywxapp/modules/cropper/croppers",
echartsTheme: "{/}/assets/ywxapp/modules/echartsTheme",
echarts: "{/}/assets/ywxapp/modules/echarts",
}).define(["all", "route"], function (exports) {
var $ = layui.$,
table = layui.table, http = layui.http;
var loadIndex;
/** 设置Ajax */
var Setter = {
layerArea: function () {
const width = window.innerWidth;
// if (width >= 1400) return ["1330px", "99%"];
// if (width >= 1200) return ["1170px", "99%"];
if (width >= 992) return ["970px", "99%"];
if (width >= 768) return ["750px", "99%"];
return ["100%", "99%"];
},
paths: {
// core: layui.cache.base + 'adminui/dist/', // 核心库所在目录
// views: '/static/backend/views/', // 动态模板所在目录
// modules: layui.cache.base + 'modules/', // 业务模块所在目录
// base: layui.cache.base // 记录静态资源所在基础目录
},
container: 'LAY_app', // 容器 ID
entry: 'index', // 默认视图文件名
engine: '.html', // 视图文件后缀名
pageTabs: true, // 是否开启页面选项卡功能。 iframe 版推荐开启
refreshCurrPage: true, // 当跳转页面 url 与当前页 url 相同时,是否自动执行刷新 --- 2.0+
name: 'YwxApp', // 系统名称 --- 2.0+
appName: 'admin',
// 记录
record: {
url: true // 是否开启 iframe 跳转时 url 记忆功能
},
debug: true, // 是否开启调试模式。如开启,接口异常时会抛出异常 URL 等信息
// 自定义请求字段
request: {
tokenName: false // 自动携带 token 的字段名(如:access_token)。可设置 false 不携带。
},
// 配置业务模块目录中的特殊模块
extend: {
layim: 'layim/layim' // layim
},
// 主题配置
theme: {
// 内置主题配色方案
color: [{
main: '#20222A', // 主题色
selected: '#16baaa', // 选中色
alias: 'default' // 默认别名
}, {
main: '#03152A',
selected: '#3B91FF',
alias: 'dark-blue' // 藏蓝
}, {
main: '#2E241B',
selected: '#A48566',
alias: 'coffee' // 咖啡
}, {
main: '#50314F',
selected: '#7A4D7B',
alias: 'purple-red' // 紫红
}, {
main: '#344058',
logo: '#1E9FFF',
selected: '#1E9FFF',
alias: 'ocean' // 海洋
}, {
main: '#3A3D49',
logo: '#2F9688',
selected: '#16b777',
alias: 'green' // 墨绿
}, {
main: '#20222A',
logo: '#F78400',
selected: '#F78400',
alias: 'red' // 橙色
}, {
main: '#28333E',
logo: '#AA3130',
selected: '#AA3130',
alias: 'fashion-red' // 时尚红
}, {
main: '#24262F',
logo: '#3A3D49',
selected: '#16baaa',
alias: 'classic-black' // 经典黑
}, {
logo: '#226A62',
header: '#2F9688',
alias: 'green-header' // 墨绿头
}, {
main: '#344058',
logo: '#0085E8',
selected: '#1E9FFF',
header: '#1E9FFF',
alias: 'ocean-header' // 海洋头
}, {
header: '#393D49',
alias: 'classic-black-header' // 经典黑头
}, {
main: '#50314F',
logo: '#50314F',
selected: '#7A4D7B',
header: '#50314F',
alias: 'purple-red-header' // 紫红头
}, {
main: '#28333E',
logo: '#28333E',
selected: '#AA3130',
header: '#AA3130',
alias: 'fashion-red-header' // 时尚红头
}, {
main: '#28333E',
logo: '#16baaa',
selected: '#16baaa',
header: '#16baaa',
alias: 'green-header' // 墨绿头
}, {
main: '#393D49',
logo: '#393D49',
selected: '#16baaa',
header: '#23262E',
alias: 'Classic-style1' // 经典风格1
}, {
main: '#001529',
logo: '#001529',
selected: '#1890FF',
header: '#1890FF',
alias: 'Classic-style2' // 经典风格2
}, {
main: '#25282A',
logo: '#25282A',
selected: '#35BDB2',
header: '#35BDB2',
alias: 'Classic-style3' // 经典风格3
}],
// 初始的颜色索引,对应上面的配色方案数组索引
// 如果本地已经有主题色记录,则以本地记录为优先,除非请求本地数据(localStorage
initColorIndex: 0
}
};
Setter.paths = {
base: '/static/' + _appName + '/', // 静态资源根目录(供业务模块拼接 json 等相对资源)
modules: '/static/' + _appName + '/modules/', // 业务模块所在目录
views: '/static/' + _appName + '/views/', // 动态模板所在目录
}
Setter.common = {
layerArea: function (url) {
return [window.innerWidth > 1200 ? '30%' : (window.innerWidth > 768 ? '50%' : '99%'), '99%'];
}
};
let localData = layui.data(Setter.appName);
localData.setter && (Setter = $.extend(Setter, localData.setter));
/**
* 获取Tokens
* @returns
*/
Setter.getTokens = function () {
let localData = layui.data(Setter.appName);
return {
access_token: localData.access_token,
refresh_token: localData.refresh_token,
};
}
/**
* 保存Tokens
* @param {*} tokens
*/
Setter.saveTokens = function (tokens) {
if (tokens.access_token)
layui.data(Setter.appName, {
key: "access_token",
value: tokens.access_token,
});
if (tokens.refresh_token)
layui.data(Setter.appName, {
key: "refresh_token",
value: tokens.refresh_token,
});
}
Setter.setMenus = function (menus) {
layui.data(Setter.appName, {
key: "menus",
value: menus,
});
}
Setter.permissions = function (permission) {
layui.data(Setter.appName, {
key: "permission",
value: permission,
});
}
// table.set({
// ajax: function (Options, type) {
// layui.http
// .get(Options.url, Options.data, Options)
// .then((res) => {
// Options.success(res);
// })
// .catch((res) => {
// console.log(res);
// //Options.error(xhr, status, error);
// });
// },
// });
exports("setter", Setter);
});