Commit 6f8b0184 authored by 李俊赕's avatar 李俊赕

简化封装代码

parent aa9c7853
const UNI_APP = { const UNI_APP = {
ucenterUrl: { ucenterUrl: {
apiUrl: 'https://rest-u.banshouhui.com', //php端域名请求头 apiUrl: 'http://rest-u.yunya.com', //php端域名请求头
xueUrl: 'https://xue.banshouhui.com', //学院 // xueUrl: 'https://xue.banshouhui.com', //学院
banshou: 'https://m.banshou.com', //扳手app // banshou: 'https://m.banshou.com', //扳手app
}, },
systemUrl: { systemUrl: {
apiUrl: 'https://system.banshouhui.com', //java端域名请求头 apiUrl: 'http://192.168.1.22', //java端域名请求头
} }
} }
module.exports = UNI_APP; module.exports = UNI_APP;
...@@ -2,13 +2,10 @@ ...@@ -2,13 +2,10 @@
(function() { (function() {
let NODE_ENV = 'dev'; // dev:开发环境 | test:测试环境 let NODE_ENV = 'dev'; // dev:开发环境 | test:测试环境
let ENV_VAR = null; let ENV_VAR = null;
console.log(process.env, 'process.env')
if (process.env.NODE_ENV === "development") { if (process.env.NODE_ENV === "development") {
// NODE_ENV = process.env.VUE_APP_ENV
if (NODE_ENV === 'dev') { if (NODE_ENV === 'dev') {
ENV_VAR = require('./.env.dev.js'); ENV_VAR = require('./.env.dev.js');
} else if (NODE_ENV === 'test') { } else if (NODE_ENV === 'test') {
// console.log(process.env.VUE_APP_ENV,'process.env.VUE_APP_ENV')
ENV_VAR = require('./.env.test.js'); ENV_VAR = require('./.env.test.js');
} }
......
const UNI_APP = { const UNI_APP = {
ucenterUrl: { ucenterUrl: {
apiUrl: 'https://rest-u.banshouhui.com', //php端域名请求头 apiUrl: 'https://rest-u.test.ibanshou.cn', //php端域名请求头
xueUrl: 'https://xue.banshouhui.com', //学院 // xueUrl: 'https://xue.banshouhui.com', //学院
banshou: 'https://m.banshou.com', //扳手app banshou: 'https://m.test.ibanshou.cn', //扳手app
}, },
systemUrl: { systemUrl: {
apiUrl: 'https://system.banshouhui.com', //java端域名请求头 apiUrl: 'https://system.dev.banshouhui.com', //java端域名请求头
} }
} }
module.exports = UNI_APP; module.exports = UNI_APP;
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
//RTOKEN45f41a3053238cb72b3b72fe14df8d7040c9f502 //RTOKEN45f41a3053238cb72b3b72fe14df8d7040c9f502
}, },
onLaunch: function() { onLaunch: function() {
console.log('App Launch') // console.log('App Launch')
console.log(process,process.env,process.uniEnv,'process.uniEnv')
}, },
onShow: function() { onShow: function() {
console.log('App Show--') // console.log('App Show--')
}, },
onHide: function() { onHide: function() {
console.log('App Hide') // console.log('App Hide')
}, },
methods: { methods: {
async getBaseInfo(vm, callBack) { async getBaseInfo(vm, callBack) {
......
// 所有模块公共API
import globalUrl from '@/common/base_url.js'
const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
let commonApiFun = function(vm){ let commonApiFun = function(vm){
let loginWxByUser = async (params = {}) => await vm.$u.get('/wxh-support-rest/rest/ssoinfo/v3/getUsersByCode', params); let loginWxByUser = async (params = {}) => await vm.$u.get('/wxh-support-rest/rest/ssoinfo/v3/getUsersByCode', params);
let loginWxByPhone = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/v3/findByMobile', params,{'content-type': 'application/x-www-form-urlencoded'}); let loginWxByPhone = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/v3/findByMobile', params,{'content-type': 'application/x-www-form-urlencoded'});
......
...@@ -4,20 +4,15 @@ import { ...@@ -4,20 +4,15 @@ import {
import { import {
commonApiFun commonApiFun
} from '@/common/api/common.js'; } from '@/common/api/common.js';
import {
take_orderApiFun
} from '@/common/api/take_order.js';
import { import {
settledApiFun settledApiFun
} from '@/common/api/settled.js'; } from '@/common/api/settled.js';
let apiFun = function(vm) { let apiFun = function(vm) {
let commonApi = commonApiFun(vm); let commonApi = commonApiFun(vm);
let take_orderApi = take_orderApiFun(vm);
let settledApi = settledApiFun(vm) let settledApi = settledApiFun(vm)
let cloudApi = cloudRulesApiFun(vm) let cloudApi = cloudRulesApiFun(vm)
let apiUrl = { let apiUrl = {
...commonApi, ...commonApi,
...take_orderApi,
...settledApi, ...settledApi,
...cloudApi ...cloudApi
} }
......
import globalUrl from '@/common/base_url.js' const globalUrl = process.uniEnv || {}
const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
let settledApiFun = function(vm){ let settledApiFun = function(vm){
......
import globalUrl from '@/common/base_url.js'
let take_orderApiFun = function(vm){
/* 通过unionid查询用户 */
let getSSOID = async (params = {}) => await vm.$u.get('/wxh-support-rest/rest/ssoinfo/v2/findByUnionId', params);
/* 根据ssoid获取logincode */
let getLoginCode = async (params = {}) => await vm.$u.get('/wxh-support-rest/rest/ssoinfo/v2/getLoginCode', params);
/* 通过appsecret查询用户token */
let getToken = async (params = {}) => await vm.$u.get('/wxh-support-rest/rest/worker/login/applets/', params);
const take_orderApi = {
getSSOID,
getLoginCode,
getToken
}
return take_orderApi
}
module.exports = {
take_orderApiFun
}
\ No newline at end of file
/* --------------------------- prod begin --------------------------- */
let ucenterUrl = {
apiUrl: 'https://rest-u.banshouhui.com', //php端域名请求头
xueUrl:'https://xue.banshouhui.com', //学院
banshou:'https://m.banshou.com' ,//扳手app
}
let systemUrl = {
apiUrl:'https://system.banshouhui.com', //java端域名请求头
}
/* --------------------------- prod end --------------------------- */
/* --------------------------- test begin --------------------------- */
// ucenterUrl = {
// apiUrl: 'https://rest-u.test.ibanshou.cn',
// xueUrl:'https://xue.test.ibanshou.cn', //学院
// banshou:'https://m.test.ibanshou.cn/', //扳手app
// }
// systemUrl = {
// apiUrl:'https://system.dev.banshouhui.com'
// }
/* --------------------------- test end --------------------------- */
/* --------------------------- dev begin --------------------------- */
// ucenterUrl = {
// apiUrl: 'http://rest-u.yunya.com',
// xueUrl:'http://rest-xue.yunya.com', //学院
// banshou:'https://m.test.ibanshou.cn/', //扳手app
// }
// systemUrl = {
// // apiUrl:'https://192.168.1.22'
// // apiUrl:'http://192.168.0.208:37080' //郭小青电脑
// apiUrl:'http://192.168.0.208:8192'
// }
/* --------------------------- dev end --------------------------- */
// function getCodeUrl(uri) {
// return codeUrl.apiBaseUrl + uri;
// }
function getUcenterUrl(uri) {
return ucenterUrl.apiUrl + uri;
}
export default {
ucenterUrl,
getUcenterUrl,
systemUrl
}
export const others = {
methods: {
//富文本的回调
navigate() {
},
moreClick() {
this.$set(this.moreList[1], 'text', this.detail.collected ? '已收藏' : '收藏');
this.is_more = true;
},
cancel() {
this.is_more = false;
}
}
}
// 收藏
export const collection = {
methods: {
//收藏
goCollectionCreate: async function(item, type) {
let res = await this.$u.api.goCollectionCreate({
id: item.id,
type: type
});
this.$u.toast(res.msg);
if (!res.code) {
return;
}
if (type == 'article' || type == 'question' || type == 'answer') {
item.collected = true;
}
},
//取消收藏
goCollectionDelete: async function(item, type) {
let res = await this.$u.api.goCollectionDelete({
id: item.id,
type: type
});
this.$u.toast(res.msg);
if (!res.code) {
return;
}
if (type == 'article' || type == 'question' || type == 'answer') {
item.collected = false;
}
},
},
}
// 点赞
export const vote = {
methods: {
goVoteCreate: async function(item, type, value = 'up') {
let res = await this.$u.api.goVoteCreate({
id: item.id,
type: type,
value: value
});
this.$u.toast(res.msg);
if (!res.code) {
return;
}
item.vote = value;
item.voteup = res.data.voteup;
},
goVoteDelete: async function(item, type, value = 'up') {
let res = await this.$u.api.goVoteDelete({
id: item.id,
type: type,
value: value
})
this.$u.toast(res.msg);
if (!res.code) {
return;
}
item.voteup = res.data.voteup;
item.vote = '';
},
}
}
// 关注
export const attention = {
methods: {
goAttentionCreate: async function(item, type, callback) {
let res = await this.$u.api.goAttentionCreate({
id: item.id,
type: type
})
this.$u.toast(res.msg);
if (!res.code) {
return;
}
item.followed = true;
if (typeof callback == 'function') {
callback();
};
},
goAttentionDelete: async function(item, type, callback = () => {}) {
let res = await this.$u.api.goAttentionDelete({
id: item.id,
type: type
})
this.$u.toast(res.msg);
if (!res.code) {
return;
}
item.followed = false;
if (typeof callback == 'function') {
callback();
};
},
}
}
//轮播图
export const swipers = {
methods: {
//轮播图事件
clickSwiper(index) {
let path = this.vuex_config.blockList[index].url;
if (path == '/' || !path) {
return;
}
if (path.substr(0, 1) == 'p') {
path = '/' + path;
}
this.$u.route({
url: path
})
},
}
}
//样式
export const styleRest = {
methods: {
getStyle(string) {
let underline = {};
let style = {};
let s = string.split('|');
s.forEach(item => {
if (item == 'b') {
style.fontWeight = 'bold';
}
if (item == 'u') {
underline.textDecoration = 'underline';
}
if (item.indexOf('#') != -1) {
let color = item.split(',');
style.backgroundImage = `linear-gradient(90deg,${color[0]} 0%, ${color[1]?color[1]:color[0]} 100%)`;
style.textFillColor = 'transparent'
}
})
return [underline, style];
},
setStyle(item) {
if (item.style) {
let result = this.getStyle(item.style);
item.styleArray = result[1];
item.underline = result[0];
} else {
item.styleArray = {};
item.underline = {};
}
}
}
}
//跳转标签
export const tagClick = {
methods: {
navigateTag(id, type) {
this.$u.route(`/pages/tag/detail?id=${id}&type=${type}`)
}
}
}
//登录成功之后
export const login = {
methods: {
success: async function(id,index=1) {
let res = await this.$u.api.getUserIndex({
id: id
});
if (!res.code) {
this.$u.toast(res.msg);
return;
}
this.$u.vuex('vuex_user', res.data.user);
this.$u.vuex('vuex_isAdmin', res.data.isAdmin);
// #ifdef APP-PLUS
this.$Router.back(index)
// #endif
// #ifndef APP-PLUS
let value = uni.getStorageSync('last_page');
//有上次页面,关闭所有页面,到此页面
if (value) {
this.$Router.replaceAll(Object.assign({},value))
return;
}
//默认到首页
this.$Router.replaceAll({
url: '/pages/index/index'
});
// #endif
}
}
}
// 查看品类模块(首页资料页)
export const getQuickTag = {
data(){
return {
quickTab:{
tabs:[],
tags:[]
}
}
},
methods:{
getTabTitle(){
},
getTabItem(){
},
}
}
\ No newline at end of file
import Vue from 'vue'
//这里仅示范npm安装方式的引入,其它方式引入请看最上面【安装】部分
import Router from 'uni-simple-router'
Vue.use(Router)
//初始化
const router = new Router({
APP: {
animation: {
animationType: 'pop-in',
animationDuration: 300
}
},
encodeURI:false,
routes: ROUTES //路由表
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
//去的页面是登录类型,来的页面不是登录类型,就缓存此页面,排除用户协议
if(to.path.indexOf('/login/') != -1 && from.path.indexOf('/login/') == -1 && from.path.indexOf('agreement') == -1){
uni.setStorageSync('last_page', {path:from.path,query:from.query});
}
next();
})
// 全局路由后置守卫
router.afterEach((to, from) => {
})
export default router;
module.exports = {
computed: {
theme() {
if (this.vuex_config.theme) {
let theme = this.vuex_config.theme;
let colorArr = this.$u.colorGradient(theme.bgColor, theme.color, theme.ladder);
return Object.assign({
lightColor:colorArr[theme.number] || '#f5f5f5',
faBorderColor:colorArr[theme.border] || '#f5f5f5'
},theme);
}
return {
bgColor: "#0301c5",
border: 5,
color: "#ffffff",
ladder: 10,
number: 9,
lightColor:'#f5f5f5',
faBorderColor:'#f5f5f5'
};
},
btnBgColor(vote, type) {
return (vote, type) => {
if(typeof type == 'undefined'){
return vote ? this.theme.bgColor : this.theme.lightColor;
}
return vote == type ? this.theme.bgColor : this.theme.lightColor;
};
},
btnColor(vote, type) {
return (vote, type) => {
if(typeof type == 'undefined'){
return vote? this.theme.color : this.theme.bgColor;
}
return vote == type ? this.theme.color : this.theme.bgColor;
};
}
},
}
This diff is collapsed.
//免登录接口 //免登录接口
import util from '@/utils/util.js' import util from '@/utils/util.js'
let noLoginUrl = [ // let noLoginUrl = [
'/v1/h5/settled/get-settled-info', // '/v1/h5/settled/get-settled-info',
'/v1/h5/settled/area', // '/v1/h5/settled/area',
'/v1/h5/settled/save-info', // '/v1/h5/settled/save-info',
'/v1/h5/settled/card-front', // ];
'/wxh-support-rest/rest/ssoinfo/v3/getUsersByCode',
'/wxh-support-rest/rest/ssoinfo/v3/findByMobile',
'/wxh-support-rest/rest/ssoinfo/wxapp/unify/authorization',
];
console.log('getSessionId---------')
//设置session_id
const getSessionId = function(vm) {
let session = vm.$util.getDb('session');
if (!session) {
let guid = vm.$u.guid();
vm.$util.setDb('session', guid);
return guid;
}
return session;
}
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token // 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token
// 同时,我们也可以在此使用getApp().globalData,如果你把token放在getApp().globalData的话,也是可以使用的 // 同时,我们也可以在此使用getApp().globalData,如果你把token放在getApp().globalData的话,也是可以使用的
// import globalUrl from '@/common/base_url.js'
const globalUrl = process.uniEnv || {} const globalUrl = process.uniEnv || {}
console.log(globalUrl,'globalUrl')
const install = (Vue, vm) => { const install = (Vue, vm) => {
let systemApiUrl = globalUrl.systemUrl.apiUrl let systemApiUrl = globalUrl.systemUrl.apiUrl
let ucenterApiUrl = globalUrl.ucenterUrl.apiUrl let ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
function toLoginPage(){ function toLoginPage(){
const app = getApp() const app = getApp()
let jumpLoginStatus let jumpLoginStatus
...@@ -90,9 +73,9 @@ const install = (Vue, vm) => { ...@@ -90,9 +73,9 @@ const install = (Vue, vm) => {
Vue.prototype.$u.http.interceptor.response = (res) => { Vue.prototype.$u.http.interceptor.response = (res) => {
let result = res.data; let result = res.data;
//返回__token__,设置 //返回__token__,设置
if (res.header.__token__) { // if (res.header.__token__) {
vm.$u.vuex('vuex__token__', res.header.__token__); // vm.$u.vuex('vuex__token__', res.header.__token__);
} // }
const code = getCode(res) const code = getCode(res)
switch (code) { switch (code) {
case 1: case 1:
......
import globalUrl from '@/common/base_url.js'
function strlen(value) { function strlen(value) {
//中文、中文标点、全角字符按1长度,英文、英文符号、数字按0.5长度计算 //中文、中文标点、全角字符按1长度,英文、英文符号、数字按0.5长度计算
...@@ -148,64 +147,8 @@ function getDb(name){ ...@@ -148,64 +147,8 @@ function getDb(name){
} }
} }
//获取缓存
function getFileUrlPrefix(){
return globalUrl.askUrl.fileUrl;
}
// 获取base_url
function getUcenterUrl(url) {
return globalUrl.getUcenterUrl(url);
}
// 获取静态文件路径
function getStaticUrl(url) {
return globalUrl.askUrl.apiUrl + '/assets/addons/ask/img/uniapp/' + url;
}
// 获取动态文件路径
function getDynamicUrl(url) {
return globalUrl.askUrl.fileUrl + url;
}
function getAskUrl(url) {
return globalUrl.askUrl.apiUrl + url;
}
// 获取文件类型
function getFileType(fileUrl){
let fileArr = ['doc','ppt','word','xls'];
let fileObj = {
doc:'doc',
docx:'doc',
xls:'xls',
xlsx:'xls',
ppt:'ppt',
pptx:'ppt',
pdf:'pdf',
}
// doc docx xls xlsx ppt pptx pdf
let reg = /\.[^\.]+$/;
let fileType = reg.exec(fileUrl);
let keyUrl = 'word';
keyUrl = fileObj[fileType] || keyUrl;
keyUrl = getStaticUrl('file/'+keyUrl+'.png')
return keyUrl
}
// 处理多次点击方法
function dianji(fn) {
let that = this;
if (that.onoff) {
that.onoff = false;
fn();
setTimeout(function () {
that.onoff = true;
}, 1500)
}
}
//时间戳转换成日期时间 //时间戳转换成日期时间
function js_date_time(unixtime) { function getDateTime(unixtime) {
var date = new Date(unixtime); var date = new Date(unixtime);
var y = date.getFullYear(); var y = date.getFullYear();
var m = date.getMonth() + 1; var m = date.getMonth() + 1;
...@@ -240,13 +183,6 @@ export { ...@@ -240,13 +183,6 @@ export {
getNavHeight, getNavHeight,
setDb, setDb,
getDb, getDb,
getFileUrlPrefix, getDateTime,
getUcenterUrl,
getFileType,
getStaticUrl,
getDynamicUrl,
getAskUrl,
dianji,
js_date_time,
randStr randStr
} }
import qiniuUploader from '@/include/libs/qiniuUploader.js'; import qiniuUploader from '@/include/libs/qiniuUploader.js';
import globalUrl from '@/common/base_url.js' const globalUrl = process.uniEnv || {}'
export default { export default {
name: 'qiniup', name: 'qiniup',
components: {}, components: {},
......
import qiniuUploader from '@/include/libs/qiniuUploader.js'; import qiniuUploader from '@/include/libs/qiniuUploader.js';
import globalUrl from '@/common/base_url.js' const globalUrl = process.uniEnv || {}
export default { export default {
name: 'upload-img', name: 'upload-img',
components: {}, components: {},
......
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
</template> </template>
<script> <script>
import globalData from '@/common/base_url.js' const globalUrl = process.uniEnv || {}
const systemApiUrl = globalData.systemUrl.apiUrl const systemApiUrl = globalUrl.systemUrl.apiUrl
const ucenterApiUrl = globalData.ucenterUrl.apiUrl const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
export default { export default {
data() { data() {
return { return {
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<script> <script>
import pingpp from '@/include/libs/pingpp.js' import pingpp from '@/include/libs/pingpp.js'
import globalUrl from '@/common/base_url.js' const globalUrl = process.uniEnv || {}
import util from '@/utils/util.js' import util from '@/utils/util.js'
export default { export default {
data() { data() {
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
</template> </template>
<script> <script>
import globalUrl from '@/common/base_url.js' const globalUrl = process.uniEnv || {}
const ucenterApiurl = globalUrl.ucenterUrl.apiUrl const ucenterApiurl = globalUrl.ucenterUrl.apiUrl
const app = getApp() const app = getApp()
export default { export default {
......
{
"passwordSecret": "passwordSecret-demo",
"tokenSecret": "tokenSecret-demo",
"tokenExpiresIn": 7200,
"tokenExpiresThreshold": 600,
"passwordErrorLimit": 6,
"bindTokenToDevice": true,
"passwordErrorRetryTime": 3600,
"autoSetInviteCode": false,
"forceInviteCode": false,
"app-plus": {
"tokenExpiresIn": 2592000,
"oauth" : {
"weixin" : {
"appid" : "weixin appid",
"appsecret" : "weixin appsecret"
}
}
},
"mp-weixin": {
"oauth" : {
"weixin" : {
"appid" : "weixin appid",
"appsecret" : "weixin appsecret"
}
}
},
"mp-alipay": {
"oauth" : {
"alipay" : {
"appid" : "alipay appid",
"privateKey" : "alipay privateKey"
}
}
},
"service": {
"sms": {
"name": "DCloud",
"codeExpiresIn": 300,
"smsKey": "your sms key",
"smsSecret": "your sms secret"
}
}
}
This diff is collapsed.
{
"name": "uni-id",
"version": "2.0.3",
"description": "uni-id for uniCloud",
"main": "index.js",
"homepage": "https://uniapp.dcloud.io/uniCloud/uni-id",
"repository": {
"type": "git",
"url": "git+https://gitee.com/dcloud/uni-id.git"
},
"author": "",
"license": "Apache-2.0"
}
\ No newline at end of file
async function getUserId(token) {
const res = await uniCloud.httpclient.request("https://system.dev.banshouhui.com/wxh-worker-rest/rest/" +
token +
"/myinfo/id", {
method: 'GET',
dataType: 'text'
})
return res && res.status === 200 ? res.data : token
}
module.exports = {
getUserId
}
{
"name": "user-common",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
let res = await db.collection("standard").where(event).get();
let data = res.data
const map = new Map()
for(let i = 0; i < data.length; i++){
let key = data[i].type
if(map.has(key)){
data[i].images = data[i].images.split(",")
map.get(key).list.push(data[i])
}else{
data[i].images = data[i].images.split(",")
map.set(key,{type:key, list:[data[i]]})
}
}
return [...map.values()]
};
// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。
// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/quickstart?id=runparam
{
"token": "RTOKENeb70458c5502c48838d5e4cf84900767fa010f00",
"classify_id": "79550af260555cc20afb34146966a2c4",
"system_id": "79550af260555cc20afb34156c94b32c",
"brand_id": "28ee4e3e6063f2880d8956a013293a7f"
}
'use strict';
const {
getUserId
} = require('user-common')
exports.main = async (event, context) => {
const db = uniCloud.database();
const _ = db.command
const $ = db.command.aggregate
const user_id = await getUserId(event.token)
let res = await db.collection("standardV2").aggregate().lookup({
from: 'user_upload_file',
let: {
standard_id: '$_id'
},
pipeline: $.pipeline()
.match(_.expr($.and([
$.eq(['$standard_id', '$$standard_id']),
$.eq(['$user_id', user_id])
]))).sort({
create_date: -1
}).limit(10)
.project({
"_id": 0,
"url": 1,
})
.done(),
as: 'imageList'
}).match({"classify_id": event.classify_id, "system_id": event.system_id, "brand_id": event.brand_id}).limit(100).end()
const watermarkC = uniCloud.database().collection("user_watermark").field({'_id': false})
let userWatermark = await watermarkC.where({
user_id: user_id,
system_id: event.system_id
}).get()
if (!userWatermark.data || userWatermark.data.length <= 0) { // 用户没有 获取模板
userWatermark = await watermarkC.where({system_id: event.system_id}).get()
}
let userWatermarkData = userWatermark.data[0]
let data = res.data
const map = new Map()
for (let i = 0; i < data.length; i++) {
data[i].imageList = data[i].imageList.map(a => a.url)
let key = data[i].type
if (map.has(key)) {
data[i].images = data[i].images.split(",")
map.get(key).list.push(data[i])
} else {
data[i].images = data[i].images.split(",")
map.set(key, {
type: key,
userWatermark: userWatermarkData,
list: [data[i]]
})
}
}
return [...map.values()]
};
{
"name": "getGroupStandardV2",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"user-common": {
"version": "file:../common/user-common"
}
}
}
{
"name": "getGroupStandardV2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"user-common": "file:../common/user-common"
}
}
// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。
// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/quickstart?id=runparam
{
"classify_id": "79550af260555cc20afb34146966a2c4",
"system_id": "79550af260555cc20afb34156c94b32c",
"field": "brand_id"
}
'use strict';
exports.main = async (event, context) => {
const param = {
"classify_id": event.classify_id,
"system_id": event.system_id,
"brand_id": event.brand_id
}
const db = uniCloud.database()
let res = await db.collection("standardV2").aggregate().match(param).group({
_id: "$" + event.field
}).end();
res = await db.collection('dictionary').field({
"_id": true,
"name": true
}).where({
_id: db.command.in(Array.from(res.data, item => item._id))
}).get()
return res.data
};
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
const db = uniCloud.database()
let res = await db.collection("standardV2").field({"classify_id": true, "system_id": true, "brand_id": true}).get();
let data = {}
let id = []
res.data.map(item => {
id.push(item.classify_id)
id.push(item.system_id)
id.push(item.brand_id)
if (data[item.classify_id]) {
if (data[item.classify_id][item.system_id]) {
if (data[item.classify_id][item.system_id].indexOf(item.brand_id) < 0)
data[item.classify_id][item.system_id].push(item.brand_id)
} else {
data[item.classify_id][item.system_id] = [item.brand_id]
}
} else {
let obj = {}
obj[item.system_id] = [item.brand_id]
data[item.classify_id] = obj
}
})
let dic = await db.collection("dictionary").where({
_id: db.command.in(id)
}).get()
let dic_data = {}
dic.data.map(item => {
dic_data[item._id] = item.name
})
let result = []
for (let first in data) {
let secondArr = []
for (let second in data[first]) {
let thirdArr = []
data[first][second].map(third => {
thirdArr.push({id: third, name: dic_data[third]})
})
secondArr.push({id: second, name: dic_data[second], child: thirdArr})
}
result.push({id: first, name: dic_data[first], child: secondArr})
}
return result;
};
// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。
// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/quickstart?id=runparam
{
"token": "fdsadfsafsafsadfdsa",
"system_id": "79550af260555cc20afb34156c94b32c"
}
'use strict';
const {
getUserId
} = require('user-common')
exports.main = async (event, context) => {
//event为客户端上传的参数
const user_id = await getUserId(event.token)
const collection = uniCloud.database().collection("user_watermark").field({
'_id': false
})
let res = await collection.where({
user_id: user_id,
system_id: event.system_id
}).get()
if (!res.data || res.data.length <= 0) { // 用户没有 获取模板
res = await collection.where({
system_id: event.system_id
}).get()
}
return res.data[0]
};
{
"name": "getUserWatermark",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"user-common": {
"version": "file:../common/user-common"
}
}
}
{
"name": "getUserWatermark",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"user-common": "file:../common/user-common"
}
}
'use strict';
const {
getUserId
} = require('user-common')
exports.main = async (event, context) => {
//event为客户端上传的参数
let workerId = await getUserId(event.token)
if (workerId) {
await uniCloud.database().collection("user_upload_file").add({
"user_id": workerId,
"standard_id": event.standardId,
url: "https://img2.banshouhui.com/" + event.url,
create_date: new Date()
})
return true
}
return false
};
{
"name": "saveImage",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"user-common": {
"version": "file:../common/user-common"
}
}
}
{
"name": "saveImage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"user-common": "file:../common/user-common"
}
}
'use strict';
const {
getUserId
} = require('user-common')
exports.main = async (event, context) => {
let user_id = await getUserId(event.token)
console.log(user_id);
const watermark = event.watermark
if (user_id) {
watermark.user_id = user_id
const collection = uniCloud.database().collection("user_watermark");
const res = await collection.where({
user_id: user_id,
system_id: watermark.system_id
}).get()
if (res.data && res.data.length > 0) {
await collection.doc(res.data[0]._id).update(watermark)
} else {
await collection.add(watermark)
}
}
//返回数据给客户端
return true
};
{
"name": "saveUserWatermark",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"user-common": {
"version": "file:../common/user-common"
}
}
}
{
"name": "saveUserWatermark",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"user-common": "file:../common/user-common"
}
}
{
"token": "fdsadfsafsafsadfdsa",
"watermark": {
"has_origin": true,
"lower_right": {
"body": [{
"enable": true,
"watemark_text": "时间",
"watemark_type": "时间",
"watemark_value": ""
}, {
"enable": true,
"watemark_text": "地址",
"watemark_type": "地址",
"watemark_value": ""
}, {
"enable": true,
"watemark_text": "经度",
"watemark_type": "经度",
"watemark_value": ""
}, {
"enable": true,
"watemark_text": "纬度",
"watemark_type": "纬度",
"watemark_value": ""
}, {
"enable": false,
"watemark_text": "",
"watemark_type": "备注",
"watemark_value": ""
}, {
"watemark_value": "蓝天工程队3",
"enable": true,
"watemark_text": "工程队名称3",
"watemark_type": "备注"
}, {
"enable": true,
"watemark_text": "10000",
"watemark_type": "备注",
"watemark_value": "111111"
}, {
"enable": false,
"watemark_text": "",
"watemark_type": "备注",
"watemark_value": ""
}, {
"enable": false,
"watemark_text": "",
"watemark_type": "备注",
"watemark_value": ""
}]
},
"mid_text": "现场拍照",
"system_id": "79550af260555cc20afb34156c94b32c",
"user_id": "fdsadfsafsafsadfdsa"
}
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment