uploadsketch.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()" style="margin-bottom:20rpx">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 32rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view style="display: flex;justify-content: center;">
  15. <radio-group @change="chan">
  16. <label v-for="item in radioGroup" :key="item">
  17. <view style="display: inline;margin: 0 20rpx">
  18. <radio :value="item" :checked="item==activeRadio" color="#fdd544" />{{item}}
  19. </view>
  20. </label>
  21. </radio-group>
  22. </view>
  23. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '图片'">
  24. <htz-image-upload :max="18" mediaType="image" name="file" :chooseNum="9" v-model="imageData"
  25. @chooseSuccess="ceshiChooseSuccess1">
  26. </htz-image-upload>
  27. </view>
  28. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '视频'">
  29. <htz-image-upload :max="1" mediaType="video" name="file" :chooseNum="1" v-model="videoData"
  30. @chooseSuccess="ceshiChooseSuccess2">
  31. </htz-image-upload>
  32. </view>
  33. <uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧">
  34. </uni-easyinput>
  35. <!-- 多行输入框 -->
  36. <view style="padding: 40rpx 30rpx 150rpx;font-size: 32rpx">
  37. <textarea v-model="text" maxlength="2000" auto-height="true" placeholder="添加正文" />
  38. </view>
  39. <view class="signup">
  40. <button type="default" class="but1" :loading="loading" :class="{'on':item.title == '1',}" @click="submit()">
  41. 提交初稿</button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import mvBar from "@/components/mys_navBar/mysNavBar";
  47. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  48. import getPolicyEncode from '@/components/obs/getPolicy.js';
  49. import getSignature from '@/components/obs/GetSignature.js';
  50. export default {
  51. components: {
  52. mvBar,
  53. htzImageUpload,
  54. },
  55. data() {
  56. return {
  57. navH: getApp().globalData.navHeight,
  58. taskId: "",
  59. title: "",
  60. text: "",
  61. sketchStatus: "",
  62. activeRadio: '图片', //存的是选中的value值
  63. radioGroup: ['图片', '视频'],
  64. videoData: [],
  65. imageData: [],
  66. mysNavConfig: {
  67. /* 开启单页显示首页图标 */
  68. isHome: true,
  69. /* 固定导航 */
  70. navFixed: true,
  71. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  72. navTitle: {
  73. text: "上传初稿",
  74. color: "",
  75. fontSize: "32rpx", // px upx rpx
  76. fontWeight: "normal", // 100 - 700
  77. },
  78. btnType: "type2",
  79. onLeftClick: '',
  80. /* type2 按钮 */
  81. type2Config: {
  82. // 左图标
  83. leftPath: "/static/img/png2.png",
  84. // 右图标
  85. rightPath: "/static/img/png4.png",
  86. // 圆角
  87. radius: "40rpx",
  88. },
  89. },
  90. }
  91. },
  92. onLoad(options) {
  93. let data = options.textObj.replace(/""/g, "");
  94. data = JSON.parse(decodeURIComponent(data))
  95. this.taskId = data.taskId
  96. this.sketchStatus = data.sketchStatus
  97. this.getSketch()
  98. },
  99. methods: {
  100. chan(e) {
  101. this.activeRadio = e.detail.value;
  102. console.log(this.activeRadio);
  103. },
  104. getSketch() {
  105. this.$https.get('/youngee/c/t/g/get-unsubmit-task-sketch' +
  106. "?" +
  107. "task_id" +
  108. "=" +
  109. this.taskId)
  110. .then(res => {
  111. console.log(res)
  112. if (res.data.data != null) {
  113. this.title = res.data.data.title
  114. this.text = res.data.data.content
  115. if (res.data.data.type == 1) { // 图片
  116. this.activeRadio = '图片'
  117. for (var j = 0; j < res.data.data.Photo.length; j++) {
  118. this.imageData.push(res.data.data.Photo[j].photo_url)
  119. }
  120. } else if (res.data.data.type == 2) { //视频
  121. this.activeRadio = '视频'
  122. for (var j = 0; j < res.data.data.Photo.length; j++) {
  123. this.videoData.push(res.data.data.Photo[j].photo_url)
  124. }
  125. }
  126. }
  127. })
  128. },
  129. toRecord() {
  130. var data = {
  131. taskId: this.taskId,
  132. };
  133. data = JSON.stringify(data)
  134. uni.navigateTo({
  135. url: '/pages/workspace/sketchrecord?textObj=' + encodeURIComponent(data)
  136. });
  137. },
  138. submit() {
  139. // 检验标题和内容是否为空
  140. let type = 0
  141. let photourl = []
  142. if (this.activeRadio == '图片') { // 图片
  143. type = 1
  144. photourl = this.imageData
  145. } else {
  146. type = 2
  147. photourl = this.videoData
  148. }
  149. if (this.title == '') {
  150. uni.showToast({
  151. title: "请填写初稿标题",
  152. icon: 'none'
  153. })
  154. return
  155. }
  156. if (this.text == '') {
  157. uni.showToast({
  158. title: "请填写初稿内容",
  159. icon: 'none'
  160. })
  161. return
  162. }
  163. if (photourl.length == 0) {
  164. uni.showToast({
  165. title: "请上传初稿图片或视频",
  166. icon: 'none'
  167. })
  168. return
  169. }
  170. console.log("photourl:", photourl)
  171. this.$https.post('/youngee/c/t/p/add-task-sketch', {
  172. task_id: this.taskId,
  173. title: this.title,
  174. content: this.text,
  175. type: type,
  176. photo_url: photourl.toString()
  177. })
  178. .then(res => {
  179. console.log(res)
  180. uni.navigateBack()
  181. })
  182. },
  183. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  184. console.log('ceshiChooseSuccess', tempFilePaths, e);
  185. /****************
  186. 以下代码是自定义上传逻辑,仅供参考
  187. ***************/
  188. this.imgUpload1(tempFilePaths, e);
  189. /*******************************/
  190. console.log("imgdata" + this.imageData)
  191. },
  192. imgUpload1(tempFilePaths, e) {
  193. let that = this
  194. console.log('imgUpload', tempFilePaths)
  195. let config = {
  196. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  197. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  198. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  199. };
  200. for (let i = 0; i < tempFilePaths.length; ++i) {
  201. if (e == 0) {
  202. this.store = 'talent_upload/' + this.guid() + '.png'
  203. } else if (e == 1) {
  204. this.store = 'talent_upload/' + this.guid() + '.mp4'
  205. }
  206. let fileName = this.store; //指定上传到OBS桶中的对象名
  207. let OBSPolicy = { //设定policy内容
  208. "expiration": "2089-12-31T12:00:00.000Z",
  209. "conditions": [{
  210. "bucket": "horastar"
  211. }, //Bucket name
  212. // {"bucket": "goin"},
  213. {
  214. 'key': fileName
  215. }
  216. ]
  217. }
  218. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  219. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  220. uni.uploadFile({
  221. //url: config.EndPoint,
  222. url: config.EndPoint,
  223. filePath: tempFilePaths[i],
  224. name: 'file',
  225. formData: {
  226. 'AccessKeyID': config.AccessKeyId,
  227. 'policy': policyEncoded,
  228. 'signature': signature,
  229. 'key': fileName,
  230. },
  231. success: function(res) {
  232. console.log(res.statusCode); //打印响应状态码
  233. if (res.statusCode == '204') {
  234. that.imageData.push(config.EndPoint + '/' + fileName);
  235. console.log('上传图片成功', res)
  236. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  237. console.log(obs_url)
  238. // that.formData.home_img = obs_url
  239. uni.showToast({
  240. title: '上传成功',
  241. icon: '成功'
  242. });
  243. } else {
  244. console.log('上传图片失败', res)
  245. uni.showToast({
  246. title: '上传失败',
  247. icon: '失败'
  248. });
  249. }
  250. },
  251. fail: function(e) {
  252. console.log(e);
  253. uni.showToast({
  254. title: '上传失败22222',
  255. icon: '失败'
  256. });
  257. }
  258. })
  259. }
  260. },
  261. ceshiChooseSuccess2(tempFilePaths, e) { //选择视频返回
  262. console.log('ceshiChooseSuccess', tempFilePaths, e);
  263. if (e == 0) {
  264. this.store = 'talent_upload/' + this.guid() + '.png'
  265. } else if (e == 1) {
  266. this.store = 'talent_upload/' + this.guid() + '.mp4'
  267. }
  268. /****************
  269. 以下代码是自定义上传逻辑,仅供参考
  270. ***************/
  271. this.imgUpload2(tempFilePaths);
  272. /*******************************/
  273. console.log("videoData" + this.videoData)
  274. },
  275. imgUpload2(tempFilePaths) {
  276. let that = this
  277. console.log('videoUpload', tempFilePaths)
  278. let config = {
  279. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  280. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  281. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  282. };
  283. let fileName = this.store; //指定上传到OBS桶中的对象名
  284. // let fileName = "talent_upload/icon-arrow-right.png"
  285. let OBSPolicy = { //设定policy内容
  286. "expiration": "2089-12-31T12:00:00.000Z",
  287. "conditions": [{
  288. "bucket": "horastar"
  289. }, //Bucket name
  290. // {"bucket": "goin"},
  291. {
  292. 'key': fileName
  293. }
  294. ]
  295. }
  296. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  297. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  298. uni.uploadFile({
  299. //url: config.EndPoint,
  300. url: config.EndPoint,
  301. filePath: tempFilePaths[0],
  302. name: 'file',
  303. formData: {
  304. 'AccessKeyID': config.AccessKeyId,
  305. 'policy': policyEncoded,
  306. 'signature': signature,
  307. 'key': fileName,
  308. },
  309. success: function(res) {
  310. console.log(res.statusCode); //打印响应状态码
  311. if (res.statusCode == '204') {
  312. that.videoData.push(config.EndPoint + '/' + fileName);
  313. console.log('上传图片成功', res)
  314. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  315. console.log(obs_url)
  316. // that.formData.home_img = obs_url
  317. uni.showToast({
  318. title: '上传成功',
  319. icon: '成功'
  320. });
  321. } else {
  322. console.log('上传图片失败', res)
  323. uni.showToast({
  324. title: '上传失败',
  325. icon: '失败'
  326. });
  327. }
  328. },
  329. fail: function(e) {
  330. console.log(e);
  331. uni.showToast({
  332. title: '上传失败22222',
  333. icon: '失败'
  334. });
  335. }
  336. })
  337. },
  338. guid() {
  339. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  340. var r = Math.random() * 16 | 0,
  341. v = c == 'x' ? r : (r & 0x3 | 0x8);
  342. return v.toString(16);
  343. });
  344. },
  345. },
  346. }
  347. </script>
  348. <style lang="scss" scoped>
  349. .signup {
  350. box-shadow: 0rpx 5rpx 40rpx #ccc;
  351. width: 100%;
  352. position: fixed;
  353. bottom: 0rpx;
  354. display: flex;
  355. height: 90rpx;
  356. padding-top: 2%;
  357. background-color: #FFFFFF;
  358. z-index: 99;
  359. }
  360. .but1 {
  361. width: 60%;
  362. background-color: #f2d22d;
  363. border-radius: 20rpx;
  364. font-size: 36rpx;
  365. line-height: 200%;
  366. letter-spacing: 10rpx;
  367. font-weight: 500;
  368. height: 80%;
  369. &.on {
  370. background-color: #C0C0C0;
  371. }
  372. }
  373. </style>