create.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="page">
  3. <ul class="profile">
  4. <li>名称:</li>
  5. <li><input type="text" class="input1" id="name" v-model="title" placeholder="请输入聊天室名称" /></li>
  6. </ul>
  7. <ul class="profile">
  8. <li>介绍:</li>
  9. <li><textarea id="content" placeholder="请输入聊天室介绍" v-model="content"></textarea></li>
  10. </ul>
  11. <ul class="profile">
  12. <li>Logo:</li>
  13. <li>
  14. <image :src="avatarsrc" class="avatar" :style="{ width: imgshow ? '60px' : '1px' }"></image>
  15. <view class="add_btn" @tap="uploadImage">
  16. <uni-icons class="icons1" type="upload"></uni-icons>
  17. 浏览1
  18. </view>
  19. </li>
  20. </ul>
  21. <ul class="profile">
  22. <li>加群验证:</li>
  23. <li>
  24. <radio :checked="no_invite === 1" @click="no_invite = 1">需要验证</radio>
  25. <radio style="margin-left: 30px;" :checked="no_invite === 0" @click="no_invite = 0">无需验证</radio>
  26. </li>
  27. </ul>
  28. <ul class="profile">
  29. <li style="vertical-align: middle">标签:</li>
  30. <li style="vertical-align: middle;line-height: 30px;">
  31. <div class="tags_show" style="vertical-align: middle;margin-right: 5px;">{{ tags_select }}</div>
  32. <div style="vertical-align: middle" class="add_btn" @tap="tags_show = true">
  33. <uni-icons class="icons1" type="plus"></uni-icons>
  34. 选择标签
  35. </div>
  36. </li>
  37. </ul>
  38. <view style="width: 80%;margin: 15px auto;display: block"><button class="button1"
  39. @tap="click_sub()">确认并提交</button></view>
  40. <view class="tags" v-if="tags_show">
  41. <view class="content">
  42. <div class="title">选择标签(最多{{ system['tags_sum'] }}个)</div>
  43. <block v-for="(item, index) in tags" :key="index">
  44. <span @tap="click_tags(index)" :class="{ active: tags_select.indexOf(item) > -1 }">{{ item }}</span>
  45. </block>
  46. </view>
  47. <image class="close_tags" @tap="tags_show = false" src="/static/close1.png"></image>
  48. </view>
  49. <yk-authpup ref="authpupCAMERA" type="top" @changeAuth="changeAuths"
  50. permissionID="CAMERA"></yk-authpup>
  51. </view>
  52. </template>
  53. <script>
  54. import ykAuthpup from "@/components/yk-authpup/yk-authpup";
  55. import http from '../../library/http.js';
  56. import uniIcons from '../../components/uni-icons/uni-icons.vue';
  57. import helper from '../../library/helper.js';
  58. import config from '../../config.js';
  59. export default {
  60. components: {
  61. uniIcons,
  62. ykAuthpup
  63. },
  64. data() {
  65. return {
  66. no_invite: 1,
  67. avatarsrc: false,
  68. avatar: '',
  69. imgshow: false,
  70. isuploading: false,
  71. system: uni.getStorageSync('system'),
  72. tags: '',
  73. tags_sum: 3,
  74. tags_show: false,
  75. tags_select: '',
  76. title: '',
  77. content: '',
  78. userid: 0,
  79. userlist: ""
  80. };
  81. },
  82. computed: {},
  83. methods: {
  84. changeAuths() {
  85. console.log('success')
  86. this.navCroper(400,400,'avatarsrc')
  87. },
  88. uploadImage() {
  89. console.log('zhe')
  90. // #ifdef APP-PLUS
  91. if(plus.os.name =='Android') {
  92. this.$refs.authpupCAMERA.open()
  93. }else {
  94. this.navCroper(400,400,'avatarsrc')
  95. }
  96. // #endif
  97. // #ifndef APP-PLUS
  98. this.navCroper(400,400,'avatarsrc')
  99. // #endif
  100. // this.navCroper(400,400,'avatarsrc')
  101. },
  102. click_tags(num) {
  103. var item = this.tags[num];
  104. if (this.tags_select.indexOf(item) > -1) {
  105. var arr = this.tags_select.split(',');
  106. var select = '';
  107. for (var i = 0; i < arr.length; i++) {
  108. if (arr[i] != item) {
  109. if (select != '') select += ',';
  110. select += arr[i];
  111. }
  112. }
  113. this.tags_select = select;
  114. } else {
  115. var arr = this.tags_select.split(',');
  116. if (arr.length >= this.tags_sum) {
  117. uni.showToast({
  118. title: '最多可以选择' + this.tags_sum + '个标签',
  119. icon: 'none'
  120. });
  121. } else {
  122. if (this.tags_select != '') this.tags_select += ',';
  123. this.tags_select += item;
  124. }
  125. }
  126. },
  127. click_sub() {
  128. if (this.title == '') {
  129. uni.showToast({
  130. title: '请输入群组名称',
  131. icon: 'none'
  132. });
  133. return false;
  134. }
  135. if (this.content == '') {
  136. uni.showToast({
  137. title: '请输入群组介绍',
  138. icon: 'none'
  139. });
  140. return false;
  141. }
  142. // if(this.imgshow==false){
  143. // uni.showToast({
  144. // title:'请上传群头像',
  145. // icon:'none'
  146. // })
  147. // return false;
  148. // }
  149. if (this.tags_select == '') {
  150. uni.showToast({
  151. title: '请设置群标签',
  152. icon: 'none'
  153. });
  154. return false;
  155. }
  156. if (this.isuploading == true) {
  157. uni.showToast({
  158. title: '头像正在上传中,请稍后提交',
  159. icon: 'none'
  160. });
  161. return false;
  162. }
  163. var postdata = {
  164. id: uni.getStorageSync('access_token'),
  165. name: this.title,
  166. content: this.content,
  167. avatar: this.avatar,
  168. tags: this.tags_select,
  169. no_invite: this.no_invite,
  170. userlist: this.userlist
  171. };
  172. http.setWait(true).post('group.php?act=createGroup', postdata)
  173. .then(res => {
  174. if (res.code == 200) {
  175. var data = res.data;
  176. uni.setStorageSync(uni.getStorageSync('access_token') + '_groups', res.groups);
  177. uni.showToast({
  178. title: '创建成功',
  179. icon: 'none'
  180. });
  181. uni.redirectTo({
  182. url: 'chat?id=' + data.id + '&nickname=' + data.nickname
  183. });
  184. } else {
  185. uni.showToast({
  186. title: '网络错误,请稍后再试',
  187. icon: 'none'
  188. });
  189. }
  190. });
  191. },
  192. // 图片上传
  193. upLoad(path) {
  194. let that = this
  195. uni.showLoading({
  196. title: '图片上传中',
  197. mask: true
  198. });
  199. console.log('图片上传中')
  200. return new Promise((resolve, error) => {
  201. // let arr = [];
  202. // arr.push(path)
  203. // const tempFilePaths = arr;
  204. var tempFilePaths = path;
  205. that.avatarsrc = tempFilePaths;
  206. that.isuploading = true;
  207. that.imgshow = true;
  208. helper.uploadFiles([tempFilePaths], 'images', {
  209. type: 'avatar'
  210. }).then(res => {
  211. // this.group.avatar=res;
  212. // this.avatarsrc=res;
  213. that.avatar = res.replace(config.imgUri, '');
  214. that.isuploading = false;
  215. });
  216. })
  217. },
  218. chooseImage: function(index) {
  219. const _this = this
  220. return new Promise((ok, error) => {
  221. // 从相册/相机选择
  222. // 如需直接开相机或直接选相册,请只使用一个选项
  223. const sourceType = index === 0 ? ['camera'] : ['album']
  224. uni.chooseImage({
  225. count: 1, //默认9
  226. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  227. sourceType: sourceType,
  228. success: function(res) {
  229. ok(res.tempFilePaths[0])
  230. },
  231. fail(e) {
  232. uni.showModal({
  233. title: '文件打开错误',
  234. content: '请设置授权文件存储权限',
  235. showCancel: false,
  236. });
  237. error(e)
  238. }
  239. });
  240. })
  241. },
  242. onImg(type) {
  243. const _this = this
  244. return new Promise((ok, erro) => {
  245. // 判断是否需要选择
  246. if (type == 1) {
  247. uni.showActionSheet({
  248. itemList: ['拍照', '选择一张照片'],
  249. success: function(res) {
  250. console.log(res, '上传')
  251. _this.chooseImage(res.tapIndex).then((url) => {
  252. console.log(url, 'url');
  253. ok(url)
  254. }).catch((res) => {
  255. erro(res)
  256. })
  257. },
  258. fail: function(res) {
  259. erro(res)
  260. console.log(res.errMsg);
  261. }
  262. });
  263. }
  264. // 判断是否只需要拍照
  265. if (type == 2) {
  266. _this.chooseImage(0).then((url) => {
  267. ok(url)
  268. }).catch((res) => {
  269. erro(res)
  270. })
  271. }
  272. })
  273. },
  274. //图像裁剪
  275. navCroper(w, h, type) {
  276. let that = this;
  277. let tt = (type == 'upimg' ? 2 : 1)
  278. this.onImg(tt).then((url) => {
  279. uni.navigateTo({
  280. url: `/pages/index/cropper?width=${w}&height=${h}`,
  281. events: {
  282. uploadSuccess(res) {
  283. console.log(res, '这里')
  284. that.upLoad(res).then((urldata) => {
  285. console.log(urldata, '这里')
  286. // that[type] = urldata.url;
  287. })
  288. }
  289. },
  290. success: function(res) {
  291. console.log(res, 'success');
  292. // 通过eventChannel向被打开页面传送数据
  293. res.eventChannel.emit('urlNext', {
  294. url
  295. })
  296. }
  297. })
  298. })
  299. },
  300. },
  301. onShow() {},
  302. onLoad(opts) {
  303. if (uni.getStorageSync('access_token') > 0) {
  304. this.tags = this.system.tags.split('|');
  305. this.tags_sum = parseInt(this.system.tags_sum);
  306. this.userid = uni.getStorageSync('access_token');
  307. if (opts.userlist) this.userlist = opts.userlist;
  308. } else {
  309. uni.setStorageSync('gourl', '/pages/group/create');
  310. this.$jump('login.index');
  311. }
  312. }
  313. };
  314. </script>
  315. <style lang="scss">
  316. @import '@/static/css/group.css';
  317. .profile {
  318. min-height: 50px;
  319. line-height: 50px;
  320. background-color: #ffffff;
  321. margin-bottom: 10px;
  322. width: 100%;
  323. padding: 5px 0px;
  324. }
  325. .detail>div:last-child .info>ul>li:last-child {
  326. padding-left: 0px;
  327. }
  328. .btn2 {
  329. height: 25px;
  330. line-height: 25px;
  331. vertical-align: middle;
  332. border-radius: 5px;
  333. text-align: center;
  334. border: 0px;
  335. background-color: #ddd;
  336. color: #666;
  337. padding: 0px 10px;
  338. }
  339. .profile li:first-child {
  340. color: #999;
  341. }
  342. .page {
  343. background-color: #fafafa;
  344. font-size: 14px;
  345. }
  346. </style>